Sha256: 33052f4f804074da428306313977da300a27152fd94b15b4a4c1321a40b704b8

Contents?: true

Size: 1.22 KB

Versions: 13

Compression:

Stored size: 1.22 KB

Contents

require 'delayed/plugin'

module Datadog
  module Contrib
    module DelayedJob
      # DelayedJob plugin that instruments invoke_job hook
      class Plugin < Delayed::Plugin
        def self.instrument(job, &block)
          return block.call(job) unless tracer && tracer.enabled

          tracer.trace('delayed_job'.freeze, service: configuration[:service_name], resource: job.name) do |span|
            span.set_tag('delayed_job.id'.freeze, job.id)
            span.set_tag('delayed_job.queue'.freeze, job.queue) if job.queue
            span.set_tag('delayed_job.priority'.freeze, job.priority)
            span.set_tag('delayed_job.attempts'.freeze, job.attempts)
            span.span_type = Ext::AppTypes::WORKER

            yield job
          end
        end

        def self.flush(worker, &block)
          yield worker

          tracer.shutdown! if tracer && tracer.enabled
        end

        def self.configuration
          Datadog.configuration[:delayed_job]
        end

        def self.tracer
          configuration[:tracer]
        end

        callbacks do |lifecycle|
          lifecycle.around(:invoke_job, &method(:instrument))
          lifecycle.around(:execute, &method(:flush))
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
ddtrace-0.16.1 lib/ddtrace/contrib/delayed_job/plugin.rb
ddtrace-0.15.0.internaltracinfeature1 lib/ddtrace/contrib/delayed_job/plugin.rb
ddtrace-0.16.0 lib/ddtrace/contrib/delayed_job/plugin.rb
ddtrace-0.14.2.disableprotocolversion4 lib/ddtrace/contrib/delayed_job/plugin.rb
ddtrace-0.15.0 lib/ddtrace/contrib/delayed_job/plugin.rb
ddtrace-0.14.2.withoutpriorityparsing1 lib/ddtrace/contrib/delayed_job/plugin.rb
ddtrace-0.14.2 lib/ddtrace/contrib/delayed_job/plugin.rb
ddtrace-0.14.1 lib/ddtrace/contrib/delayed_job/plugin.rb
ddtrace-0.15.0.beta1 lib/ddtrace/contrib/delayed_job/plugin.rb
ddtrace-0.14.0 lib/ddtrace/contrib/delayed_job/plugin.rb
ddtrace-0.14.0.rc1 lib/ddtrace/contrib/delayed_job/plugin.rb
ddtrace-0.14.0.beta2 lib/ddtrace/contrib/delayed_job/plugin.rb
ddtrace-0.14.0.beta1 lib/ddtrace/contrib/delayed_job/plugin.rb