How to monitor transactions which pass through Rabbit MQ, producer & consumer are python clients

Hi All,

I want to "trace" distributed transactions which pass through "Rabbit MQ" through the Application. The clients for Rabbit MQ are written in python 2.x & Python 3,.x to consume and produce messages.

When in Elastic APM, how do we configure/add/span which shows the "Request -calls which pass through a queue and being processed by the consumer".

Entire lifecycle of the request -> Application > some processing in the server -> generates message in RMQ - > Consumers consume the message.

Each message should be considered as transaction and latency should be calculated.

Even the Request where it went and to which queue ?

We unfortunately don't have support for RabbitMQ yet. We have an open issue, please express your interest there -- it helps us prioritize: Add instrumentation and distributed tracing for RabbitMQ (pika) · Issue #678 · elastic/apm-agent-python · GitHub

If you want to tackle this as a custom instrumentation for your code, you'll need to add the TraceParent to your messages. You should be able to use headers, the same as we do in our kafka instrumentation. You can get the TraceParent string for the current transaction with elasticapm.get_trace_parent_header().

Then, on the receiver end, you can start a new transaction using a TraceParent object from elasticapm.trace_parent_from_string().

Thank you Colton !!

If you have an example please share , a pseudo code.

If we have already instrumented and have spans across the distributed application then how do I wire the transaction from there all along to Rabbit mq queue ( producer & consumer)

I know you are very busy guy , however some light would help me


I haven't done anything in rabbitmq, so I can't help with that piece at this moment.

But something like this on the producer:

headers = {"traceparent": elasticapm.get_trace_parent_header()}
rabbitmq.queue(message, headers=headers)  # I'm making this line up

On the consumer:

def consume(message, headers, client):
    traceparent = ealsticapm.trace_parent_from_string(headers.get("traceparent", ""))
    if traceparent:
        client.begin_transaction(transaction_type="messaging", trace_parent=traceparent)

Note that you can also use span links if you're already in an active transaction in your consumer. This is where you link a span to a parent transaction so that they're tied together in the trace view, even though it's not a direct parent/child relationship. There's a links argument in the capture_span context manager.

Hope that helps!

Let me try . Submitted interest in github for RMQ - Pika library instrumentation here - Add instrumentation and distributed tracing for RabbitMQ (pika) · Issue #678 · elastic/apm-agent-python · GitHub

Thanks basepi

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