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.



131
132
133
# File 'lib/ddtrace/context.rb', line 131

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

Instance Method Details

#localObject

Return the thread-local context.



141
142
143
# File 'lib/ddtrace/context.rb', line 141

def local
  Thread.current[:datadog_context] ||= Datadog::Context.new
end

#local=(ctx) ⇒ Object

Override the thread-local context with a new context.



136
137
138
# File 'lib/ddtrace/context.rb', line 136

def local=(ctx)
  Thread.current[:datadog_context] = ctx
end