Class: Datadog::ThreadLocalContext
- Inherits:
-
Object
- Object
- Datadog::ThreadLocalContext
- Defined in:
- lib/ddtrace/context.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.
270 271 272 |
# File 'lib/ddtrace/context.rb', line 270 def initialize self.local = Datadog::Context.new end |
Instance Method Details
#local ⇒ Object
Return the thread-local context.
280 281 282 |
# File 'lib/ddtrace/context.rb', line 280 def local Thread.current[:datadog_context] ||= Datadog::Context.new end |
#local=(ctx) ⇒ Object
Override the thread-local context with a new context.
275 276 277 |
# File 'lib/ddtrace/context.rb', line 275 def local=(ctx) Thread.current[:datadog_context] = ctx end |