Class: OpenTelemetry::SDK::CorrelationContext::Manager

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

Overview

Manages correlation context

Instance Method Summary collapse

Instance Method Details

#build_context(context: Context.current) {|builder| ... } ⇒ Context

Used to chain modifications to correlation context. The result is a context with an updated correlation context. If only a single modification is being made to correlation context, 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 correlation context. Defaults to +Context.current+

Yields:

  • (builder)

Returns:

  • (Context)


25
26
27
28
29
# File 'lib/opentelemetry/sdk/correlation_context/manager.rb', line 25

def build_context(context: Context.current)
  builder = Builder.new(correlations_for(context).dup)
  yield builder
  context.set_value(CORRELATION_CONTEXT_KEY, builder.entries)
end

#clear(context: Context.current) ⇒ Context

Returns a new context with empty correlations

Parameters:

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

    Context to clear correlations from. Defaults to +Context.current+

Returns:

  • (Context)


36
37
38
# File 'lib/opentelemetry/sdk/correlation_context/manager.rb', line 36

def clear(context: Context.current)
  context.set_value(CORRELATION_CONTEXT_KEY, EMPTY_CORRELATION_CONTEXT)
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 correlation from. Defaults to +Context.current+

Returns:

  • (Context)


70
71
72
73
74
75
76
77
# File 'lib/opentelemetry/sdk/correlation_context/manager.rb', line 70

def remove_value(key, context: Context.current)
  correlations = correlations_for(context)
  return context unless correlations.key?(key)

  new_correlations = correlations.dup
  new_correlations.delete(key)
  context.set_value(CORRELATION_CONTEXT_KEY, new_correlations)
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)


58
59
60
61
62
# File 'lib/opentelemetry/sdk/correlation_context/manager.rb', line 58

def set_value(key, value, context: Context.current)
  new_correlations = correlations_for(context).dup
  new_correlations[key] = value
  context.set_value(CORRELATION_CONTEXT_KEY, new_correlations)
end

#value(key, context: Context.current) ⇒ String

Returns the corresponding correlation 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/correlation_context/manager.rb', line 47

def value(key, context: Context.current)
  correlations_for(context)[key]
end