You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What did you see instead?
close is not idempotent.
What version and what artifacts are you using?
Artifacts: opentelemetry-api, opentelemetry-sdk
Version: 1.21.0
How did you reference these artifacts? (excerpt from your build.gradle, pom.xml, etc)
Environment
Compiler: "AdoptOpenJDK 17.0.4.8"
OS: windows
Additional context
I'm trying to propagate spans in Camel (so that camel spans are correlated with spans from underlying libraries). Camel tracing is based on events that are not tracing-specific. Consequently, it's impossible (without significant refactoring) to guarantee that current span scope will be called exactly once.
And while it's possible to implement idempotency with wrapping scope, OTel should do it out of the box.
"Context in storage not the expected context, Scope.close was not called correctly");
}
THREAD_LOCAL_STORAGE.set(beforeAttach);
is a bit dangerous regardless of idempotency. Arguably, if this.current() != toAttach , it's best to do nothing or set an invalid context to minimize the side-effects of wrong operations with scope.
The proposal here is to do
if (current() == toAttach) {
THREAD_LOCAL_STORAGE.set(beforeAttach);
} else {
logger.log(
Level.WARN,
"Context in storage not the expected context, Scope.close was not called correctly");
}
Another proposal is to remember the thread id span was made current on and do nothing when attempting to close scope on a different thread.
Otherwise, what happens is that 'before' span from the different thread leaks to another thread where it can no longer be closed.
The text was updated successfully, but these errors were encountered:
Describe the bug
The following test (with obviously wrong behavior) fails
What happens:
opentelemetry-java/context/src/main/java/io/opentelemetry/context/ThreadLocalContextStorage.java
Lines 26 to 41 in 5b497b1
Steps to reproduce
the test above
What did you expect to see?
Close should be idempotent - after scope is closed, calling close should be noop.
It's also strongly encouraged according to docs
What did you see instead?
close is not idempotent.
What version and what artifacts are you using?
Artifacts:
opentelemetry-api
,opentelemetry-sdk
Version: 1.21.0
How did you reference these artifacts? (excerpt from your
build.gradle
,pom.xml
, etc)Environment
Compiler: "AdoptOpenJDK 17.0.4.8"
OS: windows
Additional context
I'm trying to propagate spans in Camel (so that camel spans are correlated with spans from underlying libraries). Camel tracing is based on events that are not tracing-specific. Consequently, it's impossible (without significant refactoring) to guarantee that current span scope will be called exactly once.
And while it's possible to implement idempotency with wrapping scope, OTel should do it out of the box.
It also seems that
opentelemetry-java/context/src/main/java/io/opentelemetry/context/ThreadLocalContextStorage.java
Lines 34 to 39 in 5b497b1
is a bit dangerous regardless of idempotency. Arguably, if
this.current() != toAttach
, it's best to do nothing or set an invalid context to minimize the side-effects of wrong operations with scope.The proposal here is to do
Another proposal is to remember the thread id span was made current on and do nothing when attempting to close scope on a different thread.
Otherwise, what happens is that 'before' span from the different thread leaks to another thread where it can no longer be closed.
The text was updated successfully, but these errors were encountered: