Skip to content

Commit eed56e1

Browse files
ref(crons): Add information to short-interval cron error message (#2246)
--------- Co-authored-by: Anton Pirker <[email protected]>
1 parent 5478df2 commit eed56e1

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

sentry_sdk/integrations/celery.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,8 @@ def _get_humanized_interval(seconds):
395395
return (int(seconds), "second")
396396

397397

398-
def _get_monitor_config(celery_schedule, app):
399-
# type: (Any, Celery) -> Dict[str, Any]
398+
def _get_monitor_config(celery_schedule, app, monitor_name):
399+
# type: (Any, Celery, str) -> Dict[str, Any]
400400
monitor_config = {} # type: Dict[str, Any]
401401
schedule_type = None # type: Optional[str]
402402
schedule_value = None # type: Optional[Union[str, int]]
@@ -419,7 +419,9 @@ def _get_monitor_config(celery_schedule, app):
419419

420420
if schedule_unit == "second":
421421
logger.warning(
422-
"Intervals shorter than one minute are not supported by Sentry Crons."
422+
"Intervals shorter than one minute are not supported by Sentry Crons. Monitor '%s' has an interval of %s seconds. Use the `exclude_beat_tasks` option in the celery integration to exclude it.",
423+
monitor_name,
424+
schedule_value,
423425
)
424426
return {}
425427

@@ -466,7 +468,7 @@ def sentry_apply_entry(*args, **kwargs):
466468
# When tasks are started from Celery Beat, make sure each task has its own trace.
467469
scope.set_new_propagation_context()
468470

469-
monitor_config = _get_monitor_config(celery_schedule, app)
471+
monitor_config = _get_monitor_config(celery_schedule, app, monitor_name)
470472

471473
is_supported_schedule = bool(monitor_config)
472474
if is_supported_schedule:

tests/integrations/celery/test_celery_beat_crons.py

+15-6
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ def test_get_monitor_config_crontab():
213213
app.conf.timezone = "Europe/Vienna"
214214

215215
celery_schedule = crontab(day_of_month="3", hour="12", minute="*/10")
216-
monitor_config = _get_monitor_config(celery_schedule, app)
216+
monitor_config = _get_monitor_config(celery_schedule, app, "foo")
217217
assert monitor_config == {
218218
"schedule": {
219219
"type": "crontab",
@@ -230,8 +230,17 @@ def test_get_monitor_config_seconds():
230230
app.conf.timezone = "Europe/Vienna"
231231

232232
celery_schedule = schedule(run_every=3) # seconds
233-
monitor_config = _get_monitor_config(celery_schedule, app)
234-
assert monitor_config == {}
233+
234+
with mock.patch(
235+
"sentry_sdk.integrations.celery.logger.warning"
236+
) as mock_logger_warning:
237+
monitor_config = _get_monitor_config(celery_schedule, app, "foo")
238+
mock_logger_warning.assert_called_with(
239+
"Intervals shorter than one minute are not supported by Sentry Crons. Monitor '%s' has an interval of %s seconds. Use the `exclude_beat_tasks` option in the celery integration to exclude it.",
240+
"foo",
241+
3,
242+
)
243+
assert monitor_config == {}
235244

236245

237246
def test_get_monitor_config_minutes():
@@ -240,7 +249,7 @@ def test_get_monitor_config_minutes():
240249
app.conf.timezone = "Europe/Vienna"
241250

242251
celery_schedule = schedule(run_every=60) # seconds
243-
monitor_config = _get_monitor_config(celery_schedule, app)
252+
monitor_config = _get_monitor_config(celery_schedule, app, "foo")
244253
assert monitor_config == {
245254
"schedule": {
246255
"type": "interval",
@@ -257,7 +266,7 @@ def test_get_monitor_config_unknown():
257266
app.conf.timezone = "Europe/Vienna"
258267

259268
unknown_celery_schedule = MagicMock()
260-
monitor_config = _get_monitor_config(unknown_celery_schedule, app)
269+
monitor_config = _get_monitor_config(unknown_celery_schedule, app, "foo")
261270
assert monitor_config == {}
262271

263272

@@ -268,7 +277,7 @@ def test_get_monitor_config_default_timezone():
268277

269278
celery_schedule = crontab(day_of_month="3", hour="12", minute="*/10")
270279

271-
monitor_config = _get_monitor_config(celery_schedule, app)
280+
monitor_config = _get_monitor_config(celery_schedule, app, "foo")
272281

273282
assert monitor_config["timezone"] == "UTC"
274283

0 commit comments

Comments
 (0)