@@ -33,6 +33,22 @@ def _break_world_contextmanager(name):
33
33
return "Hello, {}" .format (name )
34
34
35
35
36
+ @sentry_sdk .monitor (monitor_slug = "ghi789" , monitor_config = None )
37
+ def _no_monitor_config ():
38
+ return
39
+
40
+
41
+ @sentry_sdk .monitor (
42
+ monitor_slug = "ghi789" ,
43
+ monitor_config = {
44
+ "schedule" : {"type" : "crontab" , "value" : "0 0 * * *" },
45
+ "failure_issue_threshold" : 5 ,
46
+ },
47
+ )
48
+ def _with_monitor_config ():
49
+ return
50
+
51
+
36
52
def test_decorator (sentry_init ):
37
53
sentry_init ()
38
54
@@ -45,7 +61,9 @@ def test_decorator(sentry_init):
45
61
# Check for initial checkin
46
62
fake_capture_checkin .assert_has_calls (
47
63
[
48
- mock .call (monitor_slug = "abc123" , status = "in_progress" ),
64
+ mock .call (
65
+ monitor_slug = "abc123" , status = "in_progress" , monitor_config = None
66
+ ),
49
67
]
50
68
)
51
69
@@ -70,7 +88,9 @@ def test_decorator_error(sentry_init):
70
88
# Check for initial checkin
71
89
fake_capture_checkin .assert_has_calls (
72
90
[
73
- mock .call (monitor_slug = "def456" , status = "in_progress" ),
91
+ mock .call (
92
+ monitor_slug = "def456" , status = "in_progress" , monitor_config = None
93
+ ),
74
94
]
75
95
)
76
96
@@ -93,7 +113,9 @@ def test_contextmanager(sentry_init):
93
113
# Check for initial checkin
94
114
fake_capture_checkin .assert_has_calls (
95
115
[
96
- mock .call (monitor_slug = "abc123" , status = "in_progress" ),
116
+ mock .call (
117
+ monitor_slug = "abc123" , status = "in_progress" , monitor_config = None
118
+ ),
97
119
]
98
120
)
99
121
@@ -118,7 +140,9 @@ def test_contextmanager_error(sentry_init):
118
140
# Check for initial checkin
119
141
fake_capture_checkin .assert_has_calls (
120
142
[
121
- mock .call (monitor_slug = "def456" , status = "in_progress" ),
143
+ mock .call (
144
+ monitor_slug = "def456" , status = "in_progress" , monitor_config = None
145
+ ),
122
146
]
123
147
)
124
148
@@ -194,6 +218,8 @@ def test_monitor_config(sentry_init, capture_envelopes):
194
218
195
219
monitor_config = {
196
220
"schedule" : {"type" : "crontab" , "value" : "0 0 * * *" },
221
+ "failure_issue_threshold" : 5 ,
222
+ "recovery_threshold" : 5 ,
197
223
}
198
224
199
225
capture_checkin (monitor_slug = "abc123" , monitor_config = monitor_config )
@@ -211,6 +237,41 @@ def test_monitor_config(sentry_init, capture_envelopes):
211
237
assert "monitor_config" not in check_in
212
238
213
239
240
+ def test_decorator_monitor_config (sentry_init , capture_envelopes ):
241
+ sentry_init ()
242
+ envelopes = capture_envelopes ()
243
+
244
+ _with_monitor_config ()
245
+
246
+ assert len (envelopes ) == 2
247
+
248
+ for check_in_envelope in envelopes :
249
+ assert len (check_in_envelope .items ) == 1
250
+ check_in = check_in_envelope .items [0 ].payload .json
251
+
252
+ assert check_in ["monitor_slug" ] == "ghi789"
253
+ assert check_in ["monitor_config" ] == {
254
+ "schedule" : {"type" : "crontab" , "value" : "0 0 * * *" },
255
+ "failure_issue_threshold" : 5 ,
256
+ }
257
+
258
+
259
+ def test_decorator_no_monitor_config (sentry_init , capture_envelopes ):
260
+ sentry_init ()
261
+ envelopes = capture_envelopes ()
262
+
263
+ _no_monitor_config ()
264
+
265
+ assert len (envelopes ) == 2
266
+
267
+ for check_in_envelope in envelopes :
268
+ assert len (check_in_envelope .items ) == 1
269
+ check_in = check_in_envelope .items [0 ].payload .json
270
+
271
+ assert check_in ["monitor_slug" ] == "ghi789"
272
+ assert "monitor_config" not in check_in
273
+
274
+
214
275
def test_capture_checkin_sdk_not_initialized ():
215
276
# Tests that the capture_checkin does not raise an error when Sentry SDK is not initialized.
216
277
# sentry_init() is intentionally omitted.
0 commit comments