Sha256: 1b0ac2bbb4289d61159ff39901abf358406f8be85ad8b7ca65985b01c0b3fc20

Contents?: true

Size: 1.25 KB

Versions: 7

Compression:

Stored size: 1.25 KB

Contents

require 'ddtrace/ext/app_types'
require 'ddtrace/contrib/sidekiq/ext'

require 'yaml'

module Datadog
  module Contrib
    module Sidekiq
      # Common functionality used by both client-side and server-side tracers.
      module Tracing
        def initialize(options = {})
          @tracer = options[:tracer] || Datadog.configuration[:sidekiq][:tracer]
        end

        protected

        # If class is wrapping something else, the interesting resource info
        # is the underlying, wrapped class, and not the wrapper. This is
        # primarily to support `ActiveJob`.
        def job_resource(job)
          if job['wrapped']
            job['wrapped'].to_s
          elsif job['class'] == 'Sidekiq::Extensions::DelayedClass'
            delay_extension_class(job).to_s
          else
            job['class'].to_s
          end
        rescue => e
          Datadog.logger.debug { "Error retrieving Sidekiq job class name (jid:#{job['jid']}): #{e}" }

          job['class'].to_s
        end

        def delay_extension_class(job)
          clazz, method = YAML.parse(job['args'].first).children.first.children

          method = method.value[1..-1] # Remove leading `:` from method symbol

          "#{clazz.value}.#{method}"
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ddtrace-0.51.1 lib/ddtrace/contrib/sidekiq/tracing.rb
ddtrace-0.51.0 lib/ddtrace/contrib/sidekiq/tracing.rb
ddtrace-0.50.0 lib/ddtrace/contrib/sidekiq/tracing.rb
ddtrace-0.49.0 lib/ddtrace/contrib/sidekiq/tracing.rb
ddtrace-0.48.0 lib/ddtrace/contrib/sidekiq/tracing.rb
ddtrace-0.47.0 lib/ddtrace/contrib/sidekiq/tracing.rb
ddtrace-0.46.0 lib/ddtrace/contrib/sidekiq/tracing.rb