Skip to content

Commit 7f5ddb6

Browse files
committed
Add traces to framer.
1 parent fb31045 commit 7f5ddb6

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

.github/workflows/test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ permissions:
77

88
env:
99
CONSOLE_OUTPUT: XTerm
10+
TRACES_BACKEND: traces/backend/test
1011

1112
jobs:
1213
test:

lib/protocol/http2/framer.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
require_relative "window_update_frame"
1717
require_relative "continuation_frame"
1818

19+
require "traces/provider"
20+
1921
module Protocol
2022
module HTTP2
2123
# HTTP/2 frame type mapping as defined by the spec
@@ -107,6 +109,50 @@ def read_header
107109

108110
raise EOFError, "Could not read frame header!"
109111
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
110156
end
111157
end
112158
end

protocol-http2.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ Gem::Specification.new do |spec|
2626

2727
spec.add_dependency "protocol-hpack", "~> 1.4"
2828
spec.add_dependency "protocol-http", "~> 0.18"
29+
spec.add_dependency "traces"
2930
end

0 commit comments

Comments
 (0)