|
4 | 4 |
|
5 | 5 | module Appsignal
|
6 | 6 | module Integrations
|
| 7 | + # Handler for job death events. We get notified when a job has exhausted |
| 8 | + # its retries. |
| 9 | + # |
| 10 | + # This is called before the SidekiqErrorHandler so it doesn't need to worry |
| 11 | + # about completing the transaction. |
| 12 | + # |
| 13 | + # Introduced in Sidekiq 5.1. |
| 14 | + class SidekiqDeathHandler |
| 15 | + def call(_job_context, exception) |
| 16 | + return unless Appsignal.config[:sidekiq_report_errors] == "discard" |
| 17 | + |
| 18 | + transaction = Appsignal::Transaction.current |
| 19 | + transaction.set_error(exception) |
| 20 | + end |
| 21 | + end |
| 22 | + |
7 | 23 | # Error handler for Sidekiq to report errors from jobs and internal Sidekiq
|
8 | 24 | # errors.
|
9 | 25 | #
|
10 | 26 | # @api private
|
11 | 27 | class SidekiqErrorHandler
|
| 28 | + # Sidekiq 7.1.5 introduced the third sidekiq_config argument. It is not |
| 29 | + # given on older Sidekiq versions. |
12 | 30 | def call(exception, sidekiq_context, _sidekiq_config = nil)
|
13 |
| - transaction = |
14 |
| - if Appsignal::Transaction.current? |
15 |
| - Appsignal::Transaction.current |
16 |
| - else |
17 |
| - # Sidekiq error outside of the middleware scope. |
18 |
| - # Can be a job JSON parse error or some other error happening in |
19 |
| - # Sidekiq. |
20 |
| - transaction = |
21 |
| - Appsignal::Transaction.create( |
22 |
| - SecureRandom.uuid, # Newly generated job id |
23 |
| - Appsignal::Transaction::BACKGROUND_JOB, |
24 |
| - Appsignal::Transaction::GenericRequest.new({}) |
25 |
| - ) |
26 |
| - transaction.set_action_if_nil("SidekiqInternal") |
27 |
| - transaction.set_metadata("sidekiq_error", sidekiq_context[:context]) |
28 |
| - transaction.params = { :jobstr => sidekiq_context[:jobstr] } |
29 |
| - transaction |
| 31 | + if Appsignal::Transaction.current? |
| 32 | + if Appsignal.config[:sidekiq_report_errors] == "all" |
| 33 | + transaction = Appsignal::Transaction.current |
| 34 | + transaction.set_error(exception) |
30 | 35 | end
|
| 36 | + else |
| 37 | + # Sidekiq error outside of the middleware scope. |
| 38 | + # Can be a job JSON parse error or some other error happening in |
| 39 | + # Sidekiq. |
| 40 | + transaction = |
| 41 | + Appsignal::Transaction.create( |
| 42 | + SecureRandom.uuid, # Newly generated job id |
| 43 | + Appsignal::Transaction::BACKGROUND_JOB, |
| 44 | + Appsignal::Transaction::GenericRequest.new({}) |
| 45 | + ) |
| 46 | + transaction.set_action_if_nil("SidekiqInternal") |
| 47 | + transaction.set_metadata("sidekiq_error", sidekiq_context[:context]) |
| 48 | + transaction.params = { :jobstr => sidekiq_context[:jobstr] } |
| 49 | + transaction.set_error(exception) |
| 50 | + end |
31 | 51 |
|
32 |
| - transaction.set_error(exception) |
33 | 52 | Appsignal::Transaction.complete_current!
|
34 | 53 | end
|
35 | 54 | end
|
|
0 commit comments