Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the case that catches the regression

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