Skip to content

Commit

Permalink
fix(crons): Do not send monitor_config when unset (#2058)
Browse files Browse the repository at this point in the history
  • Loading branch information
evanpurkhiser authored Apr 28, 2023
1 parent e881f67 commit 68c4d10
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
4 changes: 3 additions & 1 deletion sentry_sdk/crons/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ 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,
"environment": options.get("environment", None),
"release": options.get("release", None),
}

if monitor_config:
check_in["monitor_config"] = monitor_config

return check_in


Expand Down
43 changes: 43 additions & 0 deletions tests/test_crons.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 68c4d10

Please sign in to comment.