-
Notifications
You must be signed in to change notification settings - Fork 394
Tracing.continue_from! with a block maintains active trace until the block ends #4941
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
base: master
Are you sure you want to change the base?
Conversation
Thank you for updating Change log entry section 👏 Visited at: 2025-10-04 02:07:44 UTC |
91fa0bb
to
eb4376a
Compare
BenchmarksBenchmark execution time: 2025-10-04 01:56:31 Comparing candidate commit eb4376a in PR branch Found 0 performance improvements and 1 performance regressions! Performance is the same for 43 metrics, 2 unstable metrics. scenario:tracing - Tracing.log_correlation
|
✅ Tests 🎉 All green!❄️ No new flaky tests detected 🎯 Code Coverage 🔗 Commit SHA: eb4376a | Docs | Was this helpful? Give us feedback! |
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.
Nothing for docs to review
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 this branch is missing #4925, if so it should have master merged into it and formatters rerun.
@events = events || Events.new | ||
@finished = false | ||
@spans = [] | ||
@auto_finish = auto_finish |
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.
@auto_finish = auto_finish | |
@auto_finish = !!auto_finish |
start_trace(continue_from: continue_from) | ||
else | ||
active_trace | ||
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.
Was this rubocop autocorrected? If yes this branch needs master merged into it I think.
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.
LGTM 👍🏼
P.S I've left few non-blocking suggestions
if block | ||
# When a block is given, the trace will be active until the block finishes. | ||
context.activate!(trace) do | ||
yield | ||
ensure # We have to flush even when an error occurs | ||
# On block completion, force the trace to finish and flush its finished spans. | ||
# Unfinished spans are lost as the {TraceOperation} has ended. | ||
trace.finish! | ||
flush_trace(trace) | ||
end | ||
else | ||
# Otherwise, the trace will be bound to the current thread after this point | ||
context.activate!(trace) | ||
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.
This could be streamlined with a guard-clause
if block | |
# When a block is given, the trace will be active until the block finishes. | |
context.activate!(trace) do | |
yield | |
ensure # We have to flush even when an error occurs | |
# On block completion, force the trace to finish and flush its finished spans. | |
# Unfinished spans are lost as the {TraceOperation} has ended. | |
trace.finish! | |
flush_trace(trace) | |
end | |
else | |
# Otherwise, the trace will be bound to the current thread after this point | |
context.activate!(trace) | |
end | |
# The trace will be bound to the current thread if no block is given | |
return context.activate!(trace) unless block | |
# When a block is given, the trace will be active until the block finishes. | |
context.activate!(trace) do | |
yield | |
ensure # We have to flush even when an error occurs | |
# On block completion, force the trace to finish and flush its finished spans. | |
# Unfinished spans are lost as the {TraceOperation} has ended. | |
trace.finish! | |
flush_trace(trace) | |
end |
# Don't finish the span, so finished_span_count remains 0 | ||
end | ||
|
||
# No spans should be flushed |
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 comment is unnecessary
# No spans should be flushed |
What does this PR do?
Fixes an unintended behavior of
Datadog::Tracing.continue_from!(digest, &block)
where if multiple local root spans are created inside a theblock
, only the first one is associated with thedigest
. Any subsequence spans inside that block are associated with a new, unrelated trace.Effectively, this PR makes this block do what it looks like it does:
Before this PR, only the
first.span
would be associated with thedigest
.Motivation:
While trying to address #3465, I wasn't able to get all background spans to be associated with the active span in the main calling thread. This was due to the bug that this PR fixes.
Change log entry
Yes.
Tracing.continue_from!
with a block maintains active trace until the block ends.