Class: OpenTelemetry::SDK::CorrelationContext::Manager
- Inherits:
-
Object
- Object
- OpenTelemetry::SDK::CorrelationContext::Manager
- Defined in:
- lib/opentelemetry/sdk/correlation_context/manager.rb
Overview
Manages correlation context
Instance Method Summary collapse
-
#build_context(context: Context.current) {|builder| ... } ⇒ Context
Used to chain modifications to correlation context.
-
#clear(context: Context.current) ⇒ Context
Returns a new context with empty correlations.
-
#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 correlation value (or nil) for key.
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.
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
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
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
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
47 48 49 |
# File 'lib/opentelemetry/sdk/correlation_context/manager.rb', line 47 def value(key, context: Context.current) correlations_for(context)[key] end |