From 68c4d104e2bcdfdb72447c212ee0a7d19e1ee9a3 Mon Sep 17 00:00:00 2001 From: Evan Purkhiser Date: Fri, 28 Apr 2023 12:06:14 -0700 Subject: [PATCH] fix(crons): Do not send monitor_config when unset (#2058) --- sentry_sdk/crons/api.py | 4 +++- tests/test_crons.py | 43 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/sentry_sdk/crons/api.py b/sentry_sdk/crons/api.py index 9e3d208c3d..cd240a7dcd 100644 --- a/sentry_sdk/crons/api.py +++ b/sentry_sdk/crons/api.py @@ -22,7 +22,6 @@ def _create_check_in_event( check_in = { "type": "check_in", "monitor_slug": monitor_slug, - "monitor_config": monitor_config or {}, "check_in_id": check_in_id, "status": status, "duration": duration_s, @@ -30,6 +29,9 @@ def _create_check_in_event( "release": options.get("release", None), } + if monitor_config: + check_in["monitor_config"] = monitor_config + return check_in diff --git a/tests/test_crons.py b/tests/test_crons.py index d79e79c57d..26adbb746b 100644 --- a/tests/test_crons.py +++ b/tests/test_crons.py @@ -90,3 +90,46 @@ def test_capture_checkin_new_id(sentry_init): ) assert check_in_id == "a8098c1af86e11dabd1a00112444be1e" + + +def test_end_to_end(sentry_init, capture_envelopes): + sentry_init() + envelopes = capture_envelopes() + + capture_checkin( + monitor_slug="abc123", + check_in_id="112233", + duration=123, + status="ok", + ) + + check_in = envelopes[0].items[0].payload.json + + # Check for final checkin + assert check_in["check_in_id"] == "112233" + assert check_in["monitor_slug"] == "abc123" + assert check_in["status"] == "ok" + assert check_in["duration"] == 123 + + +def test_monitor_config(sentry_init, capture_envelopes): + sentry_init() + envelopes = capture_envelopes() + + monitor_config = { + "schedule": {"type": "crontab", "value": "0 0 * * *"}, + } + + capture_checkin(monitor_slug="abc123", monitor_config=monitor_config) + check_in = envelopes[0].items[0].payload.json + + # Check for final checkin + assert check_in["monitor_slug"] == "abc123" + assert check_in["monitor_config"] == monitor_config + + # Without passing a monitor_config the field is not in the checkin + capture_checkin(monitor_slug="abc123") + check_in = envelopes[1].items[0].payload.json + + assert check_in["monitor_slug"] == "abc123" + assert "monitor_config" not in check_in