# .net agent with masstransit rabbitmq transactions

**URL:** <https://discuss.elastic.co/t/net-agent-with-masstransit-rabbitmq-transactions/332260>\
**Category:** APM\
**Tags:** dotnet\
**Created:** [May 2, 2023, 11:28am UTC](https://discuss.elastic.co/t/net-agent-with-masstransit-rabbitmq-transactions/332260 "2023-05-02T11:28:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joao\_Cardoso](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joao_cardoso/32/120395_2.png) [@Joao\_Cardoso](https://discuss.elastic.co/u/Joao_Cardoso)\
**Post date:** [May 2, 2023, 11:28am UTC](https://discuss.elastic.co/t/net-agent-with-masstransit-rabbitmq-transactions/332260/1 "2023-05-02T11:28:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![xeraa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xeraa/32/48181_2.png) [@xeraa](https://discuss.elastic.co/u/xeraa)\
**Post date:** [May 25, 2023, 12:46pm UTC](https://discuss.elastic.co/t/net-agent-with-masstransit-rabbitmq-transactions/332260/2 "2023-05-25T12:46:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Joao\_Cardoso](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joao_cardoso/32/120395_2.png) [@Joao\_Cardoso](https://discuss.elastic.co/u/Joao_Cardoso)\
**Post date:** [May 26, 2023, 9:02am UTC](https://discuss.elastic.co/t/net-agent-with-masstransit-rabbitmq-transactions/332260/3 "2023-05-26T09:02:23Z")

</div>

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

```auto
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);
                });
        });

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 23, 2023, 9:03am UTC](https://discuss.elastic.co/t/net-agent-with-masstransit-rabbitmq-transactions/332260/4 "2023-06-23T09:03:07Z")

</div>

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