-
Notifications
You must be signed in to change notification settings - Fork 24
Open
Labels
Description
I would like to know how to propagate the TraceId within the Java Stream API in Spring Cloud Sleuth.
In the code below, the trace_id is not propagated, and each client ends up having an individual TraceId.
TestForkJoinPool testForkJoinPool = new TestForkJoinPool(10);
Span span = tracer.nextSpan(tracer.currentSpan());
testForkJoinPool.submit(() -> {
try (SpanInScope ignored = tracer.withSpan(span)) {
IntStream.range(1, 20).parallel().forEach(idx -> {
httpClient.get(1000L);
});
} finally {
span.end();
}
}).get();However, if we modify the above code as shown below, the TraceId is propagated.
TestForkJoinPool testForkJoinPool = new TestForkJoinPool(10);
Span span = tracer.nextSpan(tracer.currentSpan());
testForkJoinPool.submit(() -> {
IntStream.range(1, 20).parallel().forEach(idx -> {
try (SpanInScope ignored = tracer.withSpan(span)) {
httpClient.get(1000L);
} finally {
span.end();
}
});
}).get();Unfortunately, applying SpanInScope to all existing Stream API code as mentioned above has its limitations. Is there a way to inject SpanInScope with minimal modifications to the existing Stream API code?
Thank you.
Reactions are currently unavailable