Sha256: 21b861485b0b228de8b46c4a9dff5973b1bf279d416f9d44533c38c146baf489

Contents?: true

Size: 1.92 KB

Versions: 22

Compression:

Stored size: 1.92 KB

Contents

# frozen_string_literal: true

require "resque"

module Sentry
  module Resque
    def perform
      return super unless Sentry.initialized?

      Sentry.with_scope do |scope|
        begin
          contexts = generate_contexts
          scope.set_contexts(**contexts)
          scope.set_tags("resque.queue" => queue)

          scope.set_transaction_name(contexts.dig(:"Active-Job", :job_class) || contexts.dig(:"Resque", :job_class))
          transaction = Sentry.start_transaction(name: scope.transaction_name, op: "resque")
          scope.set_span(transaction) if transaction

          super

          finish_transaction(transaction, 200)
        rescue Exception => exception
          ::Sentry::Resque.capture_exception(exception, hint: { background: false })
          finish_transaction(transaction, 500)
          raise
        end
      end
    end

    def generate_contexts
      context = {}

      if payload["class"] == "ActiveJob::QueueAdapters::ResqueAdapter::JobWrapper"
        active_job_payload = payload["args"].first

        context[:"Active-Job"] = {
          job_class: active_job_payload["job_class"],
          job_id: active_job_payload["job_id"],
          arguments: active_job_payload["arguments"],
          executions: active_job_payload["executions"],
          exception_executions: active_job_payload["exception_executions"],
          locale: active_job_payload["locale"],
          enqueued_at: active_job_payload["enqueued_at"],
          queue: queue,
          worker: worker.to_s
        }
      else
        context[:"Resque"] = {
          job_class: payload["class"],
          arguments: payload["args"],
          queue: queue,
          worker: worker.to_s
        }
      end

      context
    end

    def finish_transaction(transaction, status)
      return unless transaction

      transaction.set_http_status(status)
      transaction.finish
    end
  end
end

Resque::Job.send(:prepend, Sentry::Resque)

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
sentry-resque-5.1.0 lib/sentry/resque.rb
sentry-resque-5.0.2 lib/sentry/resque.rb
sentry-resque-5.0.1 lib/sentry/resque.rb
sentry-resque-5.0.0 lib/sentry/resque.rb
sentry-resque-4.9.2 lib/sentry/resque.rb
sentry-resque-4.9.1 lib/sentry/resque.rb
sentry-resque-4.9.0 lib/sentry/resque.rb
sentry-resque-4.8.3 lib/sentry/resque.rb
sentry-resque-4.8.2 lib/sentry/resque.rb
sentry-resque-4.8.1 lib/sentry/resque.rb
sentry-resque-4.8.0 lib/sentry/resque.rb
sentry-resque-4.7.3 lib/sentry/resque.rb
sentry-resque-4.7.2 lib/sentry/resque.rb
sentry-resque-4.7.1 lib/sentry/resque.rb
sentry-resque-4.7.0 lib/sentry/resque.rb
sentry-resque-4.6.5 lib/sentry/resque.rb
sentry-resque-4.6.4 lib/sentry/resque.rb
sentry-resque-4.6.3 lib/sentry/resque.rb
sentry-resque-4.6.2 lib/sentry/resque.rb
sentry-resque-4.6.1 lib/sentry/resque.rb