Sha256: 587de58f10ada4151968ccfa18084c8cf90da0eca0c059e4a8653e080b894227

Contents?: true

Size: 735 Bytes

Versions: 7

Compression:

Stored size: 735 Bytes

Contents

# frozen_string_literal: true

module Honeycomb
  # Stores the current span and trace context
  class Context
    attr_writer :classic
    def current_trace
      return if current_span.nil?

      current_span.trace
    end

    def current_span
      spans.last
    end

    def current_span=(span)
      spans << span
    end

    def span_sent(span)
      spans.last != span && raise(ArgumentError, "Incorrect span sent")

      spans.pop
    end

    def classic?
      @classic
    end

    private

    def spans
      storage["spans"] ||= []
    end

    def storage
      Thread.current[thread_key] ||= {}
    end

    def thread_key
      @thread_key ||= ["honeycomb", self.class.name, object_id].join("-")
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
honeycomb-beeline-3.1.0 lib/honeycomb/context.rb
honeycomb-beeline-3.0.1 lib/honeycomb/context.rb
honeycomb-beeline-3.0.0 lib/honeycomb/context.rb
honeycomb-beeline-2.11.1.pre.dev lib/honeycomb/context.rb
honeycomb-beeline-2.11.0 lib/honeycomb/context.rb
honeycomb-beeline-2.10.0 lib/honeycomb/context.rb
honeycomb-beeline-2.9.0 lib/honeycomb/context.rb