sentry-good_job, the Good Job integration for Sentry's Ruby client
This gem provides the GoodJob integration for the Sentry Ruby SDK.
Getting Started
Install
gem "sentry-ruby"
gem "sentry-rails"
gem "good_job"
gem "sentry-good_job"Then you're all set! sentry-good_job will automatically capture exceptions from your ActiveJob workers when using Good Job as the backend!
Features
- Automatic Error Capture: Captures exceptions from ActiveJob workers using Good Job
- Performance Monitoring: Tracks job execution times and performance metrics
- Cron Monitoring: Automatic setup for scheduled jobs with cron monitoring
- Context Preservation: Maintains user context and trace propagation across job executions
- Configurable Reporting: Control when errors are reported (after retries, only dead jobs, etc.)
- Rails Integration: Seamless integration with Rails applications
Configuration
The integration can be configured through Sentry's configuration:
Sentry.init do |config|
config.dsn = 'your-dsn-here'
# Good Job specific configuration
config.good_job.enable_cron_monitors = true
# ActiveJob configuration (handled by sentry-rails)
config.rails.active_job_report_on_retry_error = false
config.send_default_pii = false
# Optional: Configure logging for debugging
config.sdk_logger = Rails.logger
endConfiguration Options
Good Job Specific Options
-
enable_cron_monitors(default:true): Enable cron monitoring for scheduled jobs
ActiveJob Options (handled by sentry-rails)
-
config.rails.active_job_report_on_retry_error(default:false): Only report errors after all retry attempts are exhausted -
config.send_default_pii(default:false): Include job arguments in error context (be careful with sensitive data) -
config.sdk_logger(default:nil): Configure the SDK logger for custom logging needs (general Sentry configuration)
Note: The Good Job integration now leverages sentry-rails for core ActiveJob functionality, including trace propagation, user context preservation, and error reporting. This provides better integration and reduces duplication.
Usage
Automatic Setup
The integration works automatically once installed. It will:
- Capture exceptions from ActiveJob workers using sentry-rails
- Set up performance monitoring for job execution with enhanced GoodJob-specific metrics
- Automatically configure cron monitoring for scheduled jobs
- Preserve user context and trace propagation across job executions
- Add GoodJob-specific context including queue name, executions, priority, and latency
Cron Monitoring
For scheduled jobs, cron monitoring is automatically set up based on your Good Job configuration:
# config/application.rb
config.good_job.cron = {
'my_scheduled_job' => {
class: 'MyScheduledJob',
cron: '0 * * * *' # Every hour
}
}You can also manually set up cron monitoring:
class MyScheduledJob < ApplicationJob
include Sentry::Cron::MonitorCheckIns
sentry_monitor_check_ins(
slug: "my_scheduled_job",
monitor_config: Sentry::Cron::MonitorConfig.from_crontab("0 * * * *", timezone: "UTC")
)
endCustom Error Handling
The integration respects ActiveJob's retry configuration and will only report errors based on your settings:
class MyJob < ApplicationJob
retry_on StandardError, wait: :exponentially_longer, attempts: 3
def perform
# This will only be reported to Sentry after 3 attempts if active_job_report_on_retry_error is true
raise "Something went wrong"
end
endDebugging and Detailed Logging
The integration uses the standard Sentry SDK logger (Sentry.configuration.sdk_logger) for all logging needs. You can configure this logger to get detailed information about what the integration is doing:
Sentry.init do |config|
config.dsn = 'your-dsn-here'
# Configure the SDK logger for debugging
config.sdk_logger = Logger.new($stdout)
config.sdk_logger.level = Logger::DEBUG
# Or use Rails logger with debug level
# config.sdk_logger = Rails.logger
# config.sdk_logger.level = Logger::DEBUG
endLog Levels
The integration logs at different levels:
- INFO: Integration setup, cron monitoring configuration, job monitoring setup
- WARN: Configuration issues, missing job classes, cron parsing errors
- DEBUG: Detailed execution flow (when debug level is enabled)
What Gets Logged
When logging is enabled, you'll see information about:
- Job execution start and completion
- Error capture and reporting decisions
- Cron monitoring setup and configuration
- Performance metrics collection
- GoodJob-specific context enhancement
- Integration initialization and setup
Performance Monitoring
When performance monitoring is enabled, the integration will track:
- Job execution time
- Queue latency (GoodJob-specific)
- Retry counts
- Job context and metadata
- GoodJob-specific metrics (queue name, executions, priority)
Error Context
The integration automatically adds relevant context to error reports:
- Job class name
- Job ID
- Queue name (GoodJob-specific)
- Execution count (GoodJob-specific)
- Priority (GoodJob-specific)
- Enqueued and scheduled timestamps
- Job arguments (if enabled via send_default_pii)
- Latency metrics (GoodJob-specific)
Compatibility
- Ruby 2.4+
- Rails 5.2+
- Good Job 4.x
- Sentry Ruby SDK 6.x
Contributing
We welcome contributions! Please see our contributing guidelines for details.
License
This project is licensed under the MIT License. See the LICENSE file for details.