-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Fix OpenTelemetry context propagation and duplication issues #25012
Conversation
API changes have been detected in API changes - String PARENT_SPAN_KEY = "parent-span";
+ @Deprecated String PARENT_SPAN_KEY = "parent-span";
+ String TRACE_CONTEXT_KEY = "trace-context"; |
API changes have been detected in API changes - String PARENT_SPAN_KEY = "parent-span";
+ @Deprecated String PARENT_SPAN_KEY = "parent-span";
+ String PARENT_TRACE_CONTEXT_KEY = "trace-context"; |
4404cbe
to
27a6cda
Compare
27a6cda
to
d304bb9
Compare
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 still need to review the hard parts 😅
...pentelemetry/src/main/java/com/azure/core/tracing/opentelemetry/OpenTelemetryHttpPolicy.java
Outdated
Show resolved
Hide resolved
...pentelemetry/src/main/java/com/azure/core/tracing/opentelemetry/OpenTelemetryHttpPolicy.java
Outdated
Show resolved
Hide resolved
...pentelemetry/src/main/java/com/azure/core/tracing/opentelemetry/OpenTelemetryHttpPolicy.java
Outdated
Show resolved
Hide resolved
...pentelemetry/src/main/java/com/azure/core/tracing/opentelemetry/OpenTelemetryHttpPolicy.java
Show resolved
Hide resolved
...ng-opentelemetry/src/main/java/com/azure/core/tracing/opentelemetry/OpenTelemetryTracer.java
Show resolved
Hide resolved
sdk/core/azure-core/src/samples/java/com/azure/core/util/ContextJavaDocCodeSnippets.java
Outdated
Show resolved
Hide resolved
sdk/core/azure-core/src/samples/java/com/azure/core/util/tracing/TracerJavaDocCodeSnippets.java
Show resolved
Hide resolved
thank you! |
...ng-opentelemetry/src/main/java/com/azure/core/tracing/opentelemetry/OpenTelemetryTracer.java
Outdated
Show resolved
Hide resolved
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 got through the hard stuff 😅, thanks so much for getting this to work! I can't wait to auto-inject this new version from the agent 🎉
Class<?> agentContextStorageClass = Class.forName("io.opentelemetry.javaagent.instrumentation.opentelemetryapi.context.AgentContextStorage"); | ||
Class<?> agentContextClass = Class.forName("io.opentelemetry.javaagent.shaded.io.opentelemetry.context.Context"); | ||
Class<?> spanKeyClass = Class.forName("io.opentelemetry.javaagent.shaded.instrumentation.api.instrumenter.SpanKey"); | ||
Class<?> bridgingClass = Class.forName("io.opentelemetry.javaagent.instrumentation.opentelemetryapi.trace.Bridging"); | ||
Class<?> agentSpanClass = Class.forName("io.opentelemetry.javaagent.shaded.io.opentelemetry.api.trace.Span"); |
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'll add a test in the agent to make sure we don't accidentally break this from the agent side (the good news is that since we inject this from the agent we can coordinate)
API changes have been detected in API changes - String PARENT_SPAN_KEY = "parent-span";
+ @Deprecated String PARENT_SPAN_KEY = "parent-span";
+ String PARENT_TRACE_CONTEXT_KEY = "trace-context"; |
.addData(spanImplContext, "<user-current-span-context>"); | ||
Context updatedProcessContext = tracer.start("azure.eventhubs.process", processContext, | ||
Context updatedProcessContext = tracer.start("EventHubs.process", processContext, |
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.
will this change be true for Http calls too?
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.
http spans still take parent context from the same context key. At the same time, they are always children of API-calls spans created by Tracer impl, so context passed by users is a grandparent for them and it never directly affects them.
Fixes #24281, #22272
We now pass trace context in the
com.azure.util.Context
instead of span: passing span in the context is not correct: context can contain more things (span + baggage + any in-process instrumentation markers). It also leads to potentially wrong context usage in HTTP tracing policy and minor test issues in Pass the tracing context (instead of span) via the Azure Core Context #24281.TODO: Need to figure out how it could work with Support HTTP based Azure SDK service tracing by Spring Sleuth implementation #24192. UPDATE: Discussed and agreed on PARENT_TRACE_CONTEXTWe now propagate implicit context and it works with OTel reactor instrumentation (but could be even better - will work with OTel to fix it)
We now register HTTP span to suppress any further client spans created by the agent (which is the goal of this PR - [BUG] HTTP spans have wrong parent in ApplicationInsights #22272). It's done through reflection, but the long-term solution needs more baking (Instrumentation layers and suppressing duplicates open-telemetry/oteps#172).
Before:
After:
Agent (1.6.2 or 1.7.0)
![image](https://user-images.githubusercontent.com/2347409/138544171-69064f35-f3d0-4edc-bf9d-c42357b3b80a.png)
Application Insights (3.2.1) feels great too