Class: Datadog::Tracing::FiberLocalContext

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/tracing/context_provider.rb

Overview

FiberLocalContext can be used as a tracer global reference to create a different Context for each fiber. This allows for the tracer to create a serial execution graph regardless of any concurrent execution: each concurrent execution path creates a new trace graph.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFiberLocalContext

To support multiple tracers simultaneously, each Datadog::Tracing::FiberLocalContext instance has its own fiber-local variable.



51
52
53
54
55
# File 'lib/datadog/tracing/context_provider.rb', line 51

def initialize
  @key = "datadog_context_#{FiberLocalContext.next_instance_id}".to_sym

  self.local = Context.new
end

Class Method Details

.next_instance_idObject



77
78
79
# File 'lib/datadog/tracing/context_provider.rb', line 77

def self.next_instance_id
  UNIQUE_INSTANCE_MUTEX.synchronize { UNIQUE_INSTANCE_GENERATOR.next }
end

Instance Method Details

#local(storage = Thread.current) ⇒ Object

Return the fiber-local context.



63
64
65
# File 'lib/datadog/tracing/context_provider.rb', line 63

def local(storage = Thread.current)
  storage[@key] ||= Context.new
end

#local=(ctx) ⇒ Object

Override the fiber-local context with a new context.



58
59
60
# File 'lib/datadog/tracing/context_provider.rb', line 58

def local=(ctx)
  Thread.current[@key] = ctx
end