Sha256: 3a76a1ad288e250f5223169d5237de4b9b0ba8dbafd5204a6db52026c6b86ae5

Contents?: true

Size: 1.22 KB

Versions: 6

Compression:

Stored size: 1.22 KB

Contents

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

module Datadog
  module Contrib
    module Resque
      # Uses Resque job hooks to create traces
      module ResqueJob
        def around_perform(*_)
          pin = Pin.get_from(::Resque)
          return yield unless pin && pin.tracer
          pin.tracer.trace(Ext::SPAN_JOB, service: pin.service) do |span|
            span.resource = name
            span.span_type = pin.app_type
            yield
            span.service = pin.service
          end
        end

        def after_perform_shutdown_tracer(*_)
          shutdown_tracer_when_forked!
        end

        def on_failure_shutdown_tracer(*_)
          shutdown_tracer_when_forked!
        end

        def shutdown_tracer_when_forked!
          pin = Datadog::Pin.get_from(Resque)
          pin.tracer.shutdown! if pin && pin.tracer && pin.config && pin.config[:forked]
        end
      end
    end
  end
end

Resque.after_fork do
  # get the current tracer
  pin = Datadog::Pin.get_from(Resque)
  next unless pin && pin.tracer
  pin.config ||= {}
  pin.config[:forked] = true

  # clean the state so no CoW happens
  pin.tracer.provider.context = nil
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ddtrace-0.18.3 lib/ddtrace/contrib/resque/resque_job.rb
ddtrace-0.18.2 lib/ddtrace/contrib/resque/resque_job.rb
ddtrace-0.18.1 lib/ddtrace/contrib/resque/resque_job.rb
ddtrace-0.18.0 lib/ddtrace/contrib/resque/resque_job.rb
ddtrace-0.17.3 lib/ddtrace/contrib/resque/resque_job.rb
ddtrace-0.17.2 lib/ddtrace/contrib/resque/resque_job.rb