-
Notifications
You must be signed in to change notification settings - Fork 290
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
Update OpenTelemetry Bridge to support OTel Java API 0.11.0 #2054
Conversation
4b3b774
to
fa5d213
Compare
...datadog/trace/instrumentation/opentelemetry/context/OpenTelemetryContextInstrumentation.java
Show resolved
Hide resolved
dirName = 'test' | ||
} | ||
} | ||
// Can't have a latest test until a new version is released. |
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 don't understand why. Care to elaborate?
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.
Our latestDepTest
has an assertion to verify that the version it is testing isn't the same as what is verified in test
to ensure we declare the wildcard properly. There is a new version out now (0.10.1
), so I can fix this.
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 that assert
is counterproductive. I would have updated the gRPC instrumentation when I had time if it weren't for this.
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.
Before I added that, we had cases where we thought we were testing something new but were not. The assertion was an attempt to prevent a regression. Seems silly to run the same tests twice.
@@ -73,6 +73,8 @@ | |||
|
|||
DDId getSpanId(); | |||
|
|||
boolean isRemote(); |
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 does isRemote
mean?
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 the SpanContext was propagated from a remote parent
ie, if the context was the result of a distributed trace propagation. (extract
call)
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.
Some minor nits but looks correct from a "upgrade to latest version" perspective. I assumed the previous version was correct
.../opentelemetry/src/main/java8/datadog/trace/instrumentation/opentelemetry/TypeConverter.java
Outdated
Show resolved
Hide resolved
dd-java-agent/instrumentation/opentelemetry/src/test/groovy/OpenTelemetryTest.groovy
Outdated
Show resolved
Hide resolved
internal-api/src/main/java/datadog/trace/bootstrap/instrumentation/api/AgentTracer.java
Show resolved
Hide resolved
dd-java-agent/instrumentation/opentelemetry/src/test/groovy/OpenTelemetryTest.groovy
Show resolved
Hide resolved
dd-java-agent/instrumentation/opentelemetry/src/test/groovy/OpenTelemetryTest.groovy
Show resolved
Hide resolved
@Advice.OnMethodExit(suppress = Throwable.class) | ||
public static void updateScope( | ||
@Advice.Argument(0) Context context, @Advice.Return(readOnly = false) Scope scope) { | ||
Span span = Span.fromContext(context); |
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'd like some more explanation as to what is happening here.
I don't really understand the need for WrappedScope.
I'd expect the OTelScope to be a wrapper around an AgentScope -- and the fact that they are closed together suggests they have the same lifecycle.
.../opentelemetry/src/main/java8/datadog/trace/instrumentation/opentelemetry/TypeConverter.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
public AgentSpan.Context toAgentSpanContext(final SpanContext spanContext) { | ||
// Currently assuming the span context was created above so it should contain an existing |
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.
Given that this is public, this is worrying assumption. Should this method just be private/package visible instead?
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 will make it package visible, but I don't think that will avoid the problem. Someone can still call SpanContext.create
and pass it into SpanBuilder.setParent
and it will result in this problem. Fixing this would require significant changes to the core.
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.
Can you please describe the ramifications of calling SpanContext.create and SpanBuilder.setParent?
In general, I don't want to assume that significant changes to the core aren't necessary without fully understanding the problem first.
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 have updated to remove this assumption.
.../opentelemetry/src/main/java8/datadog/trace/instrumentation/opentelemetry/TypeConverter.java
Outdated
Show resolved
Hide resolved
|
||
@Override | ||
public Span recordException(Throwable throwable, Attributes attributes) { | ||
delegate.addThrowable(throwable); |
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.
Shouldn't this attach the Attributes as well? Or are those Attributes of the Throwable?
If the later, a comment would help here.
dd-java-agent/instrumentation/opentelemetry/src/test/groovy/OpenTelemetryTest.groovy
Show resolved
Hide resolved
dd-java-agent/instrumentation/opentelemetry/src/test/groovy/OpenTelemetryTest.groovy
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 have few concerns mostly around WrappedScope & performance.
public static void beforeBuild(@Advice.This OpenTelemetry.Builder builder) { | ||
ContextStore<SpanContext, AgentSpan.Context> spanContextStore = | ||
InstrumentationContext.get(SpanContext.class, AgentSpan.Context.class); | ||
builder.setTracerProvider(new OtelTracerProvider(spanContextStore)); |
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.
How deeply does OTelTracerProvider & OTelContextPropagators get checked by muzzle?
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 see both classes enumerated in the printReferences
which suggests they are covered sufficiently. Is there something specific you're looking for?
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 want to know how deeply we check that OTelTracerProvider and OtelContextPropagators fit the latest OTel API. For instance, do we check that OTelTracerProvider implements all the necessary methods.
Otherwise, I think this has holes where we'll activate when we shouldn't. I think that is what happened recently with servlet-3.1. Mostly, I'm just curious, and I'm fine with addressing that issue in a separate PR.
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.
Muzzle is validating those classes right now, but we have known issues with the depth that muzzle validates. I don't think that is specific to this PR. I suggest we schedule a separate effort for improving muzzle.
} | ||
|
||
public AgentSpan.Context toAgentSpanContext(final SpanContext spanContext) { | ||
// Currently assuming the span context was created above so it should contain an existing |
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.
Can you please describe the ramifications of calling SpanContext.create and SpanBuilder.setParent?
In general, I don't want to assume that significant changes to the core aren't necessary without fully understanding the problem first.
internal-api/src/main/java/datadog/trace/bootstrap/instrumentation/api/AgentTracer.java
Show resolved
Hide resolved
The more I think about this -- the more I think this isn't quite the right approach. I think if we're going to have a bridge for OTel. We should have a package similar to ddtrace-ot. I think the instrumentation based solution is good for those using the full agent, but using the full agent should be optional. In my opinion, the adapters should not and cannot rely on instrumentation. I think that means we'll have to push OpenTel's more generic Context concept into our core. Added an optional context field onto our Scope seems fairly straight-forwarded. Although, I'd prefer that we don't actually have our Scope depend on OTel directly. The tricky part appears to be deciding how Context is propagated. I think for the bridge alone we can wait on deciding, since OTel users are expected to propagate Context explicitly. However when integrated with our full agent, we'll need to think about how we lazily materialize a Context when the Scope is created by our instrumentation or through our OpenTracing bridge. |
I'm going to put this back in draft until we make progress on the context issue. |
fa5d213
to
e3911b9
Compare
bf7f42b
to
8ce7658
Compare
e3911b9
to
fc25c76
Compare
Remove some of the interfaces from the wrapped objects to stop encouraging casting to our interfaces as a way to integrate. Add instrumentation to sync our context with the new otel context. Due to implementation differences, there are still some edge cases where they can get out of sync.
fc25c76
to
10aee28
Compare
Going to close this until we get around to the prerequisite scope manager changes. |
I'm considering using datadog vs splunk as an opentelemetry endpoint. I'm curious to know-- is this actively being worked on? I'd love to be able to use my existing opentelemetry instrumentation with DataDog (without needing to run a separate opentelemetry collector). |
@dajulia3 Would you mind filing a support ticket (support@datadoghq.com) so we can get more details on your use case and figure out a good path forward? Thanks! |
@tylerbenson sure thing! |
Hey @tylerbenson, as the Opentracing library is deprecated, what are the plans to support, so that we can use custom instrumentation with all other goodness of datadog continuous profiling and the like? There is also this related issue |
@reify-marcio-faria Adding support for OpenTelemetry is definitely on our roadmap, but I can't give you any solid dates. In the meantime it is still possible to use the OpenTracing API for custom instrumentation, just because it's deprecated doesn't mean that the artifacts will disappear from maven central, and if you switch to OpenTelemetry later, there is a compatibility layer available. |
See also #1605.
To enable:
System Property:
-Ddd.integration.opentelemetry-beta.enabled=true
Environment Variable:
DD_INTEGRATION_OPENTELEMETRY_BETA_ENABLED=true
Remove some of the interfaces from the wrapped objects to stop encouraging casting to our interfaces as a way to integrate. (We will need to expose better APIs in the future, depending on what we want to allow.)
Add instrumentation to sync our context with the new otel context. Due to implementation differences, there are still some edge cases where they can get out of sync. (See the test for a demonstration of this.)
(If you skip over the first commit where the classes get moved, it gives a nicer diff.)