8000 Don't trace `async.task` unless there is an active trace. · socketry/async@5e5f2ab · GitHub
[go: up one dir, main page]

Skip to content

Commit 5e5f2ab

Browse files
committed
Don't trace async.task unless there is an active trace.
- Prevent a ton of trace garbage / incorrect/irrelevant parenting.
1 parent ba6032f commit 5e5f2ab

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

async.gemspec

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,7 @@ Gem::Specification.new do |spec|
2727

2828
spec.add_dependency "console", "~> 1.29"
2929
spec.add_dependency "fiber-annotation"
30-
spec.add_dependency "io-event", ["~> 1.6", ">= 1.6.5"]
30+
spec.add_dependency "io-event", "~> 1.7"
31+
spec.add_dependency "traces", "~> 0.15"
32+
spec.add_dependency "metrics", "~> 0.12"
3133
end

gems.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@
2525
gem "decode"
2626
gem "rubocop"
2727

28-
gem "traces"
29-
gem "metrics"
30-
3128
gem "sus-fixtures-async"
3229
gem "sus-fixtures-console"
3330
gem "sus-fixtures-time"

lib/traces/provider/async/task.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88

99
Traces::Provider(Async::Task) do
1010
def schedule(&block)
11+
# If we are not actively tracing anything, then we can skip this:
12+
unless Traces.active?
13+
return super(&block)
14+
end
15+
1116
unless self.transient?
1217
trace_context = Traces.trace_context
1318
end
@@ -18,6 +23,7 @@ def schedule(&block)
1823
"transient" => self.transient?,
1924
}
2025

26+
# Run the trace in the context of the child task:
2127
super do
2228
Traces.trace_context = trace_context
2329

@@ -26,6 +32,7 @@ def schedule(&block)
2632
end
2733

2834
Traces.trace("async.task", attributes: attributes) do
35+
# Yes, this is correct, we already called super above:
2936
yield
3037
end
3138
end

0 commit comments

Comments
 (0)
0