Class: SpanManager::ManagedSpan

Inherits:
OpenTracing::Span
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/spanmanager/managed_span.rb

Overview

The [SpanManager::ManagedSpan] inherits all of the OpenTracing funcionality and layers on in-process propagation capabilities.

Instance Method Summary collapse

Constructor Details

#initialize(span, deactivate) ⇒ ManagedSpan

Initializes a new active span. It’s ManagedSpanSource responsibility to activate the span.

Parameters:

  • span (OpenTracing::Span)

    the span to wrap

  • deactivate (Proc)

    the current span deactivation supplier. The block must return instance of [SpanManager::ManagedSpan]



13
14
15
16
17
# File 'lib/spanmanager/managed_span.rb', line 13

def initialize(span, deactivate)
  @span = span
  @deactivate = deactivate.respond_to?(:call) ? deactivate : nil
  @active = true
end

Instance Method Details

#active?Boolean

Returns whether the span is active or not.

Returns:

  • (Boolean)

    whether the span is active or not



20
21
22
# File 'lib/spanmanager/managed_span.rb', line 20

def active?
  @active
end

#deactivateObject

Mark the end of active period for the current span in this asynchronus executor and/or thread. It’s safe to call the method multiple times.



26
27
28
29
30
31
32
# File 'lib/spanmanager/managed_span.rb', line 26

def deactivate
  if @active && @deactivate
    deactivated_span = @deactivate.call
    warn "ActiveSpan::SpanSource inconsistency found during deactivation" unless deactivated_span == self
    @active = false
  end
end

#finish(end_time: Time.now) ⇒ Object

Finishes the current span, and if not yet deactivated marks the end of the active period for the span.

Parameters:

  • end_time (Time) (defaults to: Time.now)

    custom end time, if not now



36
37
38
39
# File 'lib/spanmanager/managed_span.rb', line 36

def finish(end_time: Time.now)
  deactivate
  @span.finish(end_time: end_time)
end