Skip to content

Commit 585b40d

Browse files
committed
Move all client and server tracing into provider files.
1 parent aa6720c commit 585b40d

File tree

11 files changed

+130
-121
lines changed

11 files changed

+130
-121
lines changed

config/traces.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def prepare
2+
require "traces/provider/async/http"
3+
require "traces/provider/async/http/protocol/http1/client"
4+
require "traces/provider/async/http/protocol/http2/client"
5+
end

lib/async/http/client.rb

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
require "protocol/http/body/completable"
1212
require "protocol/http/methods"
1313

14-
require "traces/provider"
15-
1614
require_relative "protocol"
1715

1816
module Async
@@ -168,56 +166,6 @@ def make_pool(**options)
168166
@protocol.client(@endpoint.connect)
169167
end
170168
end
171-
172-
Traces::Provider(self) do
173-
def call(request)
174-
attributes = {
175-
'http.method': request.method,
176-
'http.authority': request.authority || self.authority,
177-
'http.scheme': request.scheme || self.scheme,
178-
'http.path': request.path,
179-
}
180-
181-
if protocol = request.protocol
182-
attributes["http.protocol"] = protocol
183-
end
184-
185-
if length = request.body&.length
186-
attributes["http.request.length"] = length
187-
end
188-
189-
Traces.trace("async.http.client.call", attributes: attributes) do |span|
190-
if context = Traces.trace_context
191-
request.headers["traceparent"] = context.to_s
192-
# request.headers['tracestate'] = context.state
193-
end
194-
195-
super.tap do |response|
196-
if version = response&.version
197-
span["http.version"] = version
198-
end
199-
200-
if status = response&.status
201-
span["http.status_code"] = status
202-
end
203-
204-
if length = response.body&.length
205-
span["http.response.length"] = length
206-
end
207-
end
208-
end
209-
end
210-
211-
def make_response(request, connection, attempt)
212-
attributes = {
213-
attempt: attempt,
214-
}
215-
216-
Traces.trace("async.http.client.make_response", attributes: attributes) do
217-
super
218-
end
219-
end
220-
end
221169
end
222170
end
223171
end

lib/async/http/protocol/http1/client.rb

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
require_relative "connection"
77

8-
require "traces/provider"
9-
108
module Async
119
module HTTP
1210
module Protocol
@@ -88,20 +86,6 @@ def call(request, task: Task.current)
8886
self.close(error)
8987
raise
9088
end
91-
92-
Traces::Provider(self) do
93-
def write_request(...)
94-
Traces.trace("async.http.protocol.http1.client.write_request") do
95-
super
96-
end
97-
end
98-
99-
def read_response(...)
100-
Traces.trace("async.http.protocol.http1.client.read_response") do
101-
super
102-
end
103-
end
104-
end
10589
end
10690
end
10791
end

lib/async/http/protocol/http2/client.rb

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
require_relative "connection"
77
require_relative "response"
88

9-
require "traces/provider"
109
require "protocol/http2/client"
1110

1211
module Async
@@ -46,20 +45,6 @@ def write_request(response, request)
4645
def read_response(response)
4746
response.wait
4847
end
49-
50-
Traces::Provider(self) do
51-
def write_request(...)
52-
Traces.trace("async.http.protocol.http2.client.write_request") do
53-
super
54-
end
55-
end
56-
57-
def read_response(...)
58-
Traces.trace("async.http.protocol.http2.client.read_response") do
59-
super
60-
end
61-
end
62-
end
6348
end
6449
end
6550
end

lib/async/http/server.rb

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
require "async"
88
require "io/endpoint"
99
require "protocol/http/middleware"
10-
require "traces/provider"
1110

1211
require_relative "protocol"
1312

@@ -70,43 +69,6 @@ def run
7069
task.children.each(&:wait)
7170
end
7271
end
73-
74-
Traces::Provider(self) do
75-
def call(request)
76-
if trace_parent = request.headers["traceparent"]
77-
Traces.trace_context = Traces::Context.parse(trace_parent.join, request.headers["tracestate"], remote: true)
78-
end
79-
80-
attributes = {
81-
'http.version': request.version,
82-
'http.method': request.method,
83-
'http.authority': request.authority,
84-
'http.scheme': request.scheme,
85-
'http.path': request.path,
86-
'http.user_agent': request.headers["user-agent"],
87-
}
88-
89-
if length = request.body&.length
90-
attributes["http.request.length"] = length
91-
end
92-
93-
if protocol = request.protocol
94-
attributes["http.protocol"] = protocol
95-
end
96-
97-
Traces.trace("async.http.server.call", attributes: attributes) do |span|
98-
super.tap do |response|
99-
if status = response&.status
100-
span["http.status_code"] = status
101-
end
102-
103-
if length = response&.body&.length
104-
span["http.response.length"] = length
105-
end
106-
end
107-
end
108-
end
109-
end
11072
end
11173
end
11274
end

lib/traces/provider/async/http.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require_relative "http/client"
2+
require_relative "http/server"
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
require_relative "../../../../async/http/client"
2+
3+
Traces::Provider(Async::HTTP::Client) do
4+
def call(request)
5+
attributes = {
6+
'http.method': request.method,
7+
'http.authority': request.authority || self.authority,
8+
'http.scheme': request.scheme || self.scheme,
9+
'http.path': request.path,
10+
}
11+
12+
if protocol = request.protocol
13+
attributes["http.protocol"] = protocol
14+
end
15+
16+
if length = request.body&.length
17+
attributes["http.request.length"] = length
18+
end
19+
20+
Traces.trace("async.http.client.call", attributes: attributes) do |span|
21+
if context = Traces.trace_context
22+
request.headers["traceparent"] = context.to_s
23+
# request.headers['tracestate'] = context.state
24+
end
25+
26+
super.tap do |response|
27+
if version = response&.version
28+
span["http.version"] = version
29+
end
30+
31+
if status = response&.status
32+
span["http.status_code"] = status
33+
end
34+
35+
if length = response.body&.length
36+
span["http.response.length"] = length
37+
end
38+
end
39+
end
40+
end
41+
42+
def make_response(request, connection, attempt)
43+
attributes = {
44+
attempt: attempt,
45+
}
46+
47+
Traces.trace("async.http.client.make_response", attributes: attributes) do
48+
super
49+
end
50+
end
51+
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require_relative "../../../../../../async/http/protocol/http1/client"
2+
3+
Traces::Provider(Async::HTTP::Protocol::HTTP1::Client) do
4+
def write_request(...)
5+
Traces.trace("async.http.protocol.http1.client.write_request") do
6+
super
7+
end
8+
end
9+
10+
def read_response(...)
11+
Traces.trace("async.http.protocol.http1.client.read_response") do
12+
super
13+
end
14+
end
15+
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require_relative "../../../../../../async/http/protocol/http2/client"
2+
3+
Traces::Provider(Async::HTTP::Protocol::HTTP2::Client) do
4+
def write_request(...)
5+
Traces.trace("async.http.protocol.http2.client.write_request") do
6+
super
7+
end
8+
end
9+
10+
def read_response(...)
11+
Traces.trace("async.http.protocol.http2.client.read_response") do
12+
super
13+
end
14+
end
15+
end
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
require_relative "../../../../async/http/server"
2+
3+
Traces::Provider(Async::HTTP::Server) do
4+
def call(request)
5+
if trace_parent = request.headers["traceparent"]
6+
Traces.trace_context = Traces::Context.parse(trace_parent.join, request.headers["tracestate"], remote: true)
7+
end
8+
9+
attributes = {
10+
'http.version': request.version,
11+
'http.method': request.method,
12+
'http.authority': request.authority,
13+
'http.scheme': request.scheme,
14+
'http.path': request.path,
15+
'http.user_agent': request.headers["user-agent"],
16+
}
17+
18+
if length = request.body&.length
19+
attributes["http.request.length"] = length
20+
end
21+
22+
if protocol = request.protocol
23+
attributes["http.protocol"] = protocol
24+
end
25+
26+
Traces.trace("async.http.server.call", attributes: attributes) do |span|
27+
super.tap do |response|
28+
if status = response&.status
29+
span["http.status_code"] = status
30+
end
31+
32+
if length = response&.body&.length
33+
span["http.response.length"] = length
34+
end
35+
end
36+
end
37+
end
38+
end

0 commit comments

Comments
 (0)