Class: Sentry::Baggage
- Inherits:
-
Object
- Object
- Sentry::Baggage
- Defined in:
- lib/sentry/baggage.rb
Overview
A W3C Baggage Header implementation.
Constant Summary collapse
- SENTRY_PREFIX =
"sentry-"
- SENTRY_PREFIX_REGEX =
/^sentry-/
Instance Attribute Summary collapse
- #items ⇒ Hash readonly
- #mutable ⇒ Boolean readonly
Class Method Summary collapse
-
.from_incoming_header(header) ⇒ Baggage?
Creates a Baggage object from an incoming W3C Baggage header string.
Instance Method Summary collapse
-
#dynamic_sampling_context ⇒ Hash
A Dynamic Sampling Context hash to be used in the trace envelope header.
-
#freeze! ⇒ void
Make the Baggage immutable.
-
#initialize(items, mutable: true) ⇒ Baggage
constructor
A new instance of Baggage.
-
#serialize ⇒ String
Serialize the Baggage object back to a string.
Constructor Details
#initialize(items, mutable: true) ⇒ Baggage
Returns a new instance of Baggage.
17 18 19 20 |
# File 'lib/sentry/baggage.rb', line 17 def initialize(items, mutable: true) @items = items @mutable = mutable end |
Instance Attribute Details
#items ⇒ Hash (readonly)
12 13 14 |
# File 'lib/sentry/baggage.rb', line 12 def items @items end |
#mutable ⇒ Boolean (readonly)
15 16 17 |
# File 'lib/sentry/baggage.rb', line 15 def mutable @mutable end |
Class Method Details
.from_incoming_header(header) ⇒ Baggage?
Creates a Baggage object from an incoming W3C Baggage header string.
Sentry items are identified with the ‘sentry-’ prefix and stored in a hash. The presence of a Sentry item makes the baggage object immutable.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/sentry/baggage.rb', line 29 def self.from_incoming_header(header) items = {} mutable = true header.split(",").each do |item| item = item.strip key, val = item.split("=") next unless key && val next unless key =~ SENTRY_PREFIX_REGEX baggage_key = key.split("-")[1] next unless baggage_key items[CGI.unescape(baggage_key)] = CGI.unescape(val) mutable = false end new(items, mutable: mutable) end |
Instance Method Details
#dynamic_sampling_context ⇒ Hash
A Dynamic Sampling Context hash to be used in the trace envelope header.
59 60 61 |
# File 'lib/sentry/baggage.rb', line 59 def dynamic_sampling_context @items end |
#freeze! ⇒ void
This method returns an undefined value.
Make the Baggage immutable.
52 53 54 |
# File 'lib/sentry/baggage.rb', line 52 def freeze! @mutable = false end |
#serialize ⇒ String
Serialize the Baggage object back to a string.
65 66 67 68 |
# File 'lib/sentry/baggage.rb', line 65 def serialize items = @items.map { |k, v| "#{SENTRY_PREFIX}#{CGI.escape(k)}=#{CGI.escape(v)}" } items.join(",") end |