← .NET Microservices Forum
MSDN Community | My Profile

Implementing Distributed Tracing in .NET Microservices

Started by Jane Doe • 2025-09-09 14:32
Jane Doe
Sep 9, 2025 at 2:32 PM

I'm trying to set up distributed tracing across several .NET 8 microservices using OpenTelemetry. My current setup works for a single service, but the spans aren't correlating across services. Any recommendations on best practices or configuration snippets?

Alex Smith
Sep 9, 2025 at 3:07 PM

Make sure you export the traceparent and tracestate headers on every outbound HTTP call. In .NET, the HttpClient instrumentation does this automatically when you add services.AddOpenTelemetry().WithTracing(...). Also, verify that all services share the same Resource attributes (service.name, service.version) so they appear under the same application in the UI.

services.AddOpenTelemetry()
    .WithTracing(builder => builder
        .AddSource("MyCompany.MyService")
        .SetResourceBuilder(ResourceBuilder.CreateDefault()
            .AddService("order-service", "1.2.0"))
        .AddAspNetCoreInstrumentation()
        .AddHttpClientInstrumentation()
        .AddJaegerExporter());
Mike Lee
Sep 9, 2025 at 4:15 PM

Also, if you use Kafka, you need to manually inject the context into the message headers. There's a helpful extension method in OpenTelemetry.Contrib.Extensions.Propagators that simplifies this.