Sha256: 1f93fe9cdfcba7785f7ff46ea9da121df6d050c3d2bad3de2e71cd4dd1067fd9

Contents?: true

Size: 1.08 KB

Versions: 5

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

# Copyright 2020 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)
              tracer.in_span(
                job['wrapped']&.to_s || job['class'],
                attributes: {
                  'messaging.message_id' => job['jid'],
                  'messaging.destination' => job['queue']
                },
                kind: :producer
              ) do |span|
                OpenTelemetry.propagation.text.inject(job)
                span.add_event('created_at', timestamp: job['created_at'])
                yield
              end
            end

            private

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
opentelemetry-instrumentation-sidekiq-0.10.0 lib/opentelemetry/instrumentation/sidekiq/middlewares/client/tracer_middleware.rb
opentelemetry-instrumentation-sidekiq-0.9.0 lib/opentelemetry/instrumentation/sidekiq/middlewares/client/tracer_middleware.rb
opentelemetry-instrumentation-sidekiq-0.8.0 lib/opentelemetry/instrumentation/sidekiq/middlewares/client/tracer_middleware.rb
opentelemetry-instrumentation-sidekiq-0.7.0 lib/opentelemetry/instrumentation/sidekiq/middlewares/client/tracer_middleware.rb
opentelemetry-instrumentation-sidekiq-0.6.0 lib/opentelemetry/instrumentation/sidekiq/middlewares/client/tracer_middleware.rb