What's new in .NET 8 performance measuring and monitoring
Nothing major has changed in the metrics API in .NET 8 comparing to .NET 7. The main change is the addition of tags to the metrics API.
New APIs let you attach key-value pair tags to Meter and Instrument objects when you create them. Aggregators of published metric measurements can use the tags to differentiate the aggregated values.
C#
var options = new MeterOptions("name")
{
Version = "version",
// Attach these tags to the created meter.
Tags = new TagList()
{
{ "MeterKey1", "MeterValue1" },
{ "MeterKey2", "MeterValue2" }
}
};
Meter meter = meterFactory!.Create(options);
Counter<int> counterInstrument = meter.CreateCounter<int>(
"counter", null, null, new TagList() { { "counterKey1", "counterValue1" } }
);
counterInstrument.Add(1);
The new APIs include:
- MeterOptions
- Meter(MeterOptions)
- [CreateCounter](https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.metrics.meter.createcounter#system-diagnostics-metrics-meter-createcounter-1(system-string-system-string-system-string-system-collections-generic-ienumerable((system-collections-generic-keyvaluepair((system-string-system-object))
For even more details, see the GitHub issue listing the changes (go to the “Files changed” tab, and then Microsoft.NETCore.App, then look for files starting with “System.Diagnostics”).
Summary
The main change in .NET 8 metrics API is the addition of tags to the metrics API. You can now attach key-value pair tags to Meter and Instrument objects when you create them. Aggregators of published metric measurements can use the tags to differentiate the aggregated values.
To contact me, send an email anytime or leave a comment below.