Sha256: c410946c62ba0e226dfd6d7571708986c73fa5176750f26872485515805fac95

Contents?: true

Size: 1.26 KB

Versions: 27

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true

require "opentracing"

module Labkit
  module Tracing
    # https://edgeapi.rubyonrails.org/classes/ActiveSupport/Notifications/Instrumenter.html#method-c-new
    class AbstractInstrumenter
      def start(_name, _id, payload)
        scope = OpenTracing.start_active_span(span_name(payload))

        scope_stack.push scope
      end

      def finish(_name, _id, payload)
        scope = scope_stack.pop
        span = scope.span

        Labkit::Tracing::TracingUtils.log_common_fields_on_span(span, span_name(payload))

        # exception_object is the standard exception payload from ActiveSupport::Notifications
        # https://github.com/rails/rails/blob/v6.0.3.1/activesupport/lib/active_support/notifications/instrumenter.rb#L26
        exception = payload[:exception_object].presence || payload[:exception].presence
        Labkit::Tracing::TracingUtils.log_exception_on_span(span, exception)

        tags(payload).each do |k, v|
          span.set_tag(k, v)
        end

        scope.close
      end

      def scope_stack
        Thread.current[:_labkit_trace_scope_stack] ||= []
      end

      def span_name(_payload)
        raise "span_name not implemented"
      end

      def tags(_payload)
        {}
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
gitlab-labkit-0.36.1 lib/labkit/tracing/abstract_instrumenter.rb
gitlab-labkit-0.36.0 lib/labkit/tracing/abstract_instrumenter.rb
gitlab-labkit-0.35.1 lib/labkit/tracing/abstract_instrumenter.rb
gitlab-labkit-0.35.0 lib/labkit/tracing/abstract_instrumenter.rb
gitlab-labkit-0.34.0 lib/labkit/tracing/abstract_instrumenter.rb
gitlab-labkit-0.33.0 lib/labkit/tracing/abstract_instrumenter.rb
gitlab-labkit-0.32.0 lib/labkit/tracing/abstract_instrumenter.rb
gitlab-labkit-0.31.1 lib/labkit/tracing/abstract_instrumenter.rb
gitlab-labkit-0.31.0 lib/labkit/tracing/abstract_instrumenter.rb
gitlab-labkit-0.30.1 lib/labkit/tracing/abstract_instrumenter.rb
gitlab-labkit-0.30.0 lib/labkit/tracing/abstract_instrumenter.rb
gitlab-labkit-0.29.0 lib/labkit/tracing/abstract_instrumenter.rb
gitlab-labkit-0.28.0 lib/labkit/tracing/abstract_instrumenter.rb
gitlab-labkit-0.27.0 lib/labkit/tracing/abstract_instrumenter.rb
gitlab-labkit-0.26.0 lib/labkit/tracing/abstract_instrumenter.rb
gitlab-labkit-0.25.0 lib/labkit/tracing/abstract_instrumenter.rb
gitlab-labkit-0.24.0 lib/labkit/tracing/abstract_instrumenter.rb
gitlab-labkit-0.23.0 lib/labkit/tracing/abstract_instrumenter.rb
gitlab-labkit-0.22.0 lib/labkit/tracing/abstract_instrumenter.rb
gitlab-labkit-0.21.3 lib/labkit/tracing/abstract_instrumenter.rb