Closed pavolloffay closed 4 years ago
OTEL agent instruments public APIs of the ExecutorService
, ForkJoinPool
etc. When a lambda is passed e.g. executor.execute(() -> {})
. The instrumentation creates a wrapper around lambda (in this case runnable) and stores a context inside. When wrapper is executed the context is restored.
The context propagation seems to be broken only when the parallel stream is used. The parallel stream uses ForkJoinPool.commonPool
. In the following code the context is not propagated in the foreEach
. However when the commonPool
is called explicitly the context is correctly propagated since all public APIs of the ForkJoinPool
wrap the execution.
IntStream.range(0, 20)
.parallel()
.forEach(value -> {
System.out.println("Thread : " + Thread.currentThread().getName() + ", value: " + value);
// currentSpan is not propagated
printSpan(TRACER.getCurrentSpan());
});
Done this is noop on our side. The only missing part is https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/709
Hello, sorry, but issue with stream.parallel() was fixed? I mean propagating traceid, because seems it isn't work in last version of https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases
Verify whether a context is being propagated in async lambdas.
Some code examples
Using
ForkJoinPool.commonPool()
:OTEL support ForkJoinPool https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/709 OT special agent ForkJoinPool: https://github.com/opentracing-contrib/java-specialagent/issues/102