Skip to content

feat(hangfire): Add an option to monitor all recurring jobs - #5742

Open
wedamija wants to merge 15 commits into
mainfrom
danf/hangfire-bulk-cron
Open

wedamija wants to merge 15 commits into
mainfrom
danf/hangfire-bulk-cron

Conversation

@wedamija

@wedamija wedamija commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

Part of a series adding automatic Crons monitoring for the most-used job schedulers in each SDK. Check-ins for a monitor that doesn't exist yet are dropped, so today each monitor has to be created by hand with its schedule copied from the code. Sending the job's schedule as the monitor config lets Sentry create the monitor and keep it in sync.

This adds MonitorAllRecurringJobs, which sends check-ins for every recurring job without adding [SentryMonitorSlug] to each one. The monitor slug comes from the recurring job ID, and ExcludedRecurringJobs leaves out jobs by exact ID. Jobs with [SentryMonitorSlug] keep their slug. Off by default.

GlobalConfiguration.Configuration.UseSentry(options =>
{
    options.MonitorAllRecurringJobs = true;
    options.ExcludedRecurringJobs.Add("cache-warmup");
});

Schedules that can't be converted, and recurring jobs whose IDs map to the same slug with different schedules, check in without a config. Jobs that aren't recurring (BackgroundJob.Enqueue) still need the attribute.

Closes #5761

wedamija and others added 10 commits October 2, 2026 12:44
Opt-in via UseSentry(o => o.SendRecurringJobSchedule = true). The
in-progress check-in of a recurring job carries the job's cron and time
zone so Sentry can create the monitor. Unsupported schedules fall back
to a check-in without config.

Co-Authored-By: Claude <noreply@anthropic.com>
Check the crontab up front so the check-in goes out in a single call
instead of relying on the hub to swallow an exception from Interval.
The validator is shared with Sentry.Hangfire as a linked source file,
since the unsigned assembly can't see Sentry's internals.

Read the job through GetRecurringJobs, look up time zones with
FindSystemTimeZoneById on .NET 6+, and add tests for UTC, unknown
zones, deleted jobs, the UseSentry overload, and a real recurring job.

Co-Authored-By: Claude <noreply@anthropic.com>
The linux-musl CI containers have no time zone database, so lookups
of Europe/Berlin and Etc/UTC fail there.

Co-Authored-By: Claude <noreply@anthropic.com>
Hangfire runs a job only on days that match both the day-of-month and
day-of-week fields, while Sentry runs it on days that match either
unless one of them starts with '*'. Don't send those schedules, nor
ones with a reversed range such as 5-1 or SAT-SUN, which Sentry
rejects.

Co-Authored-By: Claude <noreply@anthropic.com>
Jobs are only monitored when they have [SentryMonitorSlug], so sending
the recurring job's schedule lets Sentry create or update the monitor,
like the Spring and Quartz integrations. Set SendRecurringJobSchedule
to false to keep managing the schedule in Sentry.

Co-Authored-By: Claude <noreply@anthropic.com>
The final check-in reused the ID returned for the in-progress one, which
is empty when that one isn't captured. Create the ID up front, send it
with the in-progress check-in, and store it in the job's items as before.

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

Co-Authored-By: Claude <noreply@anthropic.com>
…n cached schedule

Co-Authored-By: Claude <noreply@anthropic.com>
MonitorAllRecurringJobs sends check-ins for recurring jobs without
SentryMonitorSlugAttribute, using the slugified recurring job ID as the
monitor slug. ExcludedRecurringJobs leaves out recurring jobs by ID.

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

codecov Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.23529% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.14%. Comparing base (04cac0d) to head (08591be).

Files with missing lines Patch % Lines
src/Sentry.Hangfire/SentryServerFilter.cs 80.00% 3 Missing ⚠️
src/Sentry/Internal/MonitorSlug.cs 86.36% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5742      +/-   ##
==========================================
+ Coverage   76.13%   76.14%   +0.01%     
==========================================
  Files         528      529       +1     
  Lines       19579    19612      +33     
  Branches     3829     3837       +8     
==========================================
+ Hits        14906    14934      +28     
- Misses       3791     3797       +6     
+ Partials      882      881       -1     

☔ 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.

Base automatically changed from danf/hangfire-cron-config to main October 19, 2026 04:35
…on-merge

# Conflicts:
#	src/Sentry.Hangfire/GlobalConfigurationExtensions.cs
#	src/Sentry.Hangfire/SentryHangfireOptions.cs
#	test/Sentry.Hangfire.Tests/HangfireTests.cs
#	test/Sentry.Hangfire.Tests/ServerFilterTests.cs
@wedamija wedamija changed the title feat(hangfire): Add an option to monitor every recurring job feat(hangfire): Add an option to monitor all recurring jobs Oct 20, 2026
@wedamija
wedamija marked this pull request as ready for review October 20, 2026 17:25
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Oct 20, 2026
Collapse runs of hyphens and trim underscores, so IDs that Sentry would
store under the same slug also share one here and the conflicting
schedule check sees them.

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

linear-code Bot commented Oct 21, 2026

Copy link
Copy Markdown

NET-880

Comment thread src/Sentry.Hangfire/SentryHangfireOptions.cs Outdated
Comment thread src/Sentry.Hangfire/SentryHangfireOptions.cs

@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 generally looks good. I made a couple of suggestions that I think are worth implementing though.

…ecurringJobs

Adds a public StringOrRegex.Regex, since Sentry.Hangfire isn't strong-named
and can't see Sentry's internals.

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added risk: high PR risk score: high and removed risk: medium PR risk score: medium labels Oct 21, 2026
wedamija and others added 2 commits October 21, 2026 16:03
…nd Quartz

Quartz now joins a job's group and name with a hyphen, since Relay drops dots.

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

This branch has not been deployed

No deployments
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.

Crons: Hangfire option to monitor all recurring jobs

2 participants