-
Notifications
You must be signed in to change notification settings - Fork 902
GlobalOpenTelemetry.get()
should never returns obfuscated Noop OpenTelemetry
#7452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
quaff
wants to merge
1
commit into
open-telemetry:main
Choose a base branch
from
quaff:patch-1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,4 +115,11 @@ void toString_noop_Valid() { | |
+ "propagators=DefaultContextPropagators{textMapPropagator=NoopTextMapPropagator}" | ||
+ "}"); | ||
} | ||
|
||
@Test | ||
void neverReturnsObfuscatedNoop() { | ||
assertThat(GlobalOpenTelemetry.get()).isSameAs(OpenTelemetry.noop()); | ||
// ensure sequential calls of GlobalOpenTelemetry.get() return same object | ||
assertThat(GlobalOpenTelemetry.get()).isSameAs(OpenTelemetry.noop()); | ||
Comment on lines
+121
to
+123
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that storing the result of |
||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should flip this such that
GlobalOpenTelemetry.get()
always returns obfuscated opentelemetry, regardless of whether its noop or another instance. Something like:Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comment above, I need to check whether global
OpenTelemetry
is registered.I think it's fine to treat noop specially since it's exposed by public API
OpenTelemetry.noop()
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I don't think comparison to
OpenTelemetry.noop()
is the right way to do that.@open-telemetry/java-approvers - I think we need to be consistent here and obfuscate either ALL or NONE of the responses to calling
GlobalOpenTelemetry.get()
. And of course the risk with not obfuscating is that API users could cast toOpenTelemetrySdk
and call things like shutdown, flush.We could choose to non obfuscate and have the autoconfigure module obfuscate before calling
GlobalOpenTelemetry.set()
, but I think this still exposes too much of a foot gun. Too easy to accidentally setGlobalOpenTelemetry
to a non-obfuscated version and run into the problems above.The core thing that @quaff is asking for has come up before: How can I check if
GlobalOpenTelemetry
is set without causing the side affect of setting it?If we want to support this, we should add something like a
GlobalOpenTelemetry#getIfSet()
method, whose response is@Nullable
and which is null if set has not been called. This would allow callers to atomically check if set has been called and if so, use the result for whatever they need. We could take a naive approach like addingGlobalOpenTelemetry#isSet
, but this has race conditions in it.The key question here is when would we recommend calling this
GlobalOpenTelemetry#getIfSet()
method?The whole point of
GlobalOpenTelemetry
's current design is that it avoids hard-to-debug initialization questions by ensuring that all calls toGlobalOpenTelemetry.get()
get the same result every time. Does addinggetIfSet
break that? What about the use case @quaff brings up which is essentially: if the agent is present, I want to use theOpenTelemetry
instance provided by it, else I want to configure my own instance.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain why? the instance returned by public API
OpenTelemetry.noop()
is immutable, it is safe enough.I don't like it, we introduce
Noop
to avoid returnnull
, but it breaks the contract here.I don't like it neither, but it's better than
GlobalOpenTelemetry#getIfSet()
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I don't like the idea of having to provide guidance to users of the form: check if
GlobalOpenTelemetry.get() == OpenTelemetry.noop()
. It feels weird to have to do that comparison. Also, it gives special meaning / speecial treatment toOpenTelemetry.noop()
when I think the more precise question we're trying to answer is "was GlobalOpenTelemetry set"?On the other hand, the
getIfSet()
andisSet
are ugly because now our guidance becomes more situational:getIfSet()
/isSet()
if you don't want the side affectWell, what's our guidance for when you do or do not want the side affect?
I guess I'm softening my stance, but I still wish we could have a more reliable / idiomatic way to signal to the caller that
GlobalOpenTelemetry
was not set. On the point of a more reliable signal- its totally possible for someone else to provide their ownOpenTelemetry
implementation that is a noop. We essentially do this here - we configure theOpenTelemetrySdk
in such a way that it operates likeOpenTelemetry.noop()
, but fulfills the fullOpenTelemetrySdk
contract. And yet this instance ofOpenTelemetry
is obfuscated and callers ofGlobalOpenTelemetry.get()
have no way of knowing that its effectively a noop.We could do something like add a method:
boolean OpenTelemetry#isNoop()
so that implementations could signal that they are a noop in an unambiguous way.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
People may set
OpenTelemetry.noop()
or their own noop implementation, still cannot distinguish whetherGlobalTelemetry.set()
is called or not.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well they can't do that with the solution in this PR either.
We'll need to decide whether for use cases like yours, whether: its important to determine that GlobalOpenTelemetry was set, OR that the resolved GlobalOpenTelemetry instance is a noop (remember that
GlobalOpenTelemetry.get()
is guaranteed to return the same instance for the entire application lifecycle).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not both?