Class: Datadog::Tracing::FiberLocalContext
- Inherits:
-
Object
- Object
- Datadog::Tracing::FiberLocalContext
- Defined in:
- lib/datadog/tracing/context_provider.rb
Overview
FiberLocalContext can be used as a tracer global reference to create a different Context for each fiber. This allows for the tracer to create a serial execution graph regardless of any concurrent execution: each concurrent execution path creates a new trace graph.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ FiberLocalContext
constructor
To support multiple tracers simultaneously, each FiberLocalContext instance has its own fiber-local variable.
-
#local(storage = Thread.current) ⇒ Object
Return the fiber-local context.
-
#local=(ctx) ⇒ Object
Override the fiber-local context with a new context.
Constructor Details
#initialize ⇒ FiberLocalContext
To support multiple tracers simultaneously, each Datadog::Tracing::FiberLocalContext instance has its own fiber-local variable.
49 50 51 52 53 |
# File 'lib/datadog/tracing/context_provider.rb', line 49 def initialize @key = "datadog_context_#{FiberLocalContext.next_instance_id}".to_sym self.local = Context.new end |
Class Method Details
.next_instance_id ⇒ Object
75 76 77 |
# File 'lib/datadog/tracing/context_provider.rb', line 75 def self.next_instance_id UNIQUE_INSTANCE_MUTEX.synchronize { UNIQUE_INSTANCE_GENERATOR.next } end |
Instance Method Details
#local(storage = Thread.current) ⇒ Object
Return the fiber-local context.
61 62 63 |
# File 'lib/datadog/tracing/context_provider.rb', line 61 def local(storage = Thread.current) storage[@key] ||= Context.new end |
#local=(ctx) ⇒ Object
Override the fiber-local context with a new context.
56 57 58 |
# File 'lib/datadog/tracing/context_provider.rb', line 56 def local=(ctx) Thread.current[@key] = ctx end |