Class: Sentry::Rails::LogSubscribers::ActiveJobSubscriber
- Inherits:
-
Sentry::Rails::LogSubscriber
- Object
- ActiveSupport::LogSubscriber
- Sentry::Rails::LogSubscriber
- Sentry::Rails::LogSubscribers::ActiveJobSubscriber
- Includes:
- ParameterFilter
- Defined in:
- lib/sentry/rails/log_subscribers/active_job_subscriber.rb
Overview
LogSubscriber for ActiveJob events that captures background job execution and logs them using Sentry’s structured logging system.
This subscriber captures various ActiveJob events including job execution, enqueueing, retries, and failures with relevant job information.
Constant Summary
Constants included from ParameterFilter
Constants inherited from Sentry::Rails::LogSubscriber
Sentry::Rails::LogSubscriber::ORIGIN
Instance Method Summary collapse
- #discard(event) ⇒ Object
-
#enqueue(event) ⇒ Object
Handle enqueue.active_job events.
-
#perform(event) ⇒ Object
Handle perform.active_job events.
- #retry_stopped(event) ⇒ Object
Methods included from ParameterFilter
backend, #filter_sensitive_params
Methods inherited from Sentry::Rails::LogSubscriber
Instance Method Details
#discard(event) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/sentry/rails/log_subscribers/active_job_subscriber.rb', line 119 def discard(event) return unless Sentry.initialized? job = event.payload[:job] error = event.payload[:error] attributes = { job_class: job.class.name, job_id: job.job_id, queue_name: job.queue_name, executions: job.executions } attributes[:error_class] = error.class.name if error attributes[:error_message] = error. if error = "Job discarded: #{job.class.name}" log_structured_event( message: , level: :warn, attributes: attributes ) end |
#enqueue(event) ⇒ Object
Handle enqueue.active_job events
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/sentry/rails/log_subscribers/active_job_subscriber.rb', line 67 def enqueue(event) return unless Sentry.initialized? job = event.payload[:job] attributes = { job_class: job.class.name, job_id: job.job_id, queue_name: job.queue_name, priority: job.priority } attributes[:adapter] = job.class.queue_adapter.class.name if job.class.respond_to?(:queue_adapter) if job.scheduled_at attributes[:scheduled_at] = job.scheduled_at.iso8601 attributes[:delay_seconds] = (job.scheduled_at - Time.current).round(2) end = "Job enqueued: #{job.class.name}" log_structured_event( message: , level: :info, attributes: attributes ) end |
#perform(event) ⇒ Object
Handle perform.active_job events
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/sentry/rails/log_subscribers/active_job_subscriber.rb', line 28 def perform(event) return unless Sentry.initialized? job = event.payload[:job] duration = duration_ms(event) attributes = { job_class: job.class.name, job_id: job.job_id, queue_name: job.queue_name, duration_ms: duration, executions: job.executions, priority: job.priority } attributes[:adapter] = job.class.queue_adapter.class.name if job.scheduled_at attributes[:scheduled_at] = job.scheduled_at.iso8601 attributes[:delay_ms] = ((Time.current - job.scheduled_at) * 1000).round(2) end if Sentry.configuration.send_default_pii && job.arguments.present? filtered_args = filter_sensitive_arguments(job.arguments) attributes[:arguments] = filtered_args unless filtered_args.empty? end = "Job performed: #{job.class.name}" log_structured_event( message: , level: :info, attributes: attributes ) end |
#retry_stopped(event) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/sentry/rails/log_subscribers/active_job_subscriber.rb', line 95 def retry_stopped(event) return unless Sentry.initialized? job = event.payload[:job] error = event.payload[:error] attributes = { job_class: job.class.name, job_id: job.job_id, queue_name: job.queue_name, executions: job.executions, error_class: error.class.name, error_message: error. } = "Job retry stopped: #{job.class.name}" log_structured_event( message: , level: :error, attributes: attributes ) end |