Class: Datadog::OpenTracer::ThreadLocalScopeManager

Inherits:
ScopeManager
  • Object
show all
Defined in:
lib/datadog/opentracer/thread_local_scope_manager.rb

Overview

OpenTracing adapter for thread local scope management

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ ThreadLocalScopeManager

Returns a new instance of ThreadLocalScopeManager.



8
9
10
11
# File 'lib/datadog/opentracer/thread_local_scope_manager.rb', line 8

def initialize(*args, &block)
  super(*args, &block)
  @thread_key = "dd_opentracer_context_#{ThreadLocalScopeManager.next_instance_id}".to_sym
end

Class Method Details

.next_instance_idObject



53
54
55
# File 'lib/datadog/opentracer/thread_local_scope_manager.rb', line 53

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

Instance Method Details

#activate(span, finish_on_close: true) ⇒ Scope

Make a span instance active.

Parameters:

  • span (Span)

    the Span that should become active

  • finish_on_close (Boolean) (defaults to: true)

    whether the Span should automatically be finished when Scope#close is called

Returns:

  • (Scope)

    instance to control the end of the active period for the Span. It is a programming error to neglect to call Scope#close on the returned instance.



23
24
25
26
27
28
29
30
31
# File 'lib/datadog/opentracer/thread_local_scope_manager.rb', line 23

def activate(span, finish_on_close: true)
  ThreadLocalScope.new(
    manager: self,
    span: span,
    finish_on_close: finish_on_close
  ).tap do |scope|
    set_scope(scope)
  end
end

#activeScope

currently active Span.

If there is a non-null Scope, its wrapped Span becomes an implicit parent (as Reference#CHILD_OF) of any newly-created Span at Tracer#start_active_span or Tracer#start_span time.

Returns:

  • (Scope)

    the currently active Scope which can be used to access the



39
40
41
# File 'lib/datadog/opentracer/thread_local_scope_manager.rb', line 39

def active
  Thread.current[@thread_key]
end