OpenTelemetry aio pika Instrumentation

Instrument aio_pika to trace RabbitMQ applications.


Start broker backend

docker run -p 5672:5672 rabbitmq

Run instrumented task

import asyncio

from aio_pika import Message, connect
from opentelemetry.instrumentation.aio_pika import AioPikaInstrumentor


async def main() -> None:
    connection = await connect("amqp://guest:guest@localhost/")
    async with connection:
        channel = await
        queue = await channel.declare_queue("hello")
        await channel.default_exchange.publish(
            Message(b"Hello World!"),

if __name__ == "__main__":


class opentelemetry.instrumentation.aio_pika.AioPikaInstrumentor(*args, **kwargs)[source]

Bases: opentelemetry.instrumentation.instrumentor.BaseInstrumentor


Return a list of python packages with versions that the will be instrumented.

The format should be the same as used in requirements.txt or pyproject.toml.

For example, if an instrumentation instruments requests 1.x, this method should look like:

def instrumentation_dependencies(self) -> Collection[str]:

return [‘requests ~= 1.0’]

This will ensure that the instrumentation will only be used when the specified library is present in the environment.

Return type