Skip to content

Commit d54a680

Browse files
committed
Extract traces into separate file.
1 parent 538d46c commit d54a680

File tree

4 files changed

+77
-55
lines changed

4 files changed

+77
-55
lines changed

config/sus.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,13 @@
77
include Covered::Sus
88

99
ENV["TRACES_BACKEND"] ||= "traces/backend/test"
10+
11+
def prepare_instrumentation!
12+
require "traces"
13+
end
14+
15+
def before_tests(...)
16+
prepare_instrumentation!
17+
18+
super
19+
end

config/traces.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
# Released under the MIT License.
4+
# Copyright, 2024, by Samuel Williams.
5+
6+
def prepare
7+
require "traces/provider/async/pool/controller"
8+
end

lib/async/pool/controller.rb

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
require "async/notification"
1212
require "async/semaphore"
1313

14-
require "traces"
15-
1614
module Async
1715
module Pool
1816
# A resource pool controller.
@@ -381,59 +379,6 @@ def acquire_or_create_resource
381379
return create_resource
382380
end
383381
end
384-
385-
Traces::Provider(self) do
386-
def create_resource(...)
387-
attributes = {
388-
concurrency: @guard.limit,
389-
}
390-
391-
attributes.merge!(@tags) if @tags
392-
393-
Traces.trace('async.pool.create', attributes: attributes) {super}
394-
end
395-
396-
def drain(...)
397-
attributes = {
398-
size: @resources.size,
399-
}
400-
401-
attributes.merge!(@tags) if @tags
402-
403-
Traces.trace('async.pool.drain', attributes: attributes) {super}
404-
end
405-
406-
def acquire(...)
407-
attributes = {
408-
size: @resources.size,
409-
limit: @limit,
410-
}
411-
412-
attributes.merge!(@tags) if @tags
413-
414-
Traces.trace('async.pool.acquire', attributes: attributes) {super}
415-
end
416-
417-
def release(...)
418-
attributes = {
419-
size: @resources.size,
420-
}
421-
422-
attributes.merge!(@tags) if @tags
423-
424-
Traces.trace('async.pool.release', attributes: attributes) {super}
425-
end
426-
427-
def retire(...)
428-
attributes = {
429-
size: @resources.size,
430-
}
431-
432-
attributes.merge!(@tags) if @tags
433-
434-
Traces.trace('async.pool.retire', attributes: attributes) {super}
435-
end
436-
end
437382
end
438383
end
439384
end
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# frozen_string_literal: true
2+
3+
# Released under the MIT License.
4+
# Copyright, 2025, by Samuel Williams.
5+
6+
require_relative "../../../../async/pool/controller"
7+
8+
Traces::Provider(Async::Pool::Controller) do
9+
def create_resource(...)
10+
attributes = {
11+
concurrency: @guard.limit,
12+
}
13+
14+
attributes.merge!(@tags) if @tags
15+
16+
Traces.trace("async.pool.create", attributes: attributes) {super}
17+
end
18+
19+
def drain(...)
20+
attributes = {
21+
size: @resources.size,
22+
}
23+
24+
attributes.merge!(@tags) if @tags
25+
26+
Traces.trace("async.pool.drain", attributes: attributes) {super}
27+
end
28+
29+
def acquire(...)
30+
attributes = {
31+
size: @resources.size,
32+
limit: @limit,
33+
}
34+
35+
attributes.merge!(@tags) if @tags
36+
37+
Traces.trace("async.pool.acquire", attributes: attributes) {super}
38+
end
39+
40+
def release(...)
41+
attributes = {
42+
size: @resources.size,
43+
}
44+
45+
attributes.merge!(@tags) if @tags
46+
47+
Traces.trace("async.pool.release", attributes: attributes) {super}
48+
end
49+
50+
def retire(...)
51+
attributes = {
52+
size: @resources.size,
53+
}
54+
55+
attributes.merge!(@tags) if @tags
56+
57+
Traces.trace("async.pool.retire", attributes: attributes) {super}
58+
end
59+
end

0 commit comments

Comments
 (0)