Skip to content

feat: add Sentry.Quartz for cron monitoring of Quartz.NET 4.x jobs - #5505

Merged
jamescrosswell merged 52 commits into
getsentry:mainfrom
michaelmairegger:feature/sentry.quartz
Oct 21, 2026
Merged

jamescrosswell merged 52 commits into
getsentry:mainfrom
michaelmairegger:feature/sentry.quartz

Conversation

@michaelmairegger

@michaelmairegger michaelmairegger commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Changelog Entry

  • Add Sentry.Quartz, an integration for Quartz.NET 4.x
    • services.AddQuartz(q => q.AddSentry()) runs each job in its own scope and trace, tagged with its job key, and captures the exceptions jobs throw
    • Jobs marked with [SentryMonitorSlug] send a Sentry Crons check-in for every run, with the trigger's cron or interval schedule as the monitor config, so monitors are created and kept up to date automatically
    • SentryQuartzOptions.ConfigureMonitorOptions customizes thresholds or the schedule, and SendMonitorConfig = false sends check-ins without a schedule

Description

Adds Sentry.Quartz, a Quartz.NET 4.x integration built on Quartz's job middleware.

services.AddQuartz(q => q.AddSentry());

[SentryMonitorSlug] // or [SentryMonitorSlug("nightly-report")]
public class NightlyReport : IJob { ... }

Each job runs in its own Sentry scope and trace (unless global mode is enabled), tagged quartz.job with its job key, and what it throws is captured in that scope. Quartz's ErrorLogger logs the same exception again, wrapped in a JobExecutionProcessException, which the SDK's default deduplication doesn't catch. So with Sentry's logging integration on, a log entry filter drops that entry, and each failure is captured once. Jobs with [SentryMonitorSlug] also send a check-in for each run: in progress when it starts, then ok or error with its duration. A cancelled run counts as an error.

The monitor slug is the attribute's value, otherwise the slugified job key (reports.DailyEmail becomes reports-dailyemail). A SentryMonitorSlug entry in the job's or trigger's data map overrides both.

The in-progress check-in carries the trigger's schedule as the monitor config, so monitors don't have to be created by hand. A schedule is only sent when Sentry reads it the same way Quartz does: cron triggers with a fixed seconds field, no year and no L/W/#, and simple triggers that repeat forever at whole minutes, hours or days. Triggers with a calendar, and triggers that share a monitor slug but have different schedules, get check-ins without a schedule rather than one that would raise false missed check-in alerts. To spot shared slugs, the SDK reads every monitored trigger in the scheduler and reuses the result for a minute.

Quartz 4 only targets net10.0, so this package does too. Quartz 3 support is in #5668, which compiles the same Core/ files against Quartz 3. The only change to Sentry itself is an internal SentryMonitorOptions.HasSchedule and CopyTo, which let ConfigureMonitorOptions replace the trigger's schedule. The filter needs SentryLoggingOptions, so Sentry.Quartz depends on Sentry.Extensions.Logging. Dropping the duplicate with an exception filter in Sentry instead would avoid that dependency, but each dropped event would then show up as discarded in client reports. There's a sample in samples/Sentry.Samples.Quartz.

Docs are in getsentry/sentry-docs#19790. .craft.yml points mainDocsUrl at the page that PR adds, so it should be merged before this is released.

Closes #4601

🤖 Generated with Claude Code

@github-actions github-actions Bot added the risk: high PR risk score: high label Aug 24, 2026
Comment thread samples/Sentry.Samples.Quartz/Program.cs Outdated
Comment thread samples/Sentry.Samples.Quartz/Program.cs
Comment thread samples/Sentry.Samples.Quartz/Program.cs
Comment thread samples/Sentry.Samples.Quartz/Sentry.Samples.Quartz.csproj
Comment thread src/Sentry.Quartz/GlobalConfigurationExtensions.cs Outdated
Comment thread src/Sentry.Quartz/GlobalConfigurationExtensions.cs Outdated
@michaelmairegger michaelmairegger changed the title Feature/sentry.quartz Feature/sentry.quartz (Quartz v4 Alpha version) Aug 24, 2026
Comment thread samples/Sentry.Samples.Quartz/Program.cs Outdated
Comment thread src/Sentry.Quartz/SentryCronJobListener.cs Outdated
Comment thread src/Sentry.Quartz/SentryCronJobMiddleware.cs Outdated
Comment thread src/Sentry.Quartz/Sentry.Quartz.csproj Outdated
@michaelmairegger

Copy link
Copy Markdown
Contributor Author

@jamescrosswell I will continue watching Quartz.Net alpha releases and adopt it until final bits of 4.0 will be released.
I will notify you when ready.

@jamescrosswell

jamescrosswell commented Aug 31, 2026 •

Copy link
Copy Markdown
Collaborator

@jamescrosswell I will continue watching Quartz.Net alpha releases and adopt it until final bits of 4.0 will be released. I will notify you when ready.

Fantastic, thank you @michaelmairegger !

Maybe we mark the PR as draft until then? That let's me know it doesn't yet need my attention (you can always tag me directly if you want my input on something before v4 is released).

@michaelmairegger michaelmairegger changed the title Feature/sentry.quartz (Quartz v4 Alpha version) 🚧 Feature/sentry.quartz (Quartz v4 Alpha version) Sep 1, 2026
Comment thread src/Sentry.Quartz/SentryCronJobMiddleware.cs Outdated
Comment thread src/Sentry.Quartz/SentryCronJobMiddleware.cs
Comment thread src/Sentry.Quartz/IQuartzBuilderExtensions.cs Outdated
Comment thread src/Sentry.Quartz/GlobalConfigurationExtensions.cs Outdated
Comment thread src/Sentry.Quartz/SentryMetricsMiddleware.cs Outdated
Comment thread src/Sentry.Quartz/IQuartzBuilderExtensions.cs Outdated
Comment thread src/Sentry.Quartz/SentryCronJobMiddleware.cs Outdated
Comment thread src/Sentry.Quartz/Sentry.Quartz.csproj Outdated
Comment thread src/Sentry.Quartz/SentryCronJobMiddleware.cs Outdated

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread src/Sentry.Quartz/SentryCronJobMiddleware.cs Outdated
Comment thread src/Sentry.Quartz/SentryCronJobMiddleware.cs Outdated

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread src/Sentry.Quartz/SentryCronJobMiddleware.cs Outdated
Comment thread samples/Sentry.Samples.Quartz/Properties/launchSettings.json Outdated

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread src/Sentry.Quartz/SentryCronJobMiddleware.cs Outdated
@michaelmairegger

Copy link
Copy Markdown
Contributor Author

@jamescrosswell quartz.net released final bits of v4. I updated the package to the final version and would say this first version of the package is feature complete.

@michaelmairegger michaelmairegger changed the title 🚧 Feature/sentry.quartz (Quartz v4 Alpha version) 🚧 Feature/sentry.quartz Sep 7, 2026
@michaelmairegger michaelmairegger changed the title 🚧 Feature/sentry.quartz Feature/sentry.quartz Sep 7, 2026
@jamescrosswell

Copy link
Copy Markdown
Collaborator

@jamescrosswell quartz.net released final bits of v4. I updated the package to the final version and would say this first version of the package is feature complete.

Nice - thanks @michaelmairegger. I wasn't expecting them to get v4 out so quickly!

Apologies in advance... I might be a bis slow on reviewing - there's quite a but going on right now and the invention of AI has made it much easier for people to make PRs - so I'm spread a bit thin.

@codecov

codecov Bot commented Sep 7, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.56977% with 29 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.12%. Comparing base (876f7a6) to head (f3d7c36).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/Sentry.Quartz/Core/JobMonitor.cs 89.61% 8 Missing and 8 partials ⚠️
src/Sentry.Quartz/Core/TriggerSchedule.cs 92.59% 3 Missing and 5 partials ⚠️
src/Sentry.Quartz/SentryQuartzBuilderExtensions.cs 62.50% 3 Missing ⚠️
src/Sentry.Quartz/QuartzApi.cs 88.23% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5505      +/-   ##
==========================================
+ Coverage   75.82%   76.12%   +0.30%     
==========================================
  Files         519      528       +9     
  Lines       19235    19579     +344     
  Branches     3741     3829      +88     
==========================================
+ Hits        14584    14904     +320     
- Misses       3781     3792      +11     
- Partials      870      883      +13     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread src/Sentry.Quartz/SentryCronJobOptions.cs Outdated
Comment thread src/Sentry.Quartz/Sentry.Quartz.csproj Outdated
The AddSentry() remarks still said job exceptions are left to the logging integration. The scope middleware has captured them again since 73e5551.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 6bb5320. Configure here.

Comment thread src/Sentry.Quartz/Core/JobMonitor.cs
Comment thread src/Sentry.Quartz/Core/JobMonitor.cs Outdated
@jamescrosswell
jamescrosswell self-requested a review October 20, 2026 00:41

@jamescrosswell jamescrosswell left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wedamija very close now - I think the cursor comment/finding is legit. I suggested we adopt the same approach we did for Hangfire.

Other than that, just one leftover comment from the old implementation to clean up and I think we're good to go.

@michaelmairegger

Copy link
Copy Markdown
Contributor Author

@wedamija very close now - I think the cursor comment/finding is legit. I suggested we adopt the same approach we did for Hangfire.

Other than that, just one leftover comment from the old implementation to clean up and I think we're good to go.

Nice, that we are close to finish. And I am glad my contribution will find its path to final release

A job without an identity has fallen back to its class name with a debug message, not a warning, since fe97276.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jamescrosswell

Copy link
Copy Markdown
Collaborator

Looks good but currently blocked by this (nothing to do with you):

@wedamija @ric-oliv could I get one of you to approve the above?

Picks up getsentry#5757, which fixes the Blazor WASM E2E job on Ubuntu 26.04 runners.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread src/Sentry.Quartz/Core/JobMonitor.cs Outdated
Comment thread test/Sentry.Quartz.Tests/SentryQuartzBuilderExtensionsTests.cs
Comment thread src/Sentry.Quartz/SentryScopeMiddleware.cs
Comment thread samples/Sentry.Samples.Quartz/Program.cs Outdated
@ric-oliv

Copy link
Copy Markdown
Member

Sorry for adding comments so late here @wedamija and @jamescrosswell!
Please feel free to push this back to a future improvement issue if you prefer 🙏

wedamija and others added 5 commits October 21, 2026 09:22
…gers

A job left in a persistent store after its class was renamed or deleted
made the whole trigger read throw, so no monitored job sent its schedule.

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
…aptured

Co-Authored-By: Claude <noreply@anthropic.com>
…tion on

Quartz's ErrorLogger logs the exception again, wrapped in a
JobExecutionProcessException that the default DeduplicateMode doesn't
unwrap. AddSentry now adds a log entry filter for that entry, to
whichever SentryLoggingOptions the app uses (SentryAspNetCoreOptions
included), when the middleware captured the inner exception.

Co-Authored-By: Claude <noreply@anthropic.com>

@ric-oliv ric-oliv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last suggestion from my side 🙏

Comment thread src/Sentry.Quartz/QuartzErrorLogFilterSetup.cs Outdated
wedamija and others added 2 commits October 21, 2026 11:00
Co-authored-by: Ricardo Colombo Oliveira <github@ricoliv.com>
…log filter setup

Co-Authored-By: Claude <noreply@anthropic.com>
@jamescrosswell
jamescrosswell self-requested a review October 21, 2026 21:48

@jamescrosswell jamescrosswell left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huge thanks to @michaelmairegger @wedamija and @ric-oliv for getting this over the line!
❤️

@jamescrosswell
jamescrosswell merged commit 04cac0d into getsentry:main Oct 21, 2026
63 of 64 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: high PR risk score: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Quartz.NET like Sentry.Hangfire

4 participants