Skip to content

Commit

Permalink
Don't trace async.task unless there is an active trace.
Browse files Browse the repository at this point in the history
- Prevent a ton of trace garbage / incorrect/irrelevant parenting.
  • Loading branch information
ioquatix committed Jan 31, 2025
1 parent ba6032f commit 5e5f2ab
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion async.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,7 @@ Gem::Specification.new do |spec|

spec.add_dependency "console", "~> 1.29"
spec.add_dependency "fiber-annotation"
spec.add_dependency "io-event", ["~> 1.6", ">= 1.6.5"]
spec.add_dependency "io-event", "~> 1.7"
spec.add_dependency "traces", "~> 0.15"
spec.add_dependency "metrics", "~> 0.12"
end
3 changes: 0 additions & 3 deletions gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
gem "decode"
gem "rubocop"

gem "traces"
gem "metrics"

gem "sus-fixtures-async"
gem "sus-fixtures-console"
gem "sus-fixtures-time"
Expand Down
7 changes: 7 additions & 0 deletions lib/traces/provider/async/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

Traces::Provider(Async::Task) do
def schedule(&block)
# If we are not actively tracing anything, then we can skip this:
unless Traces.active?
return super(&block)
end

unless self.transient?
trace_context = Traces.trace_context
end
Expand All @@ -18,6 +23,7 @@ def schedule(&block)
"transient" => self.transient?,
}

# Run the trace in the context of the child task:
super do
Traces.trace_context = trace_context

Expand All @@ -26,6 +32,7 @@ def schedule(&block)
end

Traces.trace("async.task", attributes: attributes) do
# Yes, this is correct, we already called super above:
yield
end
end
Expand Down

0 comments on commit 5e5f2ab

Please sign in to comment.