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
In kafka events, the traceId and spanId are not written in the logs #3146
Comments
Apparently this is a duplication of: micrometer-metrics/micrometer#4859. Any chances that you can share with us a simple project where we can reproduce, debug and play with? Thanks |
Here is simple example https://github.com/oooximionnn/KafkaTracing/ trace id and span id are empty |
I have similar problem. @Bean
public DefaultErrorHandler errorHandler() {
BackOff fixedBackOff = new FixedBackOff(0, 0);
return new DefaultErrorHandler(
(consumerRecord, exception) -> log.error("Failed to process ATG message from topic:{}. key:{}",
consumerRecord.topic(), consumerRecord.key(), exception),
fixedBackOff);
} When I was using spring boot 3.1.9 logs produced by this handler had MDCs (traceId, spanId and one custom BaggageField). After upgrade to spring boot 3.2.4 MDCs are gone. |
it is not similar. |
thanks for the sample! I didn't run it yet, but looking into the screenshot, I see that your |
So, this one was done before in Spring Sleuth: https://github.com/spring-cloud/spring-cloud-sleuth/blob/3.1.x/spring-cloud-sleuth-instrumentation/src/main/java/org/springframework/cloud/sleuth/instrument/kafka/TracingKafkaProducer.java#L148. |
Just tested the fix against this simple unit test:
The output in logs like this:
I think this is what you are looking for. Will open PR soon. |
Fixes: spring-projects#3146 There is a requirement to see logs correlated even in the `CompletableFuture` result after `KafkaTemplate.send()` operation * Add `observation.openScope()` into the `buildCallback()` logic **Auto-cherry-pick to `3.1.x` & `3.0.x`**
Fixes: #3146 Propagate `KafkaTemplate` observation callback. There is a requirement to see logs correlated in the `CompletableFuture` result after `KafkaTemplate.send()` operation. * Add `observation.openScope()` into the `buildCallback()` logic **Auto-cherry-pick to `3.1.x` & `3.0.x`**
Fixes: #3146 Propagate `KafkaTemplate` observation callback. There is a requirement to see logs correlated in the `CompletableFuture` result after `KafkaTemplate.send()` operation. * Add `observation.openScope()` into the `buildCallback()` logic **Auto-cherry-pick to `3.0.x`** # Conflicts: # spring-kafka/src/main/java/org/springframework/kafka/core/KafkaTemplate.java
Fixes: #3146 Propagate `KafkaTemplate` observation callback. There is a requirement to see logs correlated in the `CompletableFuture` result after `KafkaTemplate.send()` operation. * Add `observation.openScope()` into the `buildCallback()` logic # Conflicts: # spring-kafka/src/main/java/org/springframework/kafka/core/KafkaTemplate.java (cherry picked from commit fffd5ef)
Thank you. Please tell me what I need to do in the end to get the traceId and span Id in the producer and consumer.
we are using spring boot 3 |
@oooximionnn , |
@artembilan |
Doesn't look like your question is related to the problem we have discussed in this issue. The
|
@artembilan |
Describe
In kafka events, the traceId and spanId are not written in the logs
Environment
Java 17. Spring boot starter 3.2.2
We use the following dependencies for tracing:
Kafka Template Bean:
application.yml file
code:
What's going on
In this case, the kafka topic places traceId and span Id in headers, but the logging pattern does not find these traceId and spanId and accordingly does not write them in logs.
What have we changed
We added Map<String, String> copyOfContextMap = MDC.getCopyOfContextMap(); to producer. and information about traceId and spanId began to appear in the logs.
Is there a better solution for not writing this?: Map<String, String> copyOfContextMap = MDC.getCopyOfContextMap();
We also used this link: https://github.com/micrometer-metrics/micrometer-samples/blob/main/kafka-producer/src/main/java/com/example/micrometer/ManualConfiguration.java
It didn't help.
The problem is related to the transition to spring boot 3. On Spring boot 2, the Sleuth library was used for tracing and kafka event tracing was present. But when we started using examples and instructions from micrometer, trace id did not appear, it only appeared in kafka headers
The text was updated successfully, but these errors were encountered: