-
Notifications
You must be signed in to change notification settings - Fork 64
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
Propagation from Kafka to RestTemplate broken #26
Comments
@timtebeek you can extract SpanContext from headers (copied to string map) and then use it as parent:
|
Thanks for the quick reply; While that could in theory work; it seems quite cumbersome to do that for all of my KafkaListeners across all of my services, just to be able to pass tracing data from kafka to rest. Is there another way? Some hooks within opentracing-kafka-spring maybe? |
I am also curious why this wasn't done automatically when invoking listeners annotated with Btw, the extract example above seems incorrect, because it will extract the span context stored in the message by the producer. The consumer already read that context and created another span that is also serialized back into the message with something like |
There is no easy way, at least not figured out yet.
Sure, but there is no solution. It's more like possible direction to try if you know how it works. |
there is an extract adapter class that could be used with second=true argument, but its constructor is not public. I had to write my own adapter, because the example above creates the span representing the handler as descending directly from producer span, which is logically incorrect (it should reference the consumer span). |
@yurishkuro could you submit PR if it can be useful for others? |
Both the consumer and producer in this library are a bit off, they open and close a span immediately, this is more forgiveable in the case of the producer as writing to kafka isn't particularily interesting and this does inject the SpanContext into the kafka headers (but if a span is being created around the message it should track some work). In the case of the consumer it is the expectation that the span cover the processing of a message but the kafka batch based apis don't really make this very simple to implement as a library. The message listener container apis for spring seem like they could do this. |
Is there a nice solution already? There is a good article with a workaround idea: https://zhaohuabing.com/post/2019-07-02-using-opentracing-with-istio-english/ Will the workaround based on AOP (aspect around methods with @Aspect
@RequiredArgsConstructor
public class KafkaListenerTracingAspect {
private final Tracer tracer;
@Around("@annotation(org.springframework.kafka.annotation.KafkaListener)")
public void aroundAdvice(ProceedingJoinPoint jp) throws Throwable {
ConsumerRecord record = (ConsumerRecord) jp.getArgs()[0];
SpanContext spanContext = TracingKafkaUtils.extractSpanContext(record.headers(), tracer);
Span span = tracer
.buildSpan(jp.getTarget().getClass().getName())
.asChildOf(spanContext)
.start();
tracer.activateSpan(span);
jp.proceed();
span.finish();
}
} |
It makes sense to have a look at Spring Sleuth implementation: https://github.com/spring-cloud/spring-cloud-sleuth/blob/e6ebce4505097aacff72a97481ab571384e08055/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/messaging/TraceMessagingAutoConfiguration.java#L140. It is easily adaptable to |
…kaListener` support
…kaListener` support
…kaListener` support
This is fixed in version |
Hi all,
Here's a minimal project to demonstrate an issue I'm having:
https://github.com/timtebeek/opentracing-demo
The project consists of three components: a web frontend, kafka backend and rest backend. The frontend calls the rest backend, and puts five messages on kafka. The Kafka backend picks up the messages and post to the rest backend as well.
The problem I'm having is in the
@KafkaListener
here: https://github.com/timtebeek/opentracing-demo/blob/master/demo-backend-kafka/src/main/java/demo/kafkabackend/DemoKafkaListener.java#L42It correctly picks up and reports the trace ids coming in on Kafka; as evidenced by the logs here:
However, within the
@KafkaListener
the tracer.activeSpan remains null, so the information is not propagated with the rest calls to the rest backend:I would have expected
opentracing-kafka-spring
to set the activeSpan on my tracer bean to make it available within my@KafkaListener
method, so it'll get propagated correctly using the RestTemplate instrumented throughopentracing-spring-jaeger-cloud-starter
.What needs to change to make this work? At present my trace information is lost and a new trace is started, making it unsuitable for full tracing.
The text was updated successfully, but these errors were encountered: