Class: Datadog::OpenTracer::ThreadLocalScope

Inherits:
Scope
  • Object
show all
Defined in:
lib/ddtrace/opentracer/thread_local_scope.rb

Overview

OpenTracing adapter for thread local scopes

Instance Attribute Summary collapse

Attributes inherited from Scope

#manager, #span

Instance Method Summary collapse

Constructor Details

#initialize(manager:, span:, finish_on_close: true) ⇒ ThreadLocalScope

Returns a new instance of ThreadLocalScope.



8
9
10
11
12
13
14
15
16
# File 'lib/ddtrace/opentracer/thread_local_scope.rb', line 8

def initialize(
  manager:,
  span:,
  finish_on_close: true
)
  super(manager: manager, span: span)
  @finish_on_close = finish_on_close
  @previous_scope = manager.active
end

Instance Attribute Details

#finish_on_closeObject (readonly)

Returns the value of attribute finish_on_close.



5
6
7
# File 'lib/ddtrace/opentracer/thread_local_scope.rb', line 5

def finish_on_close
  @finish_on_close
end

Instance Method Details

#closeObject

Mark the end of the active period for the current thread and Scope, updating the ScopeManager#active in the process.

NOTE: Calling close more than once on a single Scope instance leads to undefined behavior.



23
24
25
26
27
# File 'lib/ddtrace/opentracer/thread_local_scope.rb', line 23

def close
  return unless equal?(manager.active)
  span.finish if finish_on_close
  manager.send(:set_scope, @previous_scope)
end