spring-cloud / spring-cloud-stream

Framework for building Event-Driven Microservices
http://cloud.spring.io/spring-cloud-stream
Apache License 2.0
988 stars 603 forks source link

Trace ID logging inconsistencies across kafka binder and reactor kafka binder #2647

Open davidmelia opened 1 year ago

davidmelia commented 1 year ago

Hi,

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

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 commented 1 year ago

@patpatpat123 ^^

artembilan commented 1 year ago

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.

MarcelEdmundFranke commented 1 year ago

I have the same issue.

davidmelia commented 1 year ago

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

patpatpat123 commented 1 year ago

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

adamsmith118 commented 1 year ago

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