OpenTelemetry aio pika Instrumentation¶
Instrument aio_pika to trace RabbitMQ applications.
Usage¶
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
AioPikaInstrumentor().instrument()
async def main() -> None:
connection = await connect("amqp://guest:guest@localhost/")
async with connection:
channel = await connection.channel()
queue = await channel.declare_queue("hello")
await channel.default_exchange.publish(
Message(b"Hello World!"),
routing_key=queue.name)
if __name__ == "__main__":
asyncio.run(main())
API¶
- class opentelemetry.instrumentation.aio_pika.AioPikaInstrumentor(*args, **kwargs)[source]¶
Bases:
opentelemetry.instrumentation.instrumentor.BaseInstrumentor
- instrumentation_dependencies()[source]¶
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