Class: Datadog::ThreadLocalContext

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeThreadLocalContext

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

#localObject

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