Skip to content

Feature/sentry.quartz (Quartz v4 Alpha version) - #5505

Open
michaelmairegger wants to merge 10 commits into
getsentry:mainfrom
michaelmairegger:feature/sentry.quartz
Open

Feature/sentry.quartz (Quartz v4 Alpha version)#5505
michaelmairegger wants to merge 10 commits into
getsentry:mainfrom
michaelmairegger:feature/sentry.quartz

Conversation

@michaelmairegger

@michaelmairegger michaelmairegger commented Aug 24, 2026

Copy link
Copy Markdown

This PR implements and showcases Quartz.Net integration for Sentry

Note: Quartz.Net v4 is still alpha, therefore we should wait until v4 is finally released.

fixes #4601

@github-actions github-actions Bot added the risk: high PR risk score: high label Aug 24, 2026

@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 5 potential issues.

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 625b3e8. Configure here.

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 on lines +19 to +22
quartz.UseSentry(builder.Services, options =>
{
var jobKey1 = new JobKey(nameof(FirstJob));
quartz.AddJob<FirstJob>(opts => opts.WithIdentity(jobKey1));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Job registrations are placed inside the UseSentry options lambda, which executes too late, causing jobs to never be scheduled.
Severity: HIGH

Suggested Fix

Move the job and trigger registration calls, such as quartz.AddJob<FirstJob>(...), outside of the options => { ... } lambda and place them directly within the builder.Services.AddQuartz(quartz => { ... }) configuration block.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: samples/Sentry.Samples.Quartz/Program.cs#L19-L22

Potential issue: In `Program.cs`, the calls to `quartz.AddJob<...>` and
`quartz.AddTrigger<...>` are located within the options configuration lambda passed to
`quartz.UseSentry()`. This lambda is registered via `serviceCollection.Configure()` and
is only executed during DI options resolution, which happens after the Quartz
configuration phase has already finished. As a result, the jobs are never registered
with the Quartz scheduler, leading to a silent failure where the application runs but
the scheduled jobs never execute.

Comment on lines +48 to +52

if (_sentryCronInformation.TryGetValue(jobType, out var info) && info.ShouldWriteStatusToSentry)
{
var status = jobException is not null ? CheckInStatus.Error : CheckInStatus.Ok;
_fireInstanceId.TryRemove(context.FireInstanceId, out var checkInId);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: A race condition on the WarningShownForSecondsParameterIssue flag can cause a warning to be logged multiple times during concurrent job executions.
Severity: LOW

Suggested Fix

Use a lock statement around the read and write operations on the WarningShownForSecondsParameterIssue flag to ensure the check-and-set operation is atomic and thread-safe.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: src/Sentry.Quartz/SentryCronJobListener.cs#L48-L52

Potential issue: The `UpsertCronMonitor` method in `SentryCronJobListener` contains a
race condition. The check and subsequent update of the
`information.WarningShownForSecondsParameterIssue` flag is not an atomic operation. If
multiple instances of the same job type execute concurrently, it's possible for multiple
threads to read the flag as `false` simultaneously, leading to the warning being logged
multiple times instead of just once as intended.

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

1 participant