Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
b8163cf
Introduce sentry-good_job integration with essential files and config…
amkisko Oct 16, 2025
75c18f9
Update .gitignore and remove .rspec_status file
amkisko Oct 16, 2025
0c31fa1
Refactor job monitoring setup in sentry-good_job integration
amkisko Oct 16, 2025
fe90fb5
Refactor error handling in sentry-good_job integration
amkisko Oct 16, 2025
1dcd6bb
Enhance cron monitoring and error handling in sentry-good_job integra…
amkisko Oct 16, 2025
01fff5a
Update configuration option terminology in sentry-good_job integration
amkisko Oct 17, 2025
8f67392
Refactor sentry-good_job integration to leverage sentry-rails for Act…
amkisko Oct 17, 2025
07e9c7a
Fix enhance_sentry_reporter method to properly encapsulate patch
amkisko Oct 17, 2025
c79383f
Enhance cron monitoring setup in Sentry GoodJob integration
amkisko Oct 17, 2025
852b0fd
Improve error handling in Sentry ActiveJob integration
amkisko Oct 17, 2025
5fc4b5c
Enhance cron monitoring logging in Sentry GoodJob integration
amkisko Oct 17, 2025
9c95ff4
Refactor error handling in cron monitoring setup for Sentry GoodJob i…
amkisko Oct 17, 2025
4896a51
Refactor transaction initialization in Sentry integrations
amkisko Oct 17, 2025
3a03a19
Refactor transaction handling in Sentry ActiveJob integration
amkisko Oct 17, 2025
5cdb3d1
Refactor logging in Sentry GoodJob integration
amkisko Oct 17, 2025
8a4e074
Enhance Sentry GoodJob integration with improved context and span dat…
amkisko Oct 17, 2025
beb0927
Update README.md for Sentry GoodJob integration
amkisko Oct 17, 2025
8ff0023
Rubocop cleanup
amkisko Oct 17, 2025
471e613
Enhance user context preservation in Sentry integrations
amkisko Oct 17, 2025
3137ce5
Remove redundant user context preservation tests from Sentry integrat…
amkisko Oct 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions sentry-good_job/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/.bundle/
/.yardoc
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/
*.gem
*.rbc
/.config
/coverage/
/InstalledFiles
/pkg/
/spec/reports/
/spec/examples.txt
/test/tmp/
/test/version_tmp/
/tmp/

# Environment variables
.env
.env.local
.env.*.local

# Logs
*.log

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Coverage directory used by tools like istanbul
coverage/

# nyc test coverage
.nyc_output

# Dependency directories
node_modules/

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next

# Nuxt.js build output
.nuxt

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# RSpec status file
.rspec_status
3 changes: 3 additions & 0 deletions sentry-good_job/.rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--require spec_helper
--color
--format documentation
19 changes: 19 additions & 0 deletions sentry-good_job/.rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
inherit_gem:
rubocop-rails-omakase: rubocop.yml

Layout/SpaceInsideArrayLiteralBrackets:
Enabled: false

Layout/EmptyLineAfterMagicComment:
Enabled: true

Style/FrozenStringLiteralComment:
Enabled: true

Style/RedundantFreeze:
Enabled: true

AllCops:
Exclude:
- "tmp/**/*"
- "examples/**/*"
36 changes: 36 additions & 0 deletions sentry-good_job/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Changelog

Individual gem's changelog has been deprecated. Please check the [project changelog](https://github.com/getsentry/sentry-ruby/blob/master/CHANGELOG.md).

## 5.28.0

### Features

- Initial release of sentry-good_job integration
- Automatic error capture for ActiveJob workers using Good Job
- Performance monitoring for job execution
- Automatic cron monitoring setup for scheduled jobs
- Context preservation and trace propagation
- Configurable error reporting options
- Rails integration with automatic setup

### Configuration Options

#### Good Job Specific Options
- `enable_cron_monitors`: Enable cron monitoring for scheduled jobs
- `logging_enabled`: Enable logging for the Good Job integration
- `logger`: Custom logger to use

#### ActiveJob Options (handled by sentry-rails)
- `config.rails.active_job_report_on_retry_error`: Only report errors after all retry attempts are exhausted
- `config.send_default_pii`: Include job arguments in error context

**Note**: The Good Job integration now leverages sentry-rails for core ActiveJob functionality, including trace propagation, user context preservation, and error reporting.

### Integration Features

- Seamless integration with Rails applications
- Automatic setup when Good Job integration is enabled
- Support for both manual and automatic cron monitoring
- Respects ActiveJob retry configuration
- Comprehensive error context and performance metrics
16 changes: 16 additions & 0 deletions sentry-good_job/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

source "https://rubygems.org"

# Specify your gem's dependencies in sentry-good_job.gemspec
gemspec

gem "rake", "~> 13.0"

group :development, :test do
gem "rspec", "~> 3.0"
gem "rubocop", "~> 1.0"
gem "rubocop-rails-omakase", "~> 1.0"
gem "simplecov", "~> 0.22"
gem "simplecov-cobertura", "~> 2.0"
end
21 changes: 21 additions & 0 deletions sentry-good_job/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Sentry

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
22 changes: 22 additions & 0 deletions sentry-good_job/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

.PHONY: test
test:
bundle exec rspec

.PHONY: lint
lint:
bundle exec rubocop

.PHONY: install
install:
bundle install

.PHONY: console
console:
bundle exec bin/console

.PHONY: setup
setup:
bundle install
bundle exec bin/setup
190 changes: 190 additions & 0 deletions sentry-good_job/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
<p align="center">
<a href="https://sentry.io" target="_blank" align="center">
<img src="https://sentry-brand.storage.googleapis.com/sentry-logo-black.png" width="280">
</a>
<br>
</p>

# sentry-good_job, the Good Job integration for Sentry's Ruby client

---

[![Gem Version](https://img.shields.io/gem/v/sentry-good_job.svg)](https://rubygems.org/gems/sentry-good_job)
![Build Status](https://github.com/getsentry/sentry-ruby/actions/workflows/sentry_good_job_test.yml/badge.svg)
[![Coverage Status](https://img.shields.io/codecov/c/github/getsentry/sentry-ruby/master?logo=codecov)](https://codecov.io/gh/getsentry/sentry-ruby/branch/master)
[![Gem](https://img.shields.io/gem/dt/sentry-good_job.svg)](https://rubygems.org/gems/sentry-good_job/)
[![SemVer](https://api.dependabot.com/badges/compatibility_score?dependency-name=sentry-good_job&package-manager=bundler&version-scheme=semver)](https://dependabot.com/compatibility-score.html?dependency-name=sentry-good_job&package-manager=bundler&version-scheme=semver)

[Documentation](https://docs.sentry.io/platforms/ruby/guides/good_job/) | [Bug Tracker](https://github.com/getsentry/sentry-ruby/issues) | [Forum](https://forum.sentry.io/) | IRC: irc.freenode.net, #sentry

The official Ruby-language client and integration layer for the [Sentry](https://github.com/getsentry/sentry) error reporting API.

## Getting Started

### Install

```ruby
gem "sentry-ruby"
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:

```ruby
Sentry.init do |config|
config.dsn = 'your-dsn-here'

# Good Job specific configuration
config.good_job.enable_cron_monitors = true
config.good_job.logging_enabled = false

# ActiveJob configuration (handled by sentry-rails)
config.rails.active_job_report_on_retry_error = false
config.send_default_pii = false # Controls job arguments inclusion
end
```

### Configuration Options

#### Good Job Specific Options

- `enable_cron_monitors` (default: `true`): Enable cron monitoring for scheduled jobs
- `logging_enabled` (default: `false`): Enable logging for the Good Job integration
- `logger` (default: `nil`): Custom logger to use (defaults to Rails.logger when available)

#### 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)

**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

### Basic Setup

The integration works automatically once installed. It will:

1. Capture exceptions from ActiveJob workers
2. Set up performance monitoring for job execution
3. Automatically configure cron monitoring for scheduled jobs
4. Preserve user context and trace propagation

### Automatic Setup

The integration works automatically once installed. It will:

1. **Capture exceptions** from ActiveJob workers using sentry-rails
2. **Set up performance monitoring** for job execution with enhanced GoodJob-specific metrics
3. **Automatically configure cron monitoring** for scheduled jobs
4. **Preserve user context and trace propagation** across job executions
5. **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:

```ruby
# config/application.rb
config.good_job.cron = {
'my_scheduled_job' => {
class: 'MyScheduledJob',
cron: '0 * * * *' # Every hour
}
}
```

You can also manually set up cron monitoring:

```ruby
class MyScheduledJob < ApplicationJob
sentry_cron_monitor "0 * * * *", timezone: "UTC"
end
```

### Custom Error Handling

The integration respects ActiveJob's retry configuration and will only report errors based on your settings:

```ruby
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
end
```

### Debugging and Detailed Logging

For debugging purposes, you can enable detailed logging to see what the integration is doing:

```ruby
Sentry.init do |config|
config.dsn = 'your-dsn-here'

# Enable detailed logging for debugging
config.good_job.logging_enabled = true
config.good_job.logger = Logger.new($stdout)
end
```

This will output detailed information about:
- Job execution start and completion
- Error capture and reporting decisions
- Cron monitoring setup
- Performance metrics collection
- GoodJob-specific context enhancement

## 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 3.0+
- Sentry Ruby SDK 5.28.0+

## Contributing

We welcome contributions! Please see our [contributing guidelines](https://github.com/getsentry/sentry-ruby/blob/master/CONTRIBUTING.md) for details.

## License

This project is licensed under the MIT License. See the [LICENSE](LICENSE.txt) file for details.
Loading