Class: OpenTelemetry::SDK::Baggage::Manager
- Inherits:
-
Object
- Object
- OpenTelemetry::SDK::Baggage::Manager
- Defined in:
- lib/opentelemetry/sdk/baggage/manager.rb
Overview
Manages baggage
Instance Method Summary collapse
-
#build_context(context: Context.current) {|builder| ... } ⇒ Context
Used to chain modifications to baggage.
-
#clear(context: Context.current) ⇒ Context
Returns a new context with empty baggage.
-
#remove_value(key, context: Context.current) ⇒ Context
Returns a new context with value at key removed.
-
#set_value(key, value, context: Context.current) ⇒ Context
Returns a new context with new key-value pair.
-
#value(key, context: Context.current) ⇒ String
Returns the corresponding baggage value (or nil) for key.
-
#values(context: Context.current) ⇒ Hash
Returns the baggage.
Instance Method Details
#build_context(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 Manager
, if multiple modifications are being made, use this one.
25 26 27 28 29 |
# File 'lib/opentelemetry/sdk/baggage/manager.rb', line 25 def build_context(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
36 37 38 |
# File 'lib/opentelemetry/sdk/baggage/manager.rb', line 36 def clear(context: Context.current) context.set_value(BAGGAGE_KEY, EMPTY_BAGGAGE) end |
#remove_value(key, context: Context.current) ⇒ Context
Returns a new context with value at key removed
80 81 82 83 84 85 86 87 |
# File 'lib/opentelemetry/sdk/baggage/manager.rb', line 80 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, context: Context.current) ⇒ Context
Returns a new context with new key-value pair
68 69 70 71 72 |
# File 'lib/opentelemetry/sdk/baggage/manager.rb', line 68 def set_value(key, value, context: Context.current) new_baggage = baggage_for(context).dup new_baggage[key] = value context.set_value(BAGGAGE_KEY, new_baggage) end |
#value(key, context: Context.current) ⇒ String
Returns the corresponding baggage value (or nil) for key
47 48 49 |
# File 'lib/opentelemetry/sdk/baggage/manager.rb', line 47 def value(key, context: Context.current) baggage_for(context)[key] end |
#values(context: Context.current) ⇒ Hash
Returns the baggage
57 58 59 |
# File 'lib/opentelemetry/sdk/baggage/manager.rb', line 57 def values(context: Context.current) baggage_for(context).dup.freeze end |