Skip to content
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

Tracing: fix explicit context propagation when running in javaagent #39602

Merged
merged 3 commits into from
Apr 9, 2024

Conversation

lmolkova
Copy link
Member

@lmolkova lmolkova commented Apr 8, 2024

Fixes #38221

See open-telemetry/opentelemetry-java-instrumentation#11042 for the context.

TL;DR:
when azure-core-tracing-otel is running inside Java OTel or ApplicationInsights agents, the otel context is relocated.
However users passing context explicitly pass the original non-relocated context.
As a result, we can't correlate with the explicit context passed by users.

We need to handle both cases.
This change detects if we're running in the agent and converts original context to the relocated one using otel-provided public APIs using reflection.

#38221 also lists documentation, which we already have in the

Users can *optionally* pass the instance of `io.opentelemetry.context.Context` to the SDKs using key **PARENT_TRACE_CONTEXT_KEY** on the [Context][context] parameter of the calling method
to provide explicit parent context.
This [sample][sample_key_vault] provides an example when parent span is picked up automatically.

and

// You can pass parent explicitly using PARENT_TRACE_CONTEXT_KEY in the com.azure.core.util.Context.
// Or, when using async clients, pass it in reactor.util.context.Context under the same key.
String response = sampleClient.methodCall("get items",
new Context(PARENT_TRACE_CONTEXT_KEY, traceContext));

@lmolkova lmolkova requested a review from trask as a code owner April 8, 2024 20:57
@lmolkova lmolkova requested a review from alzimmermsft April 8, 2024 20:58
@github-actions github-actions bot added the OpenTelemetry OpenTelemetry instrumentation label Apr 8, 2024
@lmolkova
Copy link
Member Author

lmolkova commented Apr 8, 2024

I will add a test to validate it inside the shaded plugin

Copy link
Member

@trask trask left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@lmolkova lmolkova enabled auto-merge (squash) April 9, 2024 03:12
@lmolkova lmolkova merged commit aa4c7e7 into Azure:main Apr 9, 2024
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OpenTelemetry OpenTelemetry instrumentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OTel: Document disabling reactor plugin and verify that manual context propagation works with agent
3 participants