Sha256: 3fc08bef4c947edec16502540408439113f91aba7299bef83ea576879f8dd851

Contents?: true

Size: 1.19 KB

Versions: 3

Compression:

Stored size: 1.19 KB

Contents

module Test
  class SpanContext < OpenTracing::SpanContext
    class << self
      def root
        new(trace_id: IdProvider.generate,
            span_id: IdProvider.generate)
      end

      def child_of(parent_context)
        new(trace_id: parent_context.trace_id,
            span_id: IdProvider.generate,
            parent_span_id: parent_context.span_id,
            baggage: parent_context.baggage)
      end
    end

    include TypeCheck

    attr_reader :trace_id, :span_id, :parent_span_id

    def initialize(trace_id:, span_id:, parent_span_id: nil, baggage: {})
      Type! trace_id, String
      Type! span_id, String
      Type! parent_span_id, String, NilClass
      Type! baggage, Hash

      super(baggage: baggage)

      @trace_id = trace_id
      @span_id = span_id
      @parent_span_id = parent_span_id
      @baggage = baggage
    end

    def to_s
      "SpanContext(trace_id=#{trace_id}, span_id=#{span_id}, parent_span_id=#{parent_span_id}, baggage=#{baggage})"
    end

    def ==(rhs)
      self.class == rhs.class &&
        trace_id == rhs.trace_id &&
        span_id == rhs.span_id &&
        parent_span_id == rhs.parent_span_id &&
        baggage == rhs.baggage
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
test-tracer-1.2.1 lib/test/span_context.rb
test-tracer-1.2.0 lib/test/span_context.rb
test-tracer-1.1.4 lib/test/span_context.rb