Observability with OpenTelemetry in .NET

Vendor lock-in is a real risk in observability. If you instrument your code with `ApplicationInsights.TrackEvent()`, migrating to Datadog or Prometheus later requires a rewrite. OpenTelemetry (OTel) solves this.

The OTel Collector Pattern

Your app sends data to a local “Collector” (Sidecar), which then exports it to multiple backends.

services.AddOpenTelemetryTracing(b => {
    b.AddAspNetCoreInstrumentation()
     .AddHttpClientInstrumentation()
     .AddSqlClientInstrumentation()
     .AddSource("MyCompany.OrderService")
     .SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("OrderService"))
     .AddConsoleExporter()
     .AddOtlpExporter(opt => opt.Endpoint = new Uri("http://otel-collector:4317"));
});

This code is vendor-neutral. The OTel Collector configuration (YAML) determines where the data goes (Jaeger, Zipkin, Azure Monitor). This is the future of tracing.


Discover more from C4: Container, Code, Cloud & Context

Subscribe to get the latest posts sent to your email.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.