Module: Wurk::Sentry::JobContext

Defined in:
lib/wurk/sentry/job_context.rb

Overview

Builds the per-job Sentry scope: transaction name, tags, and the wurk context block. Split out from Middleware so the shape of what Sentry sees can change without touching the capture policy.

Constant Summary collapse

CONTEXT_KEY =
:wurk
TRANSACTION_PREFIX =

Sentry groups issues by transaction name, and sentry-sidekiq names its transactions Sidekiq/<JobClass>. Mirroring that shape as Wurk/<JobClass> keeps a migrating app's issue list legible: the same job reads the same way before and after the swap, and the only diff is the prefix — so history stays searchable instead of fragmenting into unnamed transactions.

'Wurk/'

Class Method Summary collapse

Class Method Details

.apply(scope, job, queue) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/wurk/sentry/job_context.rb', line 21

def apply(scope, job, queue)
  scope.clear_breadcrumbs
  scope.set_transaction_name(transaction_name(job), source: :task)
  scope.set_tags(tags(job, queue))
  scope.set_context(CONTEXT_KEY, context(job, queue))
  scope
end

.context(job, queue) ⇒ Object

Deliberately enumerated, never job.dup.except("args"): job arguments routinely carry PII, tokens, or encrypt: true ciphertext, and Sentry is not a place any of that belongs. An allow-list can't leak a new payload key that a future Wurk release starts stamping.



41
42
43
44
45
46
47
48
49
50
# File 'lib/wurk/sentry/job_context.rb', line 41

def context(job, queue)
  {
    'class' => job['class'],
    'jid' => job['jid'],
    'queue' => job['queue'] || queue,
    'retry_count' => job['retry_count'],
    'created_at' => job['created_at'],
    'enqueued_at' => job['enqueued_at']
  }
end

.tags(job, queue) ⇒ Object



33
34
35
# File 'lib/wurk/sentry/job_context.rb', line 33

def tags(job, queue)
  { queue: job['queue'] || queue, jid: job['jid'] }
end

.transaction_name(job) ⇒ Object



29
30
31
# File 'lib/wurk/sentry/job_context.rb', line 29

def transaction_name(job)
  "#{TRANSACTION_PREFIX}#{job['class']}"
end