Class: Datadog::ThreadLocalContext
- Inherits:
-
Object
- Object
- Datadog::ThreadLocalContext
- Defined in:
- lib/ddtrace/context_provider.rb
Overview
ThreadLocalContext can be used as a tracer global reference to create a different Context for each thread. In synchronous tracer, this is required to prevent multiple threads sharing the same Context in different executions.
Instance Method Summary collapse
-
#initialize ⇒ ThreadLocalContext
constructor
ThreadLocalContext can be used as a tracer global reference to create a different Context for each thread.
-
#local ⇒ Object
Return the thread-local context.
-
#local=(ctx) ⇒ Object
Override the thread-local context with a new context.
Constructor Details
#initialize ⇒ ThreadLocalContext
ThreadLocalContext can be used as a tracer global reference to create a different Context for each thread. In synchronous tracer, this is required to prevent multiple threads sharing the same Context in different executions.
To support multiple tracers simultaneously, each ThreadLocalContext instance has its own thread-local variable.
34 35 36 37 38 |
# File 'lib/ddtrace/context_provider.rb', line 34 def initialize @key = "datadog_context_#{object_id}".to_sym self.local = Datadog::Context.new end |
Instance Method Details
#local ⇒ Object
Return the thread-local context.
46 47 48 |
# File 'lib/ddtrace/context_provider.rb', line 46 def local Thread.current[@key] ||= Datadog::Context.new end |
#local=(ctx) ⇒ Object
Override the thread-local context with a new context.
41 42 43 |
# File 'lib/ddtrace/context_provider.rb', line 41 def local=(ctx) Thread.current[@key] = ctx end |