@@ -58,6 +58,22 @@ async def _break_world_contextmanager_async(name):
5858 return "Hello, {}" .format (name )
5959
6060
61+ @sentry_sdk .monitor (monitor_slug = "ghi789" , monitor_config = None )
62+ def _no_monitor_config ():
63+ return
64+
65+
66+ @sentry_sdk .monitor (
67+ monitor_slug = "ghi789" ,
68+ monitor_config = {
69+ "schedule" : {"type" : "crontab" , "value" : "0 0 * * *" },
70+ "failure_issue_threshold" : 5 ,
71+ },
72+ )
73+ def _with_monitor_config ():
74+ return
75+
76+
6177def test_decorator (sentry_init ):
6278 sentry_init ()
6379
@@ -70,7 +86,9 @@ def test_decorator(sentry_init):
7086 # Check for initial checkin
7187 fake_capture_checkin .assert_has_calls (
7288 [
73- mock .call (monitor_slug = "abc123" , status = "in_progress" ),
89+ mock .call (
90+ monitor_slug = "abc123" , status = "in_progress" , monitor_config = None
91+ ),
7492 ]
7593 )
7694
@@ -95,7 +113,9 @@ def test_decorator_error(sentry_init):
95113 # Check for initial checkin
96114 fake_capture_checkin .assert_has_calls (
97115 [
98- mock .call (monitor_slug = "def456" , status = "in_progress" ),
116+ mock .call (
117+ monitor_slug = "def456" , status = "in_progress" , monitor_config = None
118+ ),
99119 ]
100120 )
101121
@@ -118,7 +138,9 @@ def test_contextmanager(sentry_init):
118138 # Check for initial checkin
119139 fake_capture_checkin .assert_has_calls (
120140 [
121- mock .call (monitor_slug = "abc123" , status = "in_progress" ),
141+ mock .call (
142+ monitor_slug = "abc123" , status = "in_progress" , monitor_config = None
143+ ),
122144 ]
123145 )
124146
@@ -143,7 +165,9 @@ def test_contextmanager_error(sentry_init):
143165 # Check for initial checkin
144166 fake_capture_checkin .assert_has_calls (
145167 [
146- mock .call (monitor_slug = "def456" , status = "in_progress" ),
168+ mock .call (
169+ monitor_slug = "def456" , status = "in_progress" , monitor_config = None
170+ ),
147171 ]
148172 )
149173
@@ -219,6 +243,8 @@ def test_monitor_config(sentry_init, capture_envelopes):
219243
220244 monitor_config = {
221245 "schedule" : {"type" : "crontab" , "value" : "0 0 * * *" },
246+ "failure_issue_threshold" : 5 ,
247+ "recovery_threshold" : 5 ,
222248 }
223249
224250 capture_checkin (monitor_slug = "abc123" , monitor_config = monitor_config )
@@ -236,6 +262,41 @@ def test_monitor_config(sentry_init, capture_envelopes):
236262 assert "monitor_config" not in check_in
237263
238264
265+ def test_decorator_monitor_config (sentry_init , capture_envelopes ):
266+ sentry_init ()
267+ envelopes = capture_envelopes ()
268+
269+ _with_monitor_config ()
270+
271+ assert len (envelopes ) == 2
272+
273+ for check_in_envelope in envelopes :
274+ assert len (check_in_envelope .items ) == 1
275+ check_in = check_in_envelope .items [0 ].payload .json
276+
277+ assert check_in ["monitor_slug" ] == "ghi789"
278+ assert check_in ["monitor_config" ] == {
279+ "schedule" : {"type" : "crontab" , "value" : "0 0 * * *" },
280+ "failure_issue_threshold" : 5 ,
281+ }
282+
283+
284+ def test_decorator_no_monitor_config (sentry_init , capture_envelopes ):
285+ sentry_init ()
286+ envelopes = capture_envelopes ()
287+
288+ _no_monitor_config ()
289+
290+ assert len (envelopes ) == 2
291+
292+ for check_in_envelope in envelopes :
293+ assert len (check_in_envelope .items ) == 1
294+ check_in = check_in_envelope .items [0 ].payload .json
295+
296+ assert check_in ["monitor_slug" ] == "ghi789"
297+ assert "monitor_config" not in check_in
298+
299+
239300def test_capture_checkin_sdk_not_initialized ():
240301 # Tests that the capture_checkin does not raise an error when Sentry SDK is not initialized.
241302 # sentry_init() is intentionally omitted.
@@ -320,7 +381,9 @@ async def test_decorator_async(sentry_init):
320381 # Check for initial checkin
321382 fake_capture_checkin .assert_has_calls (
322383 [
323- mock .call (monitor_slug = "abc123" , status = "in_progress" ),
384+ mock .call (
385+ monitor_slug = "abc123" , status = "in_progress" , monitor_config = None
386+ ),
324387 ]
325388 )
326389
@@ -346,7 +409,9 @@ async def test_decorator_error_async(sentry_init):
346409 # Check for initial checkin
347410 fake_capture_checkin .assert_has_calls (
348411 [
349- mock .call (monitor_slug = "def456" , status = "in_progress" ),
412+ mock .call (
413+ monitor_slug = "def456" , status = "in_progress" , monitor_config = None
414+ ),
350415 ]
351416 )
352417
@@ -370,7 +435,9 @@ async def test_contextmanager_async(sentry_init):
370435 # Check for initial checkin
371436 fake_capture_checkin .assert_has_calls (
372437 [
373- mock .call (monitor_slug = "abc123" , status = "in_progress" ),
438+ mock .call (
439+ monitor_slug = "abc123" , status = "in_progress" , monitor_config = None
440+ ),
374441 ]
375442 )
376443
@@ -396,7 +463,9 @@ async def test_contextmanager_error_async(sentry_init):
396463 # Check for initial checkin
397464 fake_capture_checkin .assert_has_calls (
398465 [
399- mock .call (monitor_slug = "def456" , status = "in_progress" ),
466+ mock .call (
467+ monitor_slug = "def456" , status = "in_progress" , monitor_config = None
468+ ),
400469 ]
401470 )
402471
0 commit comments