.net agent with masstransit rabbitmq transactions

Hello,
Im using .net 6 with MassTransit and RabbitMQ and i'm trying to figure out how can i have the APM transactions of my messages being consumed. I saw the .net agent has integration with rabbitMQ nowdays but i wasn't sure how to use it (and if it's any different in my case since im using MT). I have also saw examples using agent API to be able to handle the messages from the queue, am i meant to build my own middleware to achieve what i want? Could anyone point me into the right direction please?

Thank you

Can you share how you solved it in case anybody else runs into a similar issue? :slight_smile:

Sure!
Masstransit 8 supports OpenTelemetry, so basically i integrated it with OpenTelemetry and then i used an exporter to send the traces to elastic.

builder.Services.AddOpenTelemetry()
        .WithTracing(bldr =>
        {
            bldr
                .AddSource(DiagnosticHeaders.DefaultListenerName)
                .SetResourceBuilder(ResourceBuilder.CreateDefault()
                    .AddService(builder.Environment.ApplicationName)
                    .AddTelemetrySdk()
                    .AddAttributes(
                        new KeyValuePair<string, object>[]
                        {
                            new("deployment.environment", builder.Environment.EnvironmentName),
                        })
                    .AddEnvironmentVariableDetector())
                .AddAspNetCoreInstrumentation(o =>
                {
                    o.RecordException = true;
                })
                .AddSqlClientInstrumentation(o =>
                {
                    o.EnableConnectionLevelAttributes = true;
                    o.RecordException = true;
                    o.SetDbStatementForText = true;
                    o.SetDbStatementForStoredProcedure = true;
                })
                .AddHttpClientInstrumentation(o =>
                {
                    o.RecordException = true;
                })
                .AddOtlpExporter(cfg =>
                {
                    cfg.Endpoint = new Uri(elasticAPMUrl);
                });
        });
1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.