Module: OpenTelemetry::Baggage
- Extended by:
- Baggage
- Included in:
- Baggage
- Defined in:
- lib/opentelemetry/baggage.rb,
lib/opentelemetry/baggage/entry.rb,
lib/opentelemetry/baggage/builder.rb,
lib/opentelemetry/baggage/propagation.rb,
lib/opentelemetry/baggage/propagation/context_keys.rb,
lib/opentelemetry/baggage/propagation/text_map_propagator.rb
Overview
OpenTelemetry Baggage Implementation
Defined Under Namespace
Modules: Propagation Classes: Builder, Entry
Instance Method Summary collapse
-
#build(context: Context.current) {|builder| ... } ⇒ Context
Used to chain modifications to baggage.
-
#clear(context: Context.current) ⇒ Context
Returns a new context with empty baggage.
- #raw_entries(context: Context.current) ⇒ Object private
-
#remove_value(key, context: Context.current) ⇒ Context
Returns a new context with value at key removed.
-
#set_value(key, value, metadata: nil, context: Context.current) ⇒ Context
Returns a new context with new key-value pair.
-
#value(key, context: Context.current) ⇒ String
Returns the corresponding baggage.entry (or nil) for key.
-
#values(context: Context.current) ⇒ Hash
Returns the baggage.
Instance Method Details
#build(context: Context.current) {|builder| ... } ⇒ Context
Used to chain modifications to baggage. The result is a context with an updated baggage. If only a single modification is being made to baggage, use the other methods on Baggage
, if multiple modifications are being made, use this one.
30 31 32 33 34 |
# File 'lib/opentelemetry/baggage.rb', line 30 def build(context: Context.current) builder = Builder.new(baggage_for(context).dup) yield builder context.set_value(BAGGAGE_KEY, builder.entries) end |
#clear(context: Context.current) ⇒ Context
Returns a new context with empty baggage
41 42 43 |
# File 'lib/opentelemetry/baggage.rb', line 41 def clear(context: Context.current) context.set_value(BAGGAGE_KEY, EMPTY_BAGGAGE) end |
#raw_entries(context: Context.current) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
67 68 69 |
# File 'lib/opentelemetry/baggage.rb', line 67 def raw_entries(context: Context.current) baggage_for(context).dup.freeze end |
#remove_value(key, context: Context.current) ⇒ Context
Returns a new context with value at key removed
94 95 96 97 98 99 100 101 |
# File 'lib/opentelemetry/baggage.rb', line 94 def remove_value(key, context: Context.current) baggage = baggage_for(context) return context unless baggage.key?(key) new_baggage = baggage.dup new_baggage.delete(key) context.set_value(BAGGAGE_KEY, new_baggage) end |
#set_value(key, value, metadata: nil, context: Context.current) ⇒ Context
Returns a new context with new key-value pair
82 83 84 85 86 |
# File 'lib/opentelemetry/baggage.rb', line 82 def set_value(key, value, metadata: nil, context: Context.current) new_baggage = baggage_for(context).dup new_baggage[key] = Entry.new(value, ) context.set_value(BAGGAGE_KEY, new_baggage) end |