sdk-java
sdk-java copied to clipboard
Tracing context does not propagate into .thenCompose
Expected Behavior
Temporal workflows and activities should generate related spans when the Temporal client is properly configured with OpenTracing interceptors.
Actual Behavior
Some spans end up severed from the parent. This seems to be isolated to spans that are generated with a promise chain using .thenCompose. Other spans seem to work as expected.
Steps to Reproduce the Problem
- Enable trace interceptors
- Write a workflow that has at least two activities that are composed serially via .executeAsync -> .thenCompose
- Observe that the workflow and first activity end up in one span, and the second activity ends up orphaned within its own span.
Specifications
- Version: Temporal Java SDK 1.22.3
Looking at how thenCompose
is implemented
@Override
public <U> Promise<U> thenCompose(Functions.Func1<? super V, ? extends Promise<U>> fn) {
return then(
(result) -> {
if (failure != null) {
result.completeExceptionally(failure);
return;
}
try {
Promise<U> r = fn.apply(value);
result.completeFrom(r);
} catch (RuntimeException e) {
result.completeExceptionally(e);
}
});
}
...
private <U> Promise<U> then(Functions.Proc1<CompletablePromise<U>> proc) {
CompletablePromise<U> resultPromise = new CompletablePromiseImpl<>();
if (completed) {
proc.apply(resultPromise);
unregisterWithRunner();
} else {
handlers.add(() -> proc.apply(resultPromise));
}
return resultPromise;
}
Different code paths can be taken if the future is already complete or not by the time it is called. If the future is already complete then fn
is run in the calling thread so the trace context should be setup, but if the future is not ready it will be run in a callback thread without the context set.
Just curious if there is any movement on this?
No update at this time
Would you consider a PR if I submitted one?
Yes, PRs are always welcome!