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

Propagating traceId to a spring-cloud-task application

Open zargarf opened this issue 3 years ago • 4 comments
trafficstars

Hi

I have a number of spring-boot services running in kubernetes. The same traceId for a request is generally propagated between services. However when a "task-launcher" service launches a spring-cloud-task via a spring-cloud-stream TaskLaunchRequest in a sink, the pod that is spawned uses a different traceId. Would someone be able to advise what the best approach is to ensure that the traceId used by the application running in the pod uses the same traceId as the task-launcher application and that the traces are therefore stacked appropriately?

Thanks

zargarf avatar Sep 12 '22 12:09 zargarf

Can you create a sample that replicates this problem? cc @cppwfs

marcingrzejszczak avatar Sep 13 '22 07:09 marcingrzejszczak

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

spring-cloud-issues avatar Sep 20 '22 07:09 spring-cloud-issues

Here is the issue that @zargarf opened on Spring Cloud Task https://github.com/spring-cloud/spring-cloud-task/issues/859

cppwfs avatar Sep 20 '22 12:09 cppwfs

I am creating a TaskLaunchRequest which is consumed by the TaskLaucherSink in spring-cloud-task-stream. This instantiates a task pod and runs an implementation of the CommandLineRunner(called QueryRunner).

However the traceId in the service that contains the TaskLauncherSink is different to the traceId in the task pod when I look at the logs.

If I pass the traceId as a property in the TaskLauchRequest to the task pod then I can force the trace id the same by injecting a tracer into the QueryRunner and using:

this.tracer.startScopedSpanWithParent("queryRunner",TraceContext.newBuilder().spanId(passedintraceid).spanId(passedinspanid).build());

However I was under the impression that the propagation of the traceid should happen out of the box without having to do this. Is this the case?

I am using spring-boot 2.7.1, spring-cloud-sleuth: 3.1.3, spring-cloud-task : 2.4.4

zargarf avatar Sep 21 '22 11:09 zargarf

This is not supported out of the box by Spring Cloud Sleuth. Since Sleuth is feature complete we are not planning to add this functionality

marcingrzejszczak avatar Feb 09 '24 12:02 marcingrzejszczak