Skip to content

Commit 68c4d10

Browse files
fix(crons): Do not send monitor_config when unset (#2058)
1 parent e881f67 commit 68c4d10

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

sentry_sdk/crons/api.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ def _create_check_in_event(
2222
check_in = {
2323
"type": "check_in",
2424
"monitor_slug": monitor_slug,
25-
"monitor_config": monitor_config or {},
2625
"check_in_id": check_in_id,
2726
"status": status,
2827
"duration": duration_s,
2928
"environment": options.get("environment", None),
3029
"release": options.get("release", None),
3130
}
3231

32+
if monitor_config:
33+
check_in["monitor_config"] = monitor_config
34+
3335
return check_in
3436

3537

tests/test_crons.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,46 @@ def test_capture_checkin_new_id(sentry_init):
9090
)
9191

9292
assert check_in_id == "a8098c1af86e11dabd1a00112444be1e"
93+
94+
95+
def test_end_to_end(sentry_init, capture_envelopes):
96+
sentry_init()
97+
envelopes = capture_envelopes()
98+
99+
capture_checkin(
100+
monitor_slug="abc123",
101+
check_in_id="112233",
102+
duration=123,
103+
status="ok",
104+
)
105+
106+
check_in = envelopes[0].items[0].payload.json
107+
108+
# Check for final checkin
109+
assert check_in["check_in_id"] == "112233"
110+
assert check_in["monitor_slug"] == "abc123"
111+
assert check_in["status"] == "ok"
112+
assert check_in["duration"] == 123
113+
114+
115+
def test_monitor_config(sentry_init, capture_envelopes):
116+
sentry_init()
117+
envelopes = capture_envelopes()
118+
119+
monitor_config = {
120+
"schedule": {"type": "crontab", "value": "0 0 * * *"},
121+
}
122+
123+
capture_checkin(monitor_slug="abc123", monitor_config=monitor_config)
124+
check_in = envelopes[0].items[0].payload.json
125+
126+
# Check for final checkin
127+
assert check_in["monitor_slug"] == "abc123"
128+
assert check_in["monitor_config"] == monitor_config
129+
130+
# Without passing a monitor_config the field is not in the checkin
131+
capture_checkin(monitor_slug="abc123")
132+
check_in = envelopes[1].items[0].payload.json
133+
134+
assert check_in["monitor_slug"] == "abc123"
135+
assert "monitor_config" not in check_in

0 commit comments

Comments
 (0)