# Any update for RMQ request/response tracing which uses Python pika client

**URL:** <https://discuss.elastic.co/t/any-update-for-rmq-request-response-tracing-which-uses-python-pika-client/366931>\
**Category:** Elastic Observability\
**Created:** [September 23, 2024, 5:54am UTC](https://discuss.elastic.co/t/any-update-for-rmq-request-response-tracing-which-uses-python-pika-client/366931 "2024-09-23T05:54:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dixit](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dixit/32/111369_2.png) [@Dixit](https://discuss.elastic.co/u/Dixit)\
**Post date:** [September 23, 2024, 5:54am UTC](https://discuss.elastic.co/t/any-update-for-rmq-request-response-tracing-which-uses-python-pika-client/366931/1 "2024-09-23T05:54:18Z")

</div>

> [@How to monitor transactions which pass through Rabbit MQ, producer & consumer are python clients](https://discuss.elastic.co/t/how-to-monitor-transactions-which-pass-through-rabbit-mq-producer-consumer-are-python-clients/332647/4):
>
> 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=…

---

<div class="post-metadata">

**Author:** ![Dixit](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dixit/32/111369_2.png) [@Dixit](https://discuss.elastic.co/u/Dixit)\
**Post date:** [September 23, 2024, 5:54am UTC](https://discuss.elastic.co/t/any-update-for-rmq-request-response-tracing-which-uses-python-pika-client/366931/2 "2024-09-23T05:54:36Z")

</div>

> <https://github.com/elastic/apm-agent-python/issues/678>
>
> \*\*Context\*\*
> One common way to integrate services is using RabbitMQ as a message… broker. Currently, the Elastic APM agent only supports distributed tracing for HTTP calls. It would be of high value to add instrumentation and distributed tracing for message brokers and, in particular, \[RabbitMQ\]( 
> https://www.rabbitmq.com/) - one of the most deployed open source message brokers. Not having this integration could be a show-stopper for users of competitor solutions (\[New Relic already sports this integration\](https://docs.newrelic.com/docs/agents/python-agent/getting-started/instrumented-python-packages#message-broker-clients)) when considering migrating to Elastic APM.
> 
> \*\*Solution\*\* 
> The ideal solution would be to instrument message publishing and include tracing data in message headers, interpreting those headers when consuming messages to continue the tracing.
> 
> To support the maximum number of projects using RabbitMQ, I would recommend to start by adding support for \[Pika\](https://pypi.org/project/pika/) - a widely-used AMQP client library having support for both Python 2.7 and +3.4.
> 
> \*\*Alternatives\*\*
> A flexible alternative to a library-specific integration could be to provide APIs to create and interpret a distributed tracing payload for use in custom instrumentation of any type of communication between services. New Relic, for example, does offer these APIs in \[\`create\_distributed\_trace\_payload()\`\](https://docs.newrelic.com/docs/agents/python-agent/python-agent-api/createdistributedtracepayload-python-agent-api) and \[\`accept\_distributed\_trace\_payload()\`\](https://docs.newrelic.com/docs/agents/python-agent/python-agent-api/acceptdistributedtracepayload-python-agent-api)  
> 
> I'm willing to contribute with code if this is of general interest.
> 
> / Hampus

---

<div class="post-metadata">

**Author:** ![Dixit](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dixit/32/111369_2.png) [@Dixit](https://discuss.elastic.co/u/Dixit)\
**Post date:** [September 23, 2024, 5:54am UTC](https://discuss.elastic.co/t/any-update-for-rmq-request-response-tracing-which-uses-python-pika-client/366931/3 "2024-09-23T05:54:50Z")

</div>

> <https://github.com/elastic/apm/issues/143>
>
> \## Description of the issue
> Adding dedicated fields to schema to support messag…ing context.
> 
> \## What we are voting on
> \### New types
> \#### Background
> Message send/publish events can only be captured as spans if occurring within a traced transaction.
> Message consumption can be divided into two types: passive, where you would implement a listener that is called once a message is available, and active, where the queue is being polled (blocking or non-blocking). 
> Passive consumption typically results in a Messaging transaction and is pretty straightforward to trace. 
> Message polling can be done within a traced transaction, in which case it will result in a messaging span, or it can be the initiating event for a message handling flow. Capturing polling spans is also mostly straightforward. For polling-based transactions, our goal is to capture the message handling flow, which typically starts after the polling action exits, returning a message. This may be tricky if the handling flow is not implemented within a well defined API. The actual implementation for that may be different for different clients. Whenever it is not possible (or too risky), we may consider capturing the message polling action itself, but this should be decided for each case separately and should only be used as a last resort. In any case, we should not create a transaction based on polling APIs if the polling action did not result with a message (as opposed to polling spans, where we want to capture such as well).
> 
> \#### Proposed types
> \- Transactions: \`messaging\` for \`transaction.type\`
> \- Spans: \`messaging\` for \`span.type\` (both sends and receives-within-a-transaction), the name of the framework for \`span.subtype\` (eg \`jms\` or \`kafka\`) and the operation for \`span.action\` (eg \`send\`, \`receive\`, \`poll\`).
> 
> \### New fields
> \- \*\*\`context.message.queue.name\`\*\*: optional for \`messaging\` spans and transactions. Indexed as keyword. Wherever the broker terminology uses "topic", this field will contain the topic name.
> \- \*\*\`context.message.body\`\*\*: similar to HTTP requests' \`context.request.body\`- only fill in messaging-related \*\*transactions\*\* (ie incoming messages creating a transaction) and not for outgoing messaging spans. 
> - Rely on the existing \`ELASTIC\_APM\_CAPTURE\_BODY\` agent config option.
> - Only capture UTF-8 encoded message bodies
> - Limit size to 10000 characters. If longer than this size, trim to 9999 and append with ellipsis
> - Storage: same Elasticsearch mapping as \`context.request.body\`
> \- \*\*\`context.message.headers\`\*\*: similar to HTTP requests' \`context.request.headers\`- only fill in messaging-related \*\*transactions\*\*.
> - Rely on the existing \`ELASTIC\_APM\_CAPTURE\_HEADERS\` agent config option.
> - Sanitize headers with keys configured through \`ELASTIC\_APM\_SANITIZE\_FIELD\_NAMES\`
> - Intake: key-value pairs, same like \`context.request.headers\`
> - Storage: same mapping as used for \`context.request.headers\`.
> \- \*\*\`context.message.age.ms\`\*\*: a numeric field indicating the message's age in milliseconds. Relevant for transactions and \`receive\` spans that receive valid messages. There is no accurate definition as to how this is calculated. If the messaging framework provides a timestamp for the message- agents may use it. Otherwise, the sending agent can add a timestamp \_indicated as milliseconds since epoch UTC\_ to the message's metadata to be retrieved by the receiving agent. If a timestamp is not available- agents should omit this field. Clock skews between agents are ignored, unless the calculated age (receive-timestamp minus send-timestamp) is negative, in which case the agent should report 0 for this field.
> 
> \## Vote
> @elastic/apm-agent-devs and @elastic/apm-server: tick the N/A box if irrelevant for you. Otherwise, link to the relevant issue or PR this and tick "Yes".
> 
> | Component | Yes | N/A | Link to component issue
> | -------------|:----:|:----:|:-------------------:|
> | .NET |\<ul\>\<li\> \[\] \</li\>\</ul\>|\<ul\>\<li\> \[\] \</li\>\</ul\>| 
> | Go |\<ul\>\<li\> \[x\] \</li\>\</ul\>|\<ul\>\<li\> \[\] \</li\>\</ul\>|
> | Java |\<ul\>\<li\> \[x\] \</li\>\</ul\>|\<ul\>\<li\> \[\] \</li\>\</ul\>| https://github.com/elastic/apm-agent-java/pull/664
> | Node.js |\<ul\>\<li\> \[\] \</li\>\</ul\>|\<ul\>\<li\> \[\] \</li\>\</ul\>| 
> | Python |\<ul\>\<li\> \[\] \</li\>\</ul\>|\<ul\>\<li\> \[\] \</li\>\</ul\>|
> | Ruby |\<ul\>\<li\> \[\] \</li\>\</ul\>|\<ul\>\<li\> \[x\] \</li\>\</ul\>|
> | RUM |\<ul\>\<li\> \[\] \</li\>\</ul\>|\<ul\>\<li\> \[x\] \</li\>\</ul\>|
> | Server |\<ul\>\<li\> \[\] \</li\>\</ul\>|\<ul\>\<li\> \[\] \</li\>\</ul\>| https://github.com/elastic/apm-server/issues/2697

---

<div class="post-metadata">

**Author:** ![Dixit](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dixit/32/111369_2.png) [@Dixit](https://discuss.elastic.co/u/Dixit)\
**Post date:** [September 25, 2024, 11:18am UTC](https://discuss.elastic.co/t/any-update-for-rmq-request-response-tracing-which-uses-python-pika-client/366931/4 "2024-09-25T11:18:05Z")

</div>

@basepi is there any agent update for RMQ other than custom implementation ?  
Am having some confusion over custom implementation in RMQ tracing which is being called from HTTP.

Some code samples would help

---

<div class="post-metadata">

**Author:** ![Dixit](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dixit/32/111369_2.png) [@Dixit](https://discuss.elastic.co/u/Dixit)\
**Post date:** [October 8, 2024, 5:35am UTC](https://discuss.elastic.co/t/any-update-for-rmq-request-response-tracing-which-uses-python-pika-client/366931/5 "2024-10-08T05:35:36Z")

</div>

@basepi Please can you help with this rquest

---

<div class="post-metadata">

**Author:** ![basepi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/basepi/32/53056_2.png) [@basepi](https://discuss.elastic.co/u/basepi)\
**Post date:** [October 17, 2024, 7:09pm UTC](https://discuss.elastic.co/t/any-update-for-rmq-request-response-tracing-which-uses-python-pika-client/366931/6 "2024-10-17T19:09:54Z")

</div>

Unfortunately, I don't have the bandwidth to help with custom instrumentation. Apologies!

---

<div class="post-metadata">

**Author:** ![Dixit](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dixit/32/111369_2.png) [@Dixit](https://discuss.elastic.co/u/Dixit)\
**Post date:** [October 18, 2024, 6:43am UTC](https://discuss.elastic.co/t/any-update-for-rmq-request-response-tracing-which-uses-python-pika-client/366931/7 "2024-10-18T06:43:18Z")

</div>

thanks @basepi some sample RMQ - Produce & Consume methods (challenge is in here) in Elastic would help, would try out.

---

<div class="post-metadata">

**Author:** ![Dixit](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dixit/32/111369_2.png) [@Dixit](https://discuss.elastic.co/u/Dixit)\
**Post date:** [October 28, 2024, 6:32am UTC](https://discuss.elastic.co/t/any-update-for-rmq-request-response-tracing-which-uses-python-pika-client/366931/8 "2024-10-28T06:32:34Z")

</div>

@SundarV did you happen to implement custom elastic code or RMQ. Can you please help me with
