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

**URL:** <https://discuss.elastic.co/t/how-to-monitor-transactions-which-pass-through-rabbit-mq-producer-consumer-are-python-clients/332647>\
**Category:** APM\
**Tags:** python\
**Created:** [May 5, 2023, 12:29pm UTC](https://discuss.elastic.co/t/how-to-monitor-transactions-which-pass-through-rabbit-mq-producer-consumer-are-python-clients/332647 "2023-05-05T12:29:18Z")\
**Posts on this page:** 1\
**Showing post:** 4

<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:** [May 8, 2023, 6:26pm UTC](https://discuss.elastic.co/t/how-to-monitor-transactions-which-pass-through-rabbit-mq-producer-consumer-are-python-clients/332647/4 "2023-05-08T18:26:27Z")

</div>

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:

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

```

On the consumer:

```python
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)
    else:
        client.begin_transaction(transaction_type="messaging")

```

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.](https://www.elastic.co/guide/en/apm/agent/python/current/api.html#api-capture-span)

Hope that helps!

---

_[View the full topic](https://discuss.elastic.co/t/how-to-monitor-transactions-which-pass-through-rabbit-mq-producer-consumer-are-python-clients/332647)._
