-
Notifications
You must be signed in to change notification settings - Fork 848
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
Expose AutoConfiguredOpenTelemetrySdk to AgentListener #4831
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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 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 |
---|---|---|
|
@@ -56,6 +56,7 @@ public class AgentInstaller { | |
private static final Logger logger; | ||
|
||
static final String JAVAAGENT_ENABLED_CONFIG = "otel.javaagent.enabled"; | ||
static final String JAVAAGENT_NOOP_CONFIG = "otel.javaagent.experimental.use-noop-api"; | ||
|
||
// This property may be set to force synchronous AgentListener#afterAgent() execution: the | ||
// condition for delaying the AgentListener initialization is pretty broad and in case it covers | ||
|
@@ -112,9 +113,13 @@ public static ResettableClassFileTransformer installBytebuddyAgent( | |
|
||
setBootstrapPackages(config); | ||
|
||
AutoConfiguredOpenTelemetrySdk autoConfiguredSdk = installOpenTelemetrySdk(config); | ||
boolean enableNoopApi = config.getBoolean(JAVAAGENT_NOOP_CONFIG, false); | ||
AutoConfiguredOpenTelemetrySdk autoConfiguredSdk = | ||
installOpenTelemetrySdk(enableNoopApi, config); | ||
|
||
runBeforeAgentListeners(agentListeners, config, autoConfiguredSdk); | ||
if (!enableNoopApi) { | ||
runBeforeAgentListeners(agentListeners, config, autoConfiguredSdk); | ||
} | ||
|
||
AgentBuilder agentBuilder = | ||
new AgentBuilder.Default() | ||
|
@@ -161,7 +166,11 @@ public static ResettableClassFileTransformer installBytebuddyAgent( | |
|
||
ResettableClassFileTransformer resettableClassFileTransformer = agentBuilder.installOn(inst); | ||
ClassFileTransformerHolder.setClassFileTransformer(resettableClassFileTransformer); | ||
runAfterAgentListeners(agentListeners, config, autoConfiguredSdk); | ||
|
||
if (!enableNoopApi) { | ||
runAfterAgentListeners(agentListeners, config, autoConfiguredSdk); | ||
} | ||
|
||
return resettableClassFileTransformer; | ||
} | ||
|
||
|
@@ -187,9 +196,7 @@ private static void runBeforeAgentListeners( | |
@Nullable AutoConfiguredOpenTelemetrySdk autoConfiguredSdk) { | ||
for (AgentListener agentListener : agentListeners) { | ||
agentListener.beforeAgent(config); | ||
if (autoConfiguredSdk != null) { | ||
agentListener.beforeAgent(autoConfiguredSdk); | ||
} | ||
agentListener.beforeAgent(config, autoConfiguredSdk); | ||
} | ||
} | ||
|
||
|
@@ -238,9 +245,7 @@ && isAppUsingCustomLogManager()) { | |
} else { | ||
for (AgentListener agentListener : agentListeners) { | ||
agentListener.afterAgent(config); | ||
if (autoConfiguredSdk != null) { | ||
agentListener.afterAgent(autoConfiguredSdk); | ||
} | ||
agentListener.afterAgent(config, autoConfiguredSdk); | ||
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. The |
||
} | ||
} | ||
} | ||
|
This file contains 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 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
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 considered deprecating this but
beforeAgent(AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemetrySdk)
doesn't get called when there is a noop OpenTelemetry installed. If we think its ok to not have any agent listener hooks when noop is used, then I can go ahead and deprecate this because folks can accessAutoConfiguredOpenTelemetrySdk#getConfig()
.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.
it would be really nice to deprecate this. not sure what to do about
noop
. @jkwatson @breedx-splk are you findingnoop
useful?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 do think the noop is useful.
Over in the original issue in the other repo we chatted about the two arg
(config, sdk)
version being preferred. This two-version approach requires the SPI user to override both and hold state if they need both. It also looks weird (to me) at the call site below, because, depending on the implementation,beforeAgent()
can be called twice.My preference would be to just have the two-arg version and then later when the config problem (Config vs. ConfigProperties) is solved we can remove the config arg.
How's that sound?
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.
If we continue supporting
noop
, how would we remove the config arg once the config problem is solved? since in thenoop
caseAutoConfiguredOpenTelemetrySdk
is null, so it seems like we still need to pass around agent configuration somehowThere 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.
What about a noop implementation equivalent of the
AutoConfiguredOpenTelemetrySdk
?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.
sound good 👍
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.
What if we keep
noop
, but only callAgentListener
methods if the agent is enabled and the sdk is installed? Is there a use case for having theAgentListener
whennoop
is installed? If we did that, we could define theAgentListener
as:I prefer having access to
AutoConfiguredOpenTelemetrySdk
versusOpenTelemetry
andResource
because:OpenTelemetrySdk
instead ofOpenTelemetry
, which gives access toSdkTracerProvider
andSdkMeterProvider
instead of justTracerProvider
andMeterProvider
. This also means that we could give access toSdkLogEmitterProvider
which will probably never be accessible viaOpenTelemetry
.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.
this is a good question. I'm guessing ideally we would still install things like
RuntimeMetricsInstaller
in thenoop
case, but maybe we can live without that?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, these are all perfectly valid reasons. Okay, consider me convinced -- I suppose we can live without running a few listeners in case of
noop
; all bytecode manipulations are still done, we're just not installing a couple of metrics.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.
@trask if noop
OpenTelemetry
is installed then the runtime metrics won't have any affect, right?