-
Notifications
You must be signed in to change notification settings - Fork 890
Description
When using confluent_kafka producer with opentelemetry-instrumentation-confluent-kafka,
Using the confluent_kafka.Producer.produce with topic in kwargs will result in opentelemetry failing to extract the topic.
Steps to reproduce
from opentelemetry.instrumentation.confluent_kafka import ConfluentKafkaInstrumentor
ConfluentKafkaInstrumentor().instrument()
from confluent_kafka import Producer
producer = Producer(...)
producer.produce(topic="my.topic", value=b'data')What is the expected behavior?
OTEL exports data about a produced message to topic my.topic
What is the actual behavior?
OTEL fails to export - the topic is failed to be extracted in ConfluentKafkaInstrumentor.wrap_produce.
Using the following code will work, passing the topic as arg instead of kwarg
producer.produce("my.topic", value=b'data')Additional context
I can see the bug clearly. In the beginning of ConfluentKafkaInstrumentor.wrap_produce,
The topic is extracted using this code:
topic = kwargs.get("topic")
if not topic:
topic = args[0]Later in the method, the topic is extracted again, using
topic = KafkaPropertiesExtractor.extract_produce_topic(args)This however is looking at args only and not covering cases of the topic being in kwargs.
I suggest moving the code above that looks at both args and kwargs into KafkaPropertiesExtractor.extract_produce_topic