spring-cloud-stream icon indicating copy to clipboard operation
spring-cloud-stream copied to clipboard

Trace ID logging inconsistencies across kafka binder and reactor kafka binder

Open davidmelia opened this issue 2 years ago • 6 comments

Hi,

I have created the prototype https://github.com/davidmelia/spring-boot-kafka-consumer-tracing to illustrate an issue summarised by

  • Trace ID is output OK in the kafka binder depending on where the log statement is in the reactor chain.
  • Trace ID is not output in the reactor kafka binder

If you follow the README after hitting http://localhost:8080/sendMessage you will see

...  INFO [aid=spring-boot-kafka-consumer-tracing,tid=,sid=,cusname=] 36173 --- [-f567995d3b2a-1] c.e.demo.consumer.TestMessagesConsumer   : Reactor Kafka Binder: This log statement does not have the trace id

...  INFO [aid=spring-boot-kafka-consumer-tracing,tid=63e4bb48fde4e7bad38152c80451f3e1,sid=7a6ca04b1324a87c,cusname=My Name] 36173 --- [container-0-C-1] c.e.demo.consumer.TestMessagesConsumer   : Kafka Binder: This log statement has the trace id

...  INFO [aid=spring-boot-kafka-consumer-tracing,tid=,sid=,cusname=] 36173 --- [     parallel-4] c.e.demo.consumer.TestMessagesConsumer   : Reactor Kafka Binder: This log statement does not have the trace id

...  INFO [aid=spring-boot-kafka-consumer-tracing,tid=,sid=,cusname=] 36173 --- [     parallel-5] c.e.demo.consumer.TestMessagesConsumer   : Kafka Binder: This log statement does not have the trace id

I have found no way to get the reactor kafka binder to log the trace ID nor can I get the following statement to log the trace ID in any binder

return Mono.just("OK").delayElement(Duration.ofMillis(10)).doOnSuccess(r -> log.info(...);

Thanks

davidmelia avatar Feb 09 '23 09:02 davidmelia

@patpatpat123 ^^

davidmelia avatar Feb 09 '23 09:02 davidmelia

See some related discussion here: https://github.com/reactor/reactor-kafka/issues/321. I think even if we don't something in the framework for simple operators, those flatMap, concatMap in the end-user code must be instrumented respectively.

artembilan avatar Feb 13 '23 13:02 artembilan

I have the same issue.

MarcelEdmundFranke avatar Feb 14 '23 21:02 MarcelEdmundFranke

Hi, I have updated my prototype in the branch https://github.com/davidmelia/spring-boot-kafka-consumer-tracing/tree/potential_fix using the new reactor Hooks.enableAutomaticContextPropagation(); which simulates the legacy Spring Cloud Sleuth

This solves the issue for the non reactive kafka binder.

Obviously as per the other thread the reactor kafka currently doesn't show trace IDs using this method.

Thanks

davidmelia avatar Feb 15 '23 18:02 davidmelia

Would be great if reactor kafka can leverage the latest micrometer with reactive support on reactor kafka level!

patpatpat123 avatar Feb 15 '23 20:02 patpatpat123

A fix/workaround would be great here?....

adamsmith118 avatar Jul 05 '23 10:07 adamsmith118