Skip to content

Commit

Permalink
Add traces to framer.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Nov 3, 2024
1 parent fb31045 commit 7f5ddb6
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ permissions:

env:
CONSOLE_OUTPUT: XTerm
TRACES_BACKEND: traces/backend/test

jobs:
test:
Expand Down
46 changes: 46 additions & 0 deletions lib/protocol/http2/framer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
require_relative "window_update_frame"
require_relative "continuation_frame"

require "traces/provider"

module Protocol
module HTTP2
# HTTP/2 frame type mapping as defined by the spec
Expand Down Expand Up @@ -107,6 +109,50 @@ def read_header

raise EOFError, "Could not read frame header!"
end

Traces::Provider(self) do
def write_connection_preface
Traces.trace("protocol.http2.framer.write_connection_preface") do
super
end
end

def read_connection_preface
Traces.trace("protocol.http2.framer.read_connection_preface") do
super
end
end

def write_frame(frame)
attributes = {
"frame.length" => frame.length,
"frame.type" => frame.type,
"frame.flags" => frame.flags,
"frame.stream_id" => frame.stream_id,
}

Traces.trace("protocol.http2.framer.write_frame", attributes: attributes) do
super
end
end

def read_frame(maximum_frame_size = MAXIMUM_ALLOWED_FRAME_SIZE)
Traces.trace("protocol.http2.framer.read_frame") do |span|
super.tap do |frame|
span["frame.length"] = frame.length
span["frame.type"] = frame.type
span["frame.flags"] = frame.flags
span["frame.stream_id"] = frame.stream_id
end
end
end

def flush
Traces.trace("protocol.http2.framer.flush") do
super
end
end
end
end
end
end
1 change: 1 addition & 0 deletions protocol-http2.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ Gem::Specification.new do |spec|

spec.add_dependency "protocol-hpack", "~> 1.4"
spec.add_dependency "protocol-http", "~> 0.18"
spec.add_dependency "traces"
end

0 comments on commit 7f5ddb6

Please sign in to comment.