-
Notifications
You must be signed in to change notification settings - Fork 870
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple trace Id's generated from kafka consumer #2531
Comments
We have also the same problem. We use spring boot Kafka consumer. When consumer listens to batch message every operation has its own trace ids instead of spanId. There is no problem when no batch message consumer. I think it's related to #1890 |
@previousdeveloper
Please share your configuration for "no batch message consumer" |
Hi, First step, a connector produces a message, insert it into kafka. The message contains a "traceparent" header (displayed in akhq). The second connector consumes the message to make external http requests. We have upgraded to version 1.0.0 and the problem is still there. |
@anuraaga hey do you have any idea about this issue? |
@previousdeveloper I'm not an expert in Kafka so it will take a bit to dig in. But the main thing that comes to mind is currently, I don't think we have instrumentation of reactive streams with kafka client which is used in the sample app I wouldn't be surprised if this breaks context propagation into the consumer, which would mean we need to implement support for it. |
If you are still having this issue, can you try with the latest 1.13.1? there were a couple of related kafka instrumentation fixes that could resolve this issue |
I have tried version 1.13.1 of the javaagent and it still does not work with batch listeners. Is there a possibility to manually add the links from all the messages in the batch to the auto generated spans? |
Hey @m-kay , |
I'm using spring-kafka 2.8.5 and spring-cloud-stream-binder-kafka 3.2.2. Therefore my consumer is defined as function bean and not with a |
Hmm, that's possible - we're only testing plain spring-kafka usage. Can you prepare a small repro app? That'd really help us pinpoint the issue. |
I have created a demo app with 2 consumers, one is consuming the messages in batch mode and the other one as single messages: https://github.com/m-kay/otel-demo-http-sink When sending a message to the topic |
I also added a batch listener using the annotation |
Is there something I could do with manual instrumentation to get around this issue? Maybe add all the trace parents from the batch as links to the current span which is generated from auto instrumentation? |
@mateuszrzeszutek did you already have a chance to look into this? |
Hey @m-kay , |
Do you have any progress on this? We have also the same issue... |
I think the issue is at instrumentation/kafka/kafka-clients/kafka-clients-0.11. There is an instrumentation called ConsumerRecordsInstrumentation. It has an inner class IteratorAdvice that is applied to org.apache.kafka.clients.consumer.ConsumerRecords#iterator() method. Basically, the advice wraps the result of the iterator() method using a TracingIterator object. That object, has two main overrides:
In our case, we are using Camel as an abstraction of Kafka, but the issue can apply to others libraries/frameworks. Camel processes the ConsumerRecords at KafkaRecordProcessorFacade#processPolledRecords(). The root cause of the issue is hasNext() is called twice: while (!lastResult.isBreakOnErrorHit() && recordIterator.hasNext() && !isStopping()) {
ConsumerRecord<Object, Object> record = recordIterator.next();
lastResult = processRecord(partition, partitionIterator.hasNext(), recordIterator.hasNext(), lastResult, kafkaRecordProcessor, record);
...
} So, the process span (and the context) is closed before the expected, and a new traceId is created for the following spans. UPDATE: |
Describe the bug
We have deployed three services Service A, Service B and Service C. Service A interacts with Service B via API call and drops a message to Kafka Topic which is consumed by Service C. Service C consumes the record and calls external API call and inserts data into database. We observe multiple trace Id's generated for database and external API calls from kafka consumer instead of multiple span Id's.
Services Interaction: https://github.com/sunvuz/OpenTelemetry-poc/blob/30cdb74b4ac53bbba08fbc510e5900b3dc6bdf12/Kafka%20Consumer%20-New%20Traceid%20issue.PNG
Zipkin: Image with multiple trace Id's from consumer https://github.com/sunvuz/OpenTelemetry-poc/blob/30cdb74b4ac53bbba08fbc510e5900b3dc6bdf12/Kafka%20Consumer%20-New%20Traceid%20issue%20-Zipkin.PNG
Steps to reproduce
Sample Service's mimicking above behavior has been updated at : https://github.com/sunvuz/OpenTelemetry-poc
What did you expect to see?
Span Id for database and external API call Interaction instead of Trace Id's
What did you see instead?
New Trace Id's generated for database and external API interaction.
What version are you using?
v1.0.0 same is the behavior with 0.x.x versions
Environment
JDK 8+
OS : Linux
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: