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.
241 242 243 |
# File 'lib/ddtrace/context.rb', line 241 def initialize self.local = Datadog::Context.new end |
Instance Method Details
#local ⇒ Object
Return the thread-local context.
251 252 253 |
# File 'lib/ddtrace/context.rb', line 251 def local Thread.current[:datadog_context] ||= Datadog::Context.new end |
#local=(ctx) ⇒ Object
Override the thread-local context with a new context.
246 247 248 |
# File 'lib/ddtrace/context.rb', line 246 def local=(ctx) Thread.current[:datadog_context] = ctx end |