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.



241
242
243
# File 'lib/ddtrace/context.rb', line 241

def initialize
  self.local = Datadog::Context.new
end

Instance Method Details

#localObject

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