Skip to content

Commit 4c9fadb

Browse files
committed
Restore 100% coverage and expose trace provider.
1 parent 41dda40 commit 4c9fadb

File tree

6 files changed

+83
-46
lines changed

6 files changed

+83
-46
lines changed

config/sus.rb

+14
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,17 @@
55

66
require "covered/sus"
77
include Covered::Sus
8+
9+
ENV["TRACES_BACKEND"] ||= "traces/backend/test"
10+
ENV["METRICS_BACKEND"] ||= "metrics/backend/test"
11+
12+
def prepare_instrumentation!
13+
require "traces"
14+
require "metrics"
15+
end
16+
17+
def before_tests(...)
18+
prepare_instrumentation!
19+
20+
super
21+
end

config/traces.rb

+8
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/protocol/http2"
8+
end

gems.rb

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
gem "decode"
2121
gem "rubocop"
2222

23+
gem "traces"
24+
gem "metrics"
25+
2326
gem "bake-test"
2427
gem "bake-test-external"
2528
end

lib/protocol/http2/framer.rb

-46
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
require_relative "window_update_frame"
1717
require_relative "continuation_frame"
1818

19-
require "traces/provider"
20-
2119
module Protocol
2220
module HTTP2
2321
# HTTP/2 frame type mapping as defined by the spec
@@ -109,50 +107,6 @@ def read_header
109107

110108
raise EOFError, "Could not read frame header!"
111109
end
112-
113-
Traces::Provider(self) do
114-
def write_connection_preface
115-
Traces.trace("protocol.http2.framer.write_connection_preface") do
116-
super
117-
end
118-
end
119-
120-
def read_connection_preface
121-
Traces.trace("protocol.http2.framer.read_connection_preface") do
122-
super
123-
end
124-
end
125-
126-
def write_frame(frame)
127-
attributes = {
128-
"frame.length" => frame.length,
129-
"frame.type" => frame.type,
130-
"frame.flags" => frame.flags,
131-
"frame.stream_id" => frame.stream_id,
132-
}
133-
134-
Traces.trace("protocol.http2.framer.write_frame", attributes: attributes) do
135-
super
136-
end
137-
end
138-
139-
def read_frame(maximum_frame_size = MAXIMUM_ALLOWED_FRAME_SIZE)
140-
Traces.trace("protocol.http2.framer.read_frame") do |span|
141-
super.tap do |frame|
142-
span["frame.length"] = frame.length
143-
span["frame.type"] = frame.type
144-
span["frame.flags"] = frame.flags
145-
span["frame.stream_id"] = frame.stream_id
146-
end
147-
end
148-
end
149-
150-
def flush
151-
Traces.trace("protocol.http2.framer.flush") do
152-
super
153-
end
154-
end
155-
end
156110
end
157111
end
158112
end

lib/traces/provider/protocol/http2.rb

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# frozen_string_literal: true
2+
3+
# Released under the MIT License.
4+
# Copyright, 2024, by Samuel Williams.
5+
6+
require_relative "http2/framer"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# frozen_string_literal: true
2+
3+
# Released under the MIT License.
4+
# Copyright, 2024, by Samuel Williams.
5+
6+
require "traces/provider"
7+
require_relative "../../../../protocol/http2/framer"
8+
9+
Traces::Provider(Protocol::HTTP2::Framer) do
10+
def write_connection_preface
11+
Traces.trace("protocol.http2.framer.write_connection_preface") do
12+
super
13+
end
14+
end
15+
16+
def read_connection_preface
17+
Traces.trace("protocol.http2.framer.read_connection_preface") do
18+
super
19+
end
20+
end
21+
22+
def write_frame(frame)
23+
attributes = {
24+
"frame.length" => frame.length,
25+
"frame.class" => frame.class.name,
26+
"frame.type" => frame.type,
27+
"frame.flags" => frame.flags,
28+
"frame.stream_id" => frame.stream_id,
29+
}
30+
31+
Traces.trace("protocol.http2.framer.write_frame", attributes: attributes) do
32+
super
33+
end
34+
end
35+
36+
def read_frame(...)
37+
Traces.trace("protocol.http2.framer.read_frame") do |span|
38+
super.tap do |frame|
39+
span["frame.length"] = frame.length
40+
span["frame.type"] = frame.type
41+
span["frame.flags"] = frame.flags
42+
span["frame.stream_id"] = frame.stream_id
43+
end
44+
end
45+
end
46+
47+
def flush
48+
Traces.trace("protocol.http2.framer.flush") do
49+
super
50+
end
51+
end
52+
end

0 commit comments

Comments
 (0)