Sha256: b35d80ba43fe93417a505b43790548d2f3bdfe0d690742db18cd9d76eec9b1c3

Contents?: true

Size: 1.55 KB

Versions: 1

Compression:

Stored size: 1.55 KB

Contents

# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2021

module Instana
  module Instrumentation
    module ActiveJob
      def self.prepended(target)
        target.around_enqueue do |job, block|
          tags = {
            activejob: {
              queue: job.queue_name,
              job: job.class.to_s,
              action: :enqueue,
              job_id: job.job_id
            }
          }

          ::Instana::Tracer.trace(:activejob, tags) do
            context = ::Instana.tracer.context
            job.arguments.append({
                                   instana_context: context ? context.to_hash : nil
                                 })

            block.call
          end
        end

        target.around_perform do |job, block|
          tags = {
            activejob: {
              queue: job.queue_name,
              job: job.class.to_s,
              action: :perform,
              job_id: job.job_id
            }
          }
          incoming_context = if job.arguments.is_a?(Array) && job.arguments.last.is_a?(Hash) && job.arguments.last.key?(:instana_context)
                               instana_context = job.arguments.last[:instana_context]
                               job.arguments.pop
                               instana_context ? ::Instana::SpanContext.new(instana_context[:trace_id], instana_context[:span_id]) : nil
                             end

          ::Instana::Tracer.start_or_continue_trace(:activejob, tags, incoming_context) do
            block.call
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
instana-1.217.1 lib/instana/instrumentation/active_job.rb