-
Notifications
You must be signed in to change notification settings - Fork 373
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
[OpenTracing] Fix context propagation between OpenTracing and Datadog #518
[OpenTracing] Fix context propagation between OpenTracing and Datadog #518
Conversation
# effectively ends up "assigned to a scope", by virtue of being added to the | ||
# Context. Hence, it would behave more like an active span, which is why it | ||
# should only be here. | ||
unless child_of || ignore_active_scope |
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 block is responsible for allowing OpenTracer spans to append to traces that were created by Datadog auto-instrumentation. e.g. datadog.span
--> open_tracer.span
.
3d223ff
to
fab0f89
Compare
# This is mostly for the benefit of any out-of-the-box tracing from Datadog, | ||
# such that spans generated by that tracing will be attached to the OpenTracer | ||
# parent span. | ||
datadog_tracer.provider.context = span.datadog_span.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.
This line is responsible for allowing Datadog auto-instrumentation spans to append to traces that were created by OpenTracer. e.g. open_tracer.span
--> datadog.span
.
|
||
private | ||
|
||
def inherited_span_context(parent, ignore_active_scope: false) |
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 just a refactor from #start_span
.
fab0f89
to
0612ae0
Compare
Made some significant changes to how context is resolved and written to. This should be ready for review. |
child_of = if scope_manager.active | ||
scope_manager.active.span.context | ||
else | ||
SpanContextFactory.build(datadog_context: datadog_tracer.call_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.
👍
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.
👍
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.
Looks good to me, I had a nearly identical approach with the Python tracer.
@@ -204,6 +228,58 @@ def current_trace_for(object) | |||
end | |||
end | |||
end | |||
|
|||
context 'preceded by a Datadog span' do |
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 { expect(child_datadog_span.trace_id).to eq(parent_datadog_span.trace_id) } | ||
end | ||
|
||
context 'followed by a Datadog span' do |
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.
👍
@@ -51,6 +51,30 @@ def current_trace_for(object) | |||
end | |||
|
|||
context 'for a nested span' do | |||
context 'when there is no active scope' do |
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.
👍
…#518) * Fixed: OpenTracer::Tracer not using child_of SpanContext properly. * Changed: OpenTracer to append its spans to Datadog auto-instrumentation.
When using
ddtrace
OpenTracer in conjunction with an app already instrumented byruby-rack-tracer
, we were seeing some disjoint traces. Spans generated byddtrace
out of the box instrumentation was not ending up parented by the OpenTracing integration parent span (in this case, Rack), resulting in multiple traces that should have appeared as one.To fix this, the pull request does two things:
SpanContext
objects aschild_of
. We need to make sure theDatadog::Context
object that comes from this is set on the tracer, such that the following generated Datadog span inherits the proper trace info (trace ID, parent ID.) It was not actually using this context properly before.nil
to thestart_span
method which would create a brand new context that would not be re-used on subsequent spans. We now make sure its passing aDatadog::Context
tostart_span
.