Sha256: c79a132a550934c4df8096bd0e6086a29cb96e29864c5bf76fa6e93a432abb75
Contents?: true
Size: 1.18 KB
Versions: 6
Compression:
Stored size: 1.18 KB
Contents
require 'sentry/sidekiq/context_filter' module Sentry module Sidekiq class SentryContextMiddleware def call(_worker, job, queue) return yield unless Sentry.initialized? context_filter = Sentry::Sidekiq::ContextFilter.new(job) Sentry.clone_hub_to_current_thread scope = Sentry.get_current_scope scope.set_tags(queue: queue, jid: job["jid"]) scope.set_contexts(sidekiq: job.merge("queue" => queue)) scope.set_transaction_name(context_filter.transaction_name) transaction = Sentry.start_transaction(name: scope.transaction_name, op: "sidekiq") scope.set_span(transaction) if transaction begin yield rescue => e finish_transaction(transaction, 500) raise end finish_transaction(transaction, 200) # don't need to use ensure here # if the job failed, we need to keep the scope for error handler. and the scope will be cleared there scope.clear end def finish_transaction(transaction, status) return unless transaction transaction.set_http_status(status) transaction.finish end end end end
Version data entries
6 entries across 6 versions & 1 rubygems