File: framer.rb

package info (click to toggle)
ruby-protocol-http2 0.24.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 484 kB
  • sloc: ruby: 3,671; makefile: 4
file content (62 lines) | stat: -rw-r--r-- 1,370 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# frozen_string_literal: true

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

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

Traces::Provider(Protocol::HTTP2::Framer) do
	def write_connection_preface
		return super unless Traces.active?
		
		Traces.trace("protocol.http2.framer.write_connection_preface") do
			super
		end
	end
	
	def read_connection_preface
		return super unless Traces.active?
		
		Traces.trace("protocol.http2.framer.read_connection_preface") do
			super
		end
	end
	
	def write_frame(frame)
		return super unless Traces.active?
		
		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(...)
		return super unless Traces.active?
		
		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
		return super unless Traces.active?
		
		Traces.trace("protocol.http2.framer.flush") do
			super
		end
	end
end