Class: OpenTelemetry::SDK::Baggage::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/opentelemetry/sdk/baggage/manager.rb

Overview

Manages baggage

Instance Method Summary collapse

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.

Parameters:

  • context (optional Context) (defaults to: Context.current)

    The context to update with with new modified baggage. Defaults to Context.current

Yields:

  • (builder)

Returns:

  • (Context)


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

Parameters:

  • context (optional Context) (defaults to: Context.current)

    Context to clear baggage from. Defaults to Context.current

Returns:

  • (Context)


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

Parameters:

  • key (String)

    The key to remove

  • context (optional Context) (defaults to: Context.current)

    The context to remove baggage from. Defaults to Context.current

Returns:

  • (Context)


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

Parameters:

  • key (String)

    The key to store this value under

  • value (String)

    String value to be stored under key

  • context (optional Context) (defaults to: Context.current)

    The context to update with new value. Defaults to Context.current

Returns:

  • (Context)


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

Parameters:

  • key (String)

    The lookup key

  • context (optional Context) (defaults to: Context.current)

    The context from which to retrieve the key. Defaults to Context.current

Returns:

  • (String)


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

Parameters:

  • context (optional Context) (defaults to: Context.current)

    The context from which to retrieve the baggage. Defaults to Context.current

Returns:

  • (Hash)


57
58
59
# File 'lib/opentelemetry/sdk/baggage/manager.rb', line 57

def values(context: Context.current)
  baggage_for(context).dup.freeze
end