asp.netrabbitmqtracemasstransitopen-telemetry

How to add a RabbitMQ trace with OpenTelemetry?


I'm using OpenTelemetry to trace my Web API (ASP.NET). I use Jaeger to display traces. I have HTTP, SQL, EF and Redis traces. My Web API uses RabbitMQ and MassTransit. How can I add their traces to the ones I already have?

I tried to find information on the internet, but couldn't find a solution that works with .NET. I will be very grateful if anyone can help me :-)

EDIT: I tried this code in WebAPI:

services.AddOpenTelemetry()
    .ConfigureResource(resource => resource.AddService(appSettings.JaegerSettings.ServiseName))
    .WithTracing(tracing => tracing
        .AddAspNetCoreInstrumentation()
        .AddHttpClientInstrumentation(options => options.FilterHttpRequestMessage = request => appSettings.JaegerSettings.FilterFrom.Contains(request.Headers.From))
        .AddSqlClientInstrumentation(options => options.SetDbStatementForText = true)
        .AddEntityFrameworkCoreInstrumentation(options => options.SetDbStatementForText = true)
        .AddRedisInstrumentation(options => options.SetVerboseDatabaseStatements = true)
        .AddSource("MassTransit") //I added this line
        .AddOtlpExporter(option =>
        {
            option.Endpoint = new Uri(appSettings.JaegerSettings.Endpoint);
            option.Protocol = OpenTelemetry.Exporter.OtlpExportProtocol.HttpProtobuf;
        }));

It didn't work. What did I do wrong?


Solution

  • MassTransit supports Open Telemetry out of the box. You can see in the sample that you just need to add the source MassTransit to your OTEL configuration.