spring-cloud-stream
                                
                                 spring-cloud-stream copied to clipboard
                                
                                    spring-cloud-stream copied to clipboard
                            
                            
                            
                        Observation tracing propagation is not working for consumers in bath mode
Describe the issue Distributed traceability does not seem to be working properly for Kafka consumers in batch mode.
To Reproduce Steps to reproduce the behavior:
- Start up the project located in https://github.com/ferblaca/demoKafkaBatch/tree/batch-tracing-observation
- On start-up, a list of messages to a topic is produced.
- Batch consumers consume the messages
- Access the url http://localhost:9411/zipkin/traces
- Verify that no traces are displayed for the reception of messages.
Version of the framework
- spring-boot 3.2.3
- spring-cloud 2023.0.0
Expected behavior
- Batch consumer traces are shown nested within the parent producer trace.
Additional context For consumers who are not in batch mode it works correctly.
@ferblaca We will look into it. Thanks for the sample.
@ferblaca This is by design and works as expected. Spring for Apache Kafka does not support tracing on batch listeners; it is only supported for record listeners. This is because, in a batch listener, the received records could be from multiple topics/partitions and from multiple producers where adding tracing information was optional. Since there may not be any correlations between records in the batch, the framework cannot make any assumptions about tracing them, such as providing them as a single trace ID, etc. If you convert the type signature of your listener as Message<List<String>>, you can then get a header called kafka_batchConvertedHeaders, which contains a list with the same number of entries as your payload. This list has a Map that contains the tracing headers (traceparent). However, it is up to the application to iterate over this properly and start an observation; the framework cannot do that. On the other hand, if you end up doing this, then why can't you consume the records in record mode and receive the implicit tracing capabilities available through the framework? CC @artembilan for any further insights.
Ok @sobychacko , It would be great to indicate this part in the documentation to avoid confusion.
Thank you very much!