skip to Main Content

Since .NET Core 3, the .NET SDK exposes metrics through the EventCounters. It is also possible to implement your own EventCounter. So let’s assume I’m developing a memcache client in .NET, would it make sense to expose get/set metrics through EventCounters? Also, I noticed that none of the Well-known EventCounters use dynamic metric names such as memcache-{myMemcacheClusterName}-gets. Is it not recommended?

2

Answers


  1. Chosen as BEST ANSWER

    With the release of .NET 6, System.Diagnostics.Metrics, an official .NET implementation of the OpenTelemetry Metrics API is included.

    In this conversation dotnet/designs/pull/211 we can see that Metrics is now preferred over EventCounters.

    We'll recommend using Metrics moving forward but we are not deprecating the Event counters in this release at least.

    Note that System.Diagnostics.Metrics is available for .NET < 6 through the Nuget System.Diagnostics.DiagnosticSource >= 6. Here is an example: verdie-g/modern-caching/src/ModernCaching/Instrumentation/OpenTelemetryCacheMetrics.cs.


  2. So let’s assume I’m developing a memcache client in .NET, would it make sense to expose get/set metrics through EventCounters?

    Sure, of course you could go for something like App Metrics but the nice thing about EventCounters is that it is part of the .Net Framework so no external dependencies are required. Something that is attractive when writing a library.

    Also, I noticed that none of the Well-known EventCounters use dynamic metric names such as memcache-{myMemcacheClusterName}-gets. Is it not recommended?

    Dynamic counters are hard to discover and to document (what possible values are there). It used to be the only way to include additional information though. That is, until the introduction of metadata. Nowadays you can add additional information to the counters using AddMetadata():

    EventCounter someCounter = new EventCounter(nameof(someCounter), this);
    someCounter.AddMetadata("Environment", "Production");
    someCounter.AddMetadata("SomeKey", "SomeValue");
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search