Sha256: 26ab93c5aed95efaf9ebf0edb66d2c82a789e02f6825072718d41bdfc9022ddc

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

require 'opentracing'

require_relative 'type_check'
require_relative 'id_provider'
require_relative 'span_context'
require_relative  'span'

module Test
  class Tracer < OpenTracing::Tracer
    include TypeCheck

    attr_reader :spans, :finished_spans

    def initialize
      @spans = []
      @finished_spans = []
    end

    def start_span(operation_name, child_of: nil, references: nil, start_time: Time.now, tags: nil)
      Type! child_of, ::Test::Span, ::Test::SpanContext, NilClass

      parent_context = child_of && child_of.respond_to?(:context) ? child_of.context : child_of
      new_context = parent_context ? ::Test::SpanContext.child_of(parent_context) : ::Test::SpanContext.root

      new_span = Span.new(tracer: self,
                          operation_name: operation_name,
                          context: new_context,
                          start_time: start_time,
                          tags: tags)
      @spans << new_span
      new_span
    end

    def clear
      @spans.clear
      @finished_spans.clear
      self
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
test-tracer-1.0.0 lib/test/tracer.rb