feat(celery): allow custom monitor config for beat tasks - #7839
Draft
alexon1234 wants to merge 1 commit into
Draft
alexon1234 wants to merge 1 commit into
alexon1234 wants to merge 1 commit into
Conversation
Celery Beat auto-instrumentation derives the cron monitor config from the schedule only, so max_runtime, checkin_margin, failure_issue_threshold, recovery_threshold and owner cannot be set. Tasks whose runtime can exceed Sentry's default 30-minute max_runtime are then reported as timed-out cron failures even when they complete successfully. Add a `beat_task_monitor_config` option to CeleryIntegration that maps beat task names to partial monitor configs, merged over the derived config. Refs getsentry#7838
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Celery Beat auto-instrumentation (
CeleryIntegration(monitor_beat_tasks=True)) derives the cron monitor config from the schedule only (schedule+timezone), so there is no way to setmax_runtime,checkin_margin,failure_issue_threshold,recovery_threshold, orowneron the monitors the SDK creates.Consequence: a task that can legitimately run longer than Sentry's default 30-minute
max_runtimeis reported as a timed-out cron failure even though it completes successfully. The only workaround is to exclude it from auto-instrumentation and re-declare the schedule in a manual@sentry_sdk.monitor(..., monitor_config=...)call, which is awkward when the schedule differs per environment.This adds a
beat_task_monitor_configoption toCeleryIntegration: a mapping of Celery Beat task name to a partialMonitorConfigthat is merged over the config derived from the schedule.The SDK still derives
scheduleandtimezone; the override only needs the extra fields, and can still override the derived values if explicitly provided.Changes:
CeleryIntegration: newbeat_task_monitor_configoption._get_monitor_config: accepts and merges monitor config overrides._apply_crons_data_to_schedule_entry: looks up the override for the schedule entry and passes it through (covers both the default scheduler and RedBeat, which share this path).Issues
Reminders
uv run ruff.feat:,fix:,ref:,meta:)