Sha256: 6ccb8f7fa1416f0795d22029c568c6baf38ac3b50b79f531acc5343cb37c5638

Contents?: true

Size: 1.55 KB

Versions: 10

Compression:

Stored size: 1.55 KB

Contents

module Skylight
  class Trace < Core::Trace
    attr_reader :component

    def initialize(*, component: nil)
      super
      self.component = component if component
      @too_many_spans = false
      native_use_pruning if use_pruning?
    end

    def uuid
      native_get_uuid
    end

    def uuid=(value)
      # We can't change the UUID so just check to make sure we weren't trying to change
      raise "unable to change uuid" unless value == uuid
    end

    def too_many_spans!
      @too_many_spans = true
    end

    def too_many_spans?
      !!@too_many_spans
    end

    def maybe_broken(error)
      if error.is_a?(Skylight::MaximumTraceSpansError) && config.get(:report_max_spans_exceeded)
        too_many_spans!
      else
        super
      end
    end

    def traced
      if too_many_spans?
        error("[E%04d] The request exceeded the maximum number of spans allowed. It will still " \
              "be tracked but with reduced information. endpoint=%s", Skylight::MaximumTraceSpansError.code, endpoint)
      end

      super
    end

    private

      def track_gc(*)
        # This attempts to log another span which will fail if we have too many
        return if too_many_spans?
        super
      end

      def use_pruning?
        config.get(:prune_large_traces)
      end

      def resolve_component(component)
        config.components[component].to_encoded_s
      end

      def component=(component)
        resolve_component(component).tap do |c|
          @component = c
          native_set_component(c)
        end
      end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
skylight-4.3.2 lib/skylight/trace.rb
skylight-4.3.1 lib/skylight/trace.rb
skylight-4.3.0 lib/skylight/trace.rb
skylight-4.2.3 lib/skylight/trace.rb
skylight-4.2.2 lib/skylight/trace.rb
skylight-4.2.1 lib/skylight/trace.rb
skylight-4.2.0 lib/skylight/trace.rb
skylight-4.2.0.beta3 lib/skylight/trace.rb
skylight-4.2.0.beta2 lib/skylight/trace.rb
skylight-4.2.0.beta lib/skylight/trace.rb