-
Notifications
You must be signed in to change notification settings - Fork 875
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
Question/problem: agent context shading vs explicit context propagation #11042
Comments
Shading plugins try to rename everything that looks like a class name, usually you can trick them with something like I didn't try to run your application, but I guess that the issue is that you expect to set the context that is used in application under |
Thanks a lot @laurit! I decided to start with hacky but simple Once the Azure/azure-sdk-for-java#39602 is merged and released, I want to add a test inside the https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/instrumentation/azure-core/azure-core-1.36/javaagent/src/testAzure/java/io/opentelemetry/javaagent/instrumentation/azurecore/v1_36/AzureSdkTest.java to validate if it works (validated manually for now). So could you please keep this issue open until then and assign it to me? Thanks! |
FYI while this may work in the short term it is likely that we will break it when work on #8999 resumes. |
I am having maybe similar issues while using AwsXrayPropagator's |
@MrSinisterX Agent renames opentelemetry api classes as to not conflict with application provided opentelemetry api. |
Is your feature request related to a problem? Please describe.
Azure SDKs are instrumented natively. We have a plugin (azure-core-tracing-opentelemetry) shaded into the otel java agent.
Our SDKs are reactor/async heavy and we can't always rely that context propagation happens correctly. Also reactor instrumentation has relatively high overhead and some users want to disable it.
To help with context propagation we recommend users to pass it over explicitly through our own
com.azure.core.util.Context
property bag.It looks similar to the following:
Life's good: tests are green, applications that manually instrument by installing the plugin work just fine.
But it does not work with the agent - as long as plugin is shaded, it does not recognize the type of the context in
PARENT_TRACE_CONTEXT_KEY
key.Repro
context_prop_issue.zip
run with
-javaagent:"path/to/opentelemetry-javaagent.jar" -Dotel.traces.exporter=logging -Dotel.logs.exporter=none -Dotel.metrics.exporter=none
It'll print two scenarios:
Root cause
The plugin needs to cast the object behind
PARENT_TRACE_CONTEXT_KEY
toio.opentelemetry.context.Context
to use it as an explicit parent to new spans.But during shading and relocation, the type I need to cast to becomes
io.opentelemetry.javaagent.shaded.io.opentelemetry.context.Context
.The context created by the application is
io.opentelemetry.javaagent.instrumentation.opentelemetryapi.context.AgentContextWrapper
and it implements the originalio.opentelemetry.context.Context
, therefore it can't be used as parent.Describe the solution you'd like
I'd like users to be able to pass me context explicitly that I can correlate with.
Ideally, native instrumentations should not worry about relocation/shading at all, but I'd be happy to add any duct tape and detect that plugin runs in the agent.
So essentially I'm looking for any guidance on how to solve this either in the shaded instrumentation part, or inside the azure plugin.
Describe alternatives you've considered
I tried detecting that I'm in the agent and calling
AgentContextStorage.toAgentContext
to convert user-passed-context to the shaded one.The only way however, I can resolve this method with reflection is by iterating over all methods on the class like
because even string literals in
Class.forName("io.opentelemetry.context.Context")
are rewritten to the new shaded context type.The text was updated successfully, but these errors were encountered: