Sha256: 5f10c7f30f3a9eb1eb2b5b6e288da39e208529f1bfc38080f4dcf035fbc23983

Contents?: true

Size: 1.71 KB

Versions: 2

Compression:

Stored size: 1.71 KB

Contents

# frozen_string_literal: true

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

module OpenTelemetry
  module Instrumentation
    module Sidekiq
      module Middlewares
        module Client
          # TracerMiddleware propagates context and instruments Sidekiq client
          # by way of its middleware system
          class TracerMiddleware
            def call(_worker_class, job, _queue, _redis_pool) # rubocop:disable Metrics/AbcSize
              attributes = {
                'messaging.system' => 'sidekiq',
                'messaging.sidekiq.job_class' => job['wrapped']&.to_s || job['class'],
                'messaging.message_id' => job['jid'],
                'messaging.destination' => job['queue'],
                'messaging.destination_kind' => 'queue'
              }
              attributes['peer.service'] = instrumentation_config[:peer_service] if instrumentation_config[:peer_service]

              span_name = case instrumentation_config[:span_naming]
                          when :job_class then "#{job['wrapped']&.to_s || job['class']} send"
                          else "#{job['queue']} send"
                          end

              tracer.in_span(span_name, attributes: attributes, kind: :producer) do |span|
                OpenTelemetry.propagation.inject(job)
                span.add_event('created_at', timestamp: job['created_at'])
                yield
              end
            end

            private

            def instrumentation_config
              Sidekiq::Instrumentation.instance.config
            end

            def tracer
              Sidekiq::Instrumentation.instance.tracer
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
opentelemetry-instrumentation-sidekiq-0.22.0 lib/opentelemetry/instrumentation/sidekiq/middlewares/client/tracer_middleware.rb
opentelemetry-instrumentation-sidekiq-0.21.1 lib/opentelemetry/instrumentation/sidekiq/middlewares/client/tracer_middleware.rb