Sha256: deebbc34b9d0d551c76f24ccfbf047684a135cbf32c7a0211e0638cb7fcf7be1

Contents?: true

Size: 1.75 KB

Versions: 9

Compression:

Stored size: 1.75 KB

Contents

# frozen_string_literal: true

# Copyright The OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0

require 'opentelemetry'
require 'opentelemetry-instrumentation-base'

module OpenTelemetry
  module Instrumentation
    # Contains the OpenTelemetry instrumentation for the ActiveJob gem
    module ActiveJob
      extend self

      CURRENT_SPAN_KEY = Context.create_key('current-span')
      private_constant :CURRENT_SPAN_KEY

      # Returns the current span from the current or provided context
      #
      # @param [optional Context] context The context to lookup the current
      #   {Span} from. Defaults to Context.current
      def current_span(context = nil)
        context ||= Context.current
        context.value(CURRENT_SPAN_KEY) || OpenTelemetry::Trace::Span::INVALID
      end

      # Returns a context containing the span, derived from the optional parent
      # context, or the current context if one was not provided.
      #
      # @param [optional Context] context The context to use as the parent for
      #   the returned context
      def context_with_span(span, parent_context: Context.current)
        parent_context.set_value(CURRENT_SPAN_KEY, span)
      end

      # Activates/deactivates the Span within the current Context, which makes the "current span"
      # available implicitly.
      #
      # On exit, the Span that was active before calling this method will be reactivated.
      #
      # @param [Span] span the span to activate
      # @yield [span, context] yields span and a context containing the span to the block.
      def with_span(span)
        Context.with_value(CURRENT_SPAN_KEY, span) { |c, s| yield s, c }
      end
    end
  end
end

require_relative 'active_job/instrumentation'
require_relative 'active_job/version'

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
opentelemetry-instrumentation-active_job-0.7.8 lib/opentelemetry/instrumentation/active_job.rb
opentelemetry-instrumentation-active_job-0.7.7 lib/opentelemetry/instrumentation/active_job.rb
opentelemetry-instrumentation-active_job-0.7.6 lib/opentelemetry/instrumentation/active_job.rb
opentelemetry-instrumentation-active_job-0.7.5 lib/opentelemetry/instrumentation/active_job.rb
opentelemetry-instrumentation-active_job-0.7.4 lib/opentelemetry/instrumentation/active_job.rb
opentelemetry-instrumentation-active_job-0.7.3 lib/opentelemetry/instrumentation/active_job.rb
opentelemetry-instrumentation-active_job-0.7.2 lib/opentelemetry/instrumentation/active_job.rb
opentelemetry-instrumentation-active_job-0.7.1 lib/opentelemetry/instrumentation/active_job.rb
opentelemetry-instrumentation-active_job-0.7.0 lib/opentelemetry/instrumentation/active_job.rb