-
Notifications
You must be signed in to change notification settings - Fork 377
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
Add option to inherit service name from the parent span #3685
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,7 +48,8 @@ def initialize( | |
tags: nil, | ||
trace_id: nil, | ||
type: nil, | ||
links: nil | ||
links: nil, | ||
inherit_parent_service: false | ||
) | ||
# Ensure dynamically created strings are UTF-8 encoded. | ||
# | ||
|
@@ -90,6 +91,8 @@ def initialize( | |
# Subscribe :on_error event | ||
@events.on_error.wrap_default(&on_error) if on_error.is_a?(Proc) | ||
|
||
@inherit_parent_service = inherit_parent_service | ||
|
||
# Start the span with start time, if given. | ||
start(start_time) if start_time | ||
end | ||
|
@@ -428,7 +431,8 @@ def message | |
# it has been finished. | ||
attr_reader \ | ||
:events, | ||
:span | ||
:span, | ||
:inherit_parent_service | ||
|
||
# Stored only for `service_entry` calculation. | ||
# Use `parent_id` for the effective parent span id. | ||
|
@@ -439,6 +443,11 @@ def message | |
# mutation by reference; when this span is returned, | ||
# we don't want this SpanOperation to modify it further. | ||
def build_span | ||
# Use parent service if no service is set and @inherit_parent_service is set | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am generally supportive for moving toward this direction. What I found a larger problem is the fact that Things get tricky when parent span changes its service after child spans are finished. For instance: Datadog::Tracing.trace('parent', service: 'service-parent') do |span_op, _|
Datadog::Tracing.trace('child1') {}
span_op.service = "BalaBoom!" # Change the service name after the child span is finished
end I was not sure what the behaviour is like for instrumentation depending on Any thoughts about restricting the mutability of the service field? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with Tony; mutability is a problem. Generally speaking, I think moving towards an immutable world simplifies things quite a bit, the only question is how, and what kinds of trade-offs. Have to think about this more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Secondary question: how does this feature fit in with the "one service name" change we originally planned for 2.0? If we end up introducing that, is this obsolete? |
||
service = self.service || (@parent&.service if @inherit_parent_service) | ||
|
||
service_entry = @parent.nil? || (service && @parent.service != service) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is I know my original intention was to eliminate |
||
|
||
Span.new( | ||
@name, | ||
duration: duration, | ||
|
@@ -448,13 +457,13 @@ def build_span | |
metrics: Core::Utils::SafeDup.frozen_or_dup(metrics), | ||
parent_id: @parent_id, | ||
resource: @resource, | ||
service: @service, | ||
service: service, | ||
start_time: @start_time, | ||
status: @status, | ||
type: @type, | ||
trace_id: @trace_id, | ||
links: @links, | ||
service_entry: parent.nil? || (service && parent.service != service) | ||
service_entry: service_entry | ||
) | ||
end | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -58,7 +58,8 @@ def initialize( | |||||||
), | ||||||||
span_sampler: Sampling::Span::Sampler.new, | ||||||||
tags: {}, | ||||||||
writer: Writer.new | ||||||||
writer: Writer.new, | ||||||||
inherit_parent_service: false | ||||||||
) | ||||||||
@trace_flush = trace_flush | ||||||||
@default_service = default_service | ||||||||
|
@@ -68,6 +69,7 @@ def initialize( | |||||||
@span_sampler = span_sampler | ||||||||
@tags = tags | ||||||||
@writer = writer | ||||||||
@inherit_parent_service = inherit_parent_service | ||||||||
end | ||||||||
|
||||||||
# Return a {Datadog::Tracing::SpanOperation span_op} and {Datadog::Tracing::TraceOperation trace_op} | ||||||||
|
@@ -327,12 +329,16 @@ def build_trace(digest = nil) | |||||||
trace_state: digest.trace_state, | ||||||||
trace_state_unknown_fields: digest.trace_state_unknown_fields, | ||||||||
remote_parent: digest.span_remote, | ||||||||
default_service: @default_service, | ||||||||
inherit_parent_service: @inherit_parent_service, | ||||||||
) | ||||||||
else | ||||||||
TraceOperation.new( | ||||||||
hostname: hostname, | ||||||||
profiling_enabled: profiling_enabled, | ||||||||
remote_parent: false, | ||||||||
default_service: @default_service, | ||||||||
inherit_parent_service: @inherit_parent_service, | ||||||||
) | ||||||||
end | ||||||||
end | ||||||||
|
@@ -341,12 +347,13 @@ def bind_trace_events!(trace_op) | |||||||
events = trace_op.send(:events) | ||||||||
|
||||||||
events.span_before_start.subscribe do |event_span_op, event_trace_op| | ||||||||
event_trace_op.service ||= @default_service | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. A small improvement here: we used to always set dd-trace-rb/lib/datadog/tracing/trace_operation.rb Lines 171 to 173 in b3c5a3d
This PR no longer explicitly sets the service field in the active |
||||||||
event_span_op.service ||= @default_service | ||||||||
sample_trace(event_trace_op) if event_span_op && event_span_op.parent_id == 0 | ||||||||
end | ||||||||
|
||||||||
events.span_finished.subscribe do |event_span, event_trace_op| | ||||||||
# Fallback in case the service was never set | ||||||||
event_span.service ||= @default_service | ||||||||
Comment on lines
-345
to
+355
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved the fallback |
||||||||
|
||||||||
sample_span(event_trace_op, event_span) | ||||||||
flush_trace(event_trace_op) | ||||||||
end | ||||||||
|
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.
Should we be more explicit about this option is not ready for production yet?
And it might leads to breaking changes for user existing graph with various instrumentations