Sha256: 21b6ed662fd16e0e363bfa0ec06084e612c763a23297a7dcfe7ab15e6842e118

Contents?: true

Size: 1.58 KB

Versions: 9

Compression:

Stored size: 1.58 KB

Contents

# frozen_string_literal: true

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

module OpenTelemetry
  module Instrumentation
    module ActiveJob
      module Mappers
        # Maps ActiveJob Attributes to Semantic Conventions
        class Attribute
          # Generates a set of attributes to add to a span using
          # general and messaging semantic conventions as well as
          # using `rails.active_job.*` namespace for custom attributes
          #
          # @param payload [Hash] of an ActiveSupport::Notifications payload
          # @return [Hash<String, Object>] of semantic attributes
          def call(payload)
            job = payload.fetch(:job)

            otel_attributes = {
              'code.namespace' => job.class.name,
              'messaging.system' => 'active_job',
              'messaging.destination' => job.queue_name,
              'messaging.message.id' => job.job_id,
              'messaging.active_job.adapter.name' => job.class.queue_adapter_name
            }

            # Not all adapters generate or provide back end specific ids for messages
            otel_attributes['messaging.active_job.message.provider_job_id'] = job.provider_job_id.to_s if job.provider_job_id
            # This can be problematic if programs use invalid attribute types like Symbols for priority instead of using Integers.
            otel_attributes['messaging.active_job.message.priority'] = job.priority.to_s if job.priority

            otel_attributes.compact!

            otel_attributes
          end
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

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