Skip to content

Observability: Sentry Cron #780

Merged
AkhileshNegi merged 6 commits intomainfrom
enhancement/cron-observability
Apr 24, 2026
Merged

Observability: Sentry Cron #780
AkhileshNegi merged 6 commits intomainfrom
enhancement/cron-observability

Conversation

@AkhileshNegi
Copy link
Copy Markdown
Collaborator

@AkhileshNegi AkhileshNegi commented Apr 22, 2026

Summary

Target issue is #776

Description

  • Enhanced monitoring for scheduled evaluation tasks to capture failures and performance data.
  • Improved error handling so exceptions during cron execution are recorded by monitoring and surfaced for investigation.
  • Added a new configurable setting to adjust cron execution intervals (default: 5 minutes).

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 22, 2026

📝 Walkthrough

Walkthrough

Sentry monitoring was added to the evaluation cron endpoint and a new CRON_INTERVAL_MINUTES setting (default 5) was introduced. Exceptions in the cron handler are now captured with Sentry and re-raised instead of returning a structured error response.

Changes

Cohort / File(s) Summary
Configuration Settings
backend/app/core/config.py
Added CRON_INTERVAL_MINUTES: int = 5 to Settings for configurable cron intervals.
Sentry Cron Monitoring
backend/app/api/routes/cron.py
Imported sentry_sdk and MonitorConfig, added EVALUATION_CRON_MONITOR_CONFIG, applied @sentry_sdk.monitor(...) to evaluation_cron_job, and changed error handling to call sentry_sdk.capture_exception() then re-raise exceptions (removed previous structured error response).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A cron job hops through the night,
Sentry watches with gentle sight,
When errors tumble, they’re caught and shared,
Then raised again—no longer scared,
Five-minute beats keep everything light.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Observability: Sentry Cron' directly and specifically summarizes the main changes, which add Sentry cron monitoring to the evaluation job endpoint.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch enhancement/cron-observability

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@AkhileshNegi AkhileshNegi self-assigned this Apr 22, 2026
@AkhileshNegi AkhileshNegi added the enhancement New feature or request label Apr 22, 2026
@AkhileshNegi AkhileshNegi marked this pull request as ready for review April 22, 2026 05:26
@AkhileshNegi AkhileshNegi requested a review from vprashrex April 22, 2026 05:26
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@backend/app/core/config.py`:
- Around line 159-163: Add a lower-bound validator to CRON_INTERVAL_MINUTES so
zero/negative values are rejected: change the declaration of
CRON_INTERVAL_MINUTES in config.py to use Pydantic Field with default=5 and ge=1
(i.e., Field(default=5, ge=1)) and add the required import for Field from
pydantic at the top of the file; update any type hints that reference
CRON_INTERVAL_MINUTES if necessary to keep it as int.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 731b3b13-b9db-462f-bc48-fb11acc7ffe7

📥 Commits

Reviewing files that changed from the base of the PR and between d7b3359 and 1715ed0.

📒 Files selected for processing (2)
  • backend/app/api/routes/cron.py
  • backend/app/core/config.py

Comment on lines +159 to +163
# Evaluation cron invocation interval (minutes). In staging/production the
# endpoint is triggered by AWS EventBridge on this cadence; locally it can
# be driven by scripts/python/invoke-cron.py. The Sentry cron monitor reads
# this same value so its expected schedule stays aligned with the trigger.
CRON_INTERVAL_MINUTES: int = 5
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🌐 Web query:

What are the valid value constraints for Sentry Python SDK crons MonitorConfig interval schedules with type interval value unit minute?

💡 Result:

For Sentry Python SDK crons MonitorConfig with schedule type "interval", unit "minute", the "value" is a positive integer representing the number of minutes between executions. No explicit upper or lower bounds are documented in official sources, but practical constraints apply: Sentry limits check-ins to 6 per minute per monitor environment, implying a minimum practical value of 10 minutes (to allow for checkin_margin). Examples use values like 3 or 10 minutes. The value must be a non-negative integer (likely >0), as indicated by type definitions and SDK code references.

Citations:


🏁 Script executed:

# Find usage of CRON_INTERVAL_MINUTES
rg "CRON_INTERVAL_MINUTES" --type py -B 2 -A 2

Repository: ProjectTech4DevAI/kaapi-backend

Length of output: 1774


🏁 Script executed:

# Check the config file for imports and current validation patterns
head -50 backend/app/core/config.py

Repository: ProjectTech4DevAI/kaapi-backend

Length of output: 1586


🏁 Script executed:

# Check if Field is already imported in config.py
rg "from pydantic import" backend/app/core/config.py -A 10

Repository: ProjectTech4DevAI/kaapi-backend

Length of output: 322


Add lower bound validation to CRON_INTERVAL_MINUTES to prevent invalid Sentry monitor config.

CRON_INTERVAL_MINUTES is environment-overridable but currently accepts any integer value. Setting it to 0 or negative values would create invalid Sentry monitor schedule configuration (used as interval "value" and in "max_runtime" calculation). Sentry requires positive interval values.

Apply Field(default=5, ge=1) with the necessary import addition.

Suggested fix
 from pydantic import (
     EmailStr,
+    Field,
     HttpUrl,
     PostgresDsn,
     computed_field,
     model_validator,
 )
@@
-    CRON_INTERVAL_MINUTES: int = 5
+    CRON_INTERVAL_MINUTES: int = Field(default=5, ge=1)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Evaluation cron invocation interval (minutes). In staging/production the
# endpoint is triggered by AWS EventBridge on this cadence; locally it can
# be driven by scripts/python/invoke-cron.py. The Sentry cron monitor reads
# this same value so its expected schedule stays aligned with the trigger.
CRON_INTERVAL_MINUTES: int = 5
# Evaluation cron invocation interval (minutes). In staging/production the
# endpoint is triggered by AWS EventBridge on this cadence; locally it can
# be driven by scripts/python/invoke-cron.py. The Sentry cron monitor reads
# this same value so its expected schedule stays aligned with the trigger.
CRON_INTERVAL_MINUTES: int = Field(default=5, ge=1)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@backend/app/core/config.py` around lines 159 - 163, Add a lower-bound
validator to CRON_INTERVAL_MINUTES so zero/negative values are rejected: change
the declaration of CRON_INTERVAL_MINUTES in config.py to use Pydantic Field with
default=5 and ge=1 (i.e., Field(default=5, ge=1)) and add the required import
for Field from pydantic at the top of the file; update any type hints that
reference CRON_INTERVAL_MINUTES if necessary to keep it as int.

@AkhileshNegi AkhileshNegi merged commit 18bef6b into main Apr 24, 2026
2 checks passed
@AkhileshNegi AkhileshNegi deleted the enhancement/cron-observability branch April 24, 2026 01:51
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 24, 2026

Codecov Report

❌ Patch coverage is 75.00000% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
backend/app/api/routes/cron.py 71.42% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@AkhileshNegi AkhileshNegi linked an issue Apr 28, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Integration: Monitor scheduled jobs in Sentry

2 participants