Skip to content

Commit

Permalink
Restore 100% coverage and expose trace provider.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Nov 9, 2024
1 parent 41dda40 commit 4c9fadb
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 46 deletions.
14 changes: 14 additions & 0 deletions config/sus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,17 @@

require "covered/sus"
include Covered::Sus

ENV["TRACES_BACKEND"] ||= "traces/backend/test"
ENV["METRICS_BACKEND"] ||= "metrics/backend/test"

def prepare_instrumentation!
require "traces"
require "metrics"
end

def before_tests(...)
prepare_instrumentation!

super
end
8 changes: 8 additions & 0 deletions config/traces.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2024, by Samuel Williams.

def prepare
require "traces/provider/protocol/http2"
end
3 changes: 3 additions & 0 deletions gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
gem "decode"
gem "rubocop"

gem "traces"
gem "metrics"

gem "bake-test"
gem "bake-test-external"
end
46 changes: 0 additions & 46 deletions lib/protocol/http2/framer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
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 @@ -109,50 +107,6 @@ 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
6 changes: 6 additions & 0 deletions lib/traces/provider/protocol/http2.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2024, by Samuel Williams.

require_relative "http2/framer"
52 changes: 52 additions & 0 deletions lib/traces/provider/protocol/http2/framer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2024, by Samuel Williams.

require "traces/provider"
require_relative "../../../../protocol/http2/framer"

Traces::Provider(Protocol::HTTP2::Framer) 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.class" => frame.class.name,
"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(...)
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

0 comments on commit 4c9fadb

Please sign in to comment.