Sha256: 21cdd0abf2407ad275f8ac88c4ff08ac0806cec8fd09a3169b70dd90b197b54c

Contents?: true

Size: 1.34 KB

Versions: 46

Compression:

Stored size: 1.34 KB

Contents

require 'ddtrace/contrib/sidekiq/tracing'
require 'ddtrace/contrib/analytics'

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

        def initialize(options = {})
          super
          @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)

          @tracer.trace(Ext::SPAN_PUSH, service: @sidekiq_service) do |span|
            span.resource = resource
            # 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[:sidekiq]
        end
      end
    end
  end
end

Version data entries

46 entries across 46 versions & 2 rubygems

Version Path
ddtrace-0.51.1 lib/ddtrace/contrib/sidekiq/client_tracer.rb
ddtrace-0.51.0 lib/ddtrace/contrib/sidekiq/client_tracer.rb
ddtrace-0.50.0 lib/ddtrace/contrib/sidekiq/client_tracer.rb
ddtrace-0.49.0 lib/ddtrace/contrib/sidekiq/client_tracer.rb
ddtrace-0.48.0 lib/ddtrace/contrib/sidekiq/client_tracer.rb
ddtrace-0.47.0 lib/ddtrace/contrib/sidekiq/client_tracer.rb
ddtrace-0.46.0 lib/ddtrace/contrib/sidekiq/client_tracer.rb
ddtrace-0.45.0 lib/ddtrace/contrib/sidekiq/client_tracer.rb
ddtrace-0.44.0 lib/ddtrace/contrib/sidekiq/client_tracer.rb
ddtrace-0.43.0 lib/ddtrace/contrib/sidekiq/client_tracer.rb
ddtrace-0.42.0 lib/ddtrace/contrib/sidekiq/client_tracer.rb
ddtrace-0.41.0 lib/ddtrace/contrib/sidekiq/client_tracer.rb
ls-trace-0.2.0 lib/ddtrace/contrib/sidekiq/client_tracer.rb
ddtrace-0.40.0 lib/ddtrace/contrib/sidekiq/client_tracer.rb
ddtrace-0.39.0 lib/ddtrace/contrib/sidekiq/client_tracer.rb
ddtrace-0.38.0 lib/ddtrace/contrib/sidekiq/client_tracer.rb
ddtrace-0.37.0 lib/ddtrace/contrib/sidekiq/client_tracer.rb
ddtrace-0.36.0 lib/ddtrace/contrib/sidekiq/client_tracer.rb
ls-trace-0.1.2 lib/ddtrace/contrib/sidekiq/client_tracer.rb
ddtrace-0.35.2 lib/ddtrace/contrib/sidekiq/client_tracer.rb