Class: SpanManager::Tracer

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

Overview

Convenience [OpenTracing::Tracer] that automates managing current span.

It’s a wrapper that forwards all calls to another [OpenTracing::Tracer] implementation. Spans created with this tracer are automatically activated when started, and deactivated when they finish.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tracer, managed_span_source = ThreadLocalManagedSpanSource.new) ⇒ Tracer

Returns a new instance of Tracer.

Parameters:

  • tracer (OpenTracing::Tracer)

    the tracer to be wrapped.

  • active_span_source (SpanManager::ManagedSpanSource)

    the span source that keeps track of the current active span.



16
17
18
19
# File 'lib/spanmanager/tracer.rb', line 16

def initialize(tracer, managed_span_source = ThreadLocalManagedSpanSource.new)
  @tracer = tracer
  @managed_span_source = managed_span_source
end

Instance Attribute Details

#managed_span_sourceSpanManager::ManagedSpanSource (readonly)

Returns the active span source

Returns:



12
13
14
# File 'lib/spanmanager/tracer.rb', line 12

def managed_span_source
  @managed_span_source
end

Instance Method Details

#active_spanSpanManager::ManagedSpan

Retrieves the current active span.

Returns:



29
30
31
# File 'lib/spanmanager/tracer.rb', line 29

def active_span
  managed_span_source.active_span
end

#start_span(operation_name, child_of: active_span, **args) ⇒ SpanManager::ManagedSpan

Starts a new active span.

Parameters:

  • operation_name (String)

    The operation name for the Span

  • child_of (SpanContext, Span) (defaults to: active_span)

    SpanContext that acts as a parent to the newly-started Span. If default argument is used then the currently active span becomes an implicit parent of a newly-started span.

Returns:



42
43
44
45
# File 'lib/spanmanager/tracer.rb', line 42

def start_span(operation_name, child_of: active_span, **args)
  span = @tracer.start_span(operation_name, child_of: child_of, **args)
  @managed_span_source.make_active(span)
end

#wrappedOpenTracing::Tracer

Returns the wrapped tracer.

Returns:

  • (OpenTracing::Tracer)

    the wrapped tracer



22
23
24
# File 'lib/spanmanager/tracer.rb', line 22

def wrapped
  @tracer
end