open-telemetry / opentelemetry-python-contrib

OpenTelemetry instrumentation for Python modules
https://opentelemetry.io
Apache License 2.0
698 stars 579 forks source link

opentelemetry-instrumentation-aio-pika to support QueueIterator #1993

Open akalex opened 11 months ago

akalex commented 11 months ago

Is your feature request related to a problem? It was noticed that when using opentelemetry-instrumentation-aio-pika with QueueIterator (an example https://aio-pika.readthedocs.io/en/latest/apidoc.html#aio_pika.RobustQueue.iterator), trace context information carried by the message is ignored or not correctly parsed.

Describe the solution you'd like It would be great to make it work with QueueIterator and use trace context from the message.

Describe alternatives you've considered N/A

Additional context As a temporary solution, this could be solved with the following code:

from opentelemetry.instrumentation.aio_pika.callback_decorator import CallbackDecorator
...
decorated_callback = CallbackDecorator(tracer, queue).decorate(self.on_message)
while True:
    async with queue.iterator() as queue_iter:
        async for message in queue_iter:
            await decorated_callback(message)  # type: ignore
    await asyncio.sleep(0.1)
hxyannay commented 2 months ago

+1