Sha256: f36175ce2ff2298626cb0a3176f4853295920ebb78a0ca5036ebd1fa1ee97db6

Contents?: true

Size: 1.67 KB

Versions: 9

Compression:

Stored size: 1.67 KB

Contents

# typed: true

require_relative '../../metadata/ext'
require_relative '../analytics'
require_relative 'ext'
require_relative 'tracing'

module Datadog
  module Tracing
    module Contrib
      module Sidekiq
        # Tracer is a Sidekiq client-side middleware which traces job enqueues/pushes
        class ClientTracer
          include Tracing

          def initialize(options = {})
            @sidekiq_service = options[:client_service_name] || configuration[:client_service_name]
          end

          # Client middleware arguments are documented here:
          #   https://github.com/mperham/sidekiq/wiki/Middleware#client-middleware
          def call(worker_class, job, queue, redis_pool)
            resource = job_resource(job)

            Datadog::Tracing.trace(Ext::SPAN_PUSH, service: @sidekiq_service) do |span|
              span.resource = resource

              span.set_tag(Datadog::Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
              span.set_tag(Datadog::Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_PUSH)

              # Set analytics sample rate
              if Contrib::Analytics.enabled?(configuration[:analytics_enabled])
                Contrib::Analytics.set_sample_rate(span, configuration[:analytics_sample_rate])
              end
              span.set_tag(Ext::TAG_JOB_ID, job['jid'])
              span.set_tag(Ext::TAG_JOB_QUEUE, job['queue'])
              span.set_tag(Ext::TAG_JOB_WRAPPER, job['class']) if job['wrapped']

              yield
            end
          end

          private

          def configuration
            Datadog.configuration.tracing[:sidekiq]
          end
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
ddtrace-1.6.1 lib/datadog/tracing/contrib/sidekiq/client_tracer.rb
ddtrace-1.6.0 lib/datadog/tracing/contrib/sidekiq/client_tracer.rb
ddtrace-1.5.2 lib/datadog/tracing/contrib/sidekiq/client_tracer.rb
ddtrace-1.5.1 lib/datadog/tracing/contrib/sidekiq/client_tracer.rb
ddtrace-1.5.0 lib/datadog/tracing/contrib/sidekiq/client_tracer.rb
ddtrace-1.4.2 lib/datadog/tracing/contrib/sidekiq/client_tracer.rb
ddtrace-1.4.1 lib/datadog/tracing/contrib/sidekiq/client_tracer.rb
ddtrace-1.4.0 lib/datadog/tracing/contrib/sidekiq/client_tracer.rb
ddtrace-1.3.0 lib/datadog/tracing/contrib/sidekiq/client_tracer.rb