class LightStep::ScopeManager
ScopeManager
represents an OpenTracing ScopeManager
See www.opentracing.io for more information.
The ScopeManager
interface abstracts both the activation of Span
instances via ScopeManager#activate
and access to an active Span/Scope via ScopeManager#active
Public Instance Methods
Make a span instance active.
@param span [Span] the Span
that should become active @param finish_on_close [Boolean] whether the Span
should automatically be
finished when Scope#close is called
@return [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.
# File lib/lightstep/scope_manager.rb, line 19 def activate(span:, finish_on_close: true) return active if active && active.span == span LightStep::Scope.new(manager: self, span: span, finish_on_close: finish_on_close).tap do |scope| add_scope(scope) end end
@return [Scope] the currently active Scope
which can be used to access the 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.
# File lib/lightstep/scope_manager.rb, line 32 def active scopes.last end
# File lib/lightstep/scope_manager.rb, line 36 def deactivate scopes.pop end
Private Instance Methods
# File lib/lightstep/scope_manager.rb, line 46 def add_scope(scope) if Thread.current[object_id.to_s].nil? Thread.current[object_id.to_s] = [scope] else Thread.current[object_id.to_s] << scope end end
# File lib/lightstep/scope_manager.rb, line 42 def scopes Thread.current[object_id.to_s] || [] end