Class: Datadog::OpenTracer::ThreadLocalScope

Inherits:
Scope
  • Object
show all
Defined in:
lib/datadog/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.



11
12
13
14
15
16
17
18
19
# File 'lib/datadog/opentracer/thread_local_scope.rb', line 11

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.



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

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.



26
27
28
29
30
31
# File 'lib/datadog/opentracer/thread_local_scope.rb', line 26

def close
  return unless equal?(manager.active)

  span.finish if finish_on_close
  manager.send(:set_scope, @previous_scope)
end