Skip to content

aiokafka: cannot trace message consuming with auto-instrumentation #3465

@andreaturli

Description

@andreaturli

What problem do you want to solve?

When running https://aiokafka.readthedocs.io/en/stable/#aiokafkaconsumer, traces are not produced when using zero-code instrumentation similar to https://opentelemetry.io/docs/languages/python/getting-started/#instrumentation

Describe the solution you'd like

I'd like aiokafka consumer to produce traces with zero-code instrumentation

Describe alternatives you've considered

Having something like the following

async def consume():
    consumer = AIOKafkaConsumer(
        'my_topic', 'my_other_topic',
        bootstrap_servers='localhost:9092',
        group_id="my-group")
    # Get cluster layout and join group `my-group`
    await consumer.start()
    try:
        # Consume messages
        async for msg in consumer:
            print("consumed: ", msg.topic, msg.partition, msg.offset,
                  msg.key, msg.value, msg.timestamp)
    finally:
        # Will leave consumer group; perform autocommit if enabled.
        await consumer.stop()

I've tried to get traces using

async def main():
   consume()

and also

async def main():
   with tracer.start_as_current_span("kafka-consumer") as span:
      consume()

but nothing gets created in my OTEL exporter

Additional Context

Using

opentelemetry-instrumentation-aiokafka==0.53b1 and python 3.13

Would you like to implement a fix?

None

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions