Sobes.tech
Middle+

What was used for tracing and metrics?

sobes.tech AI

Answer from AI

For tracing and metrics in C#, I often use the following tools:

  • Application Insights — integrates with .NET applications, allows collecting logs, metrics, traces, and telemetry.
  • OpenTelemetry — an open standard for collecting distributed traces and metrics, with support for C#.
  • Serilog with appropriate sinks for sending logs to monitoring systems.
  • Prometheus in conjunction with application metrics exporters.

For example, for simple tracing with OpenTelemetry, you can set up tracing as follows:

using OpenTelemetry;
using OpenTelemetry.Trace;

var tracerProvider = Sdk.CreateTracerProviderBuilder()
    .AddSource("MyCompany.MyProduct.MyLibrary")
    .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("MyService"))
    .AddConsoleExporter()
    .Build();

var tracer = tracerProvider.GetTracer("MyCompany.MyProduct.MyLibrary");

using (var span = tracer.StartActiveSpan("MyOperation"))
{
    // operation code
}

The choice of specific tool depends on the infrastructure and project requirements.