Skip to content

Commit 1f27ad4

Browse files
committed
Move health logic to transport
1 parent a8f4e92 commit 1f27ad4

File tree

3 files changed

+17
-24
lines changed

3 files changed

+17
-24
lines changed

sentry_sdk/monitor.py

+3-18
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,9 @@ def _thread():
5959
def run(self):
6060
# type: () -> None
6161
self.check_health()
62-
self._set_downsample_factor()
62+
self.set_downsample_factor()
6363

64-
def _is_transport_rate_limited(self):
65-
# type: () -> bool
66-
if self.transport and hasattr(self.transport, "is_rate_limited"):
67-
return self.transport.is_rate_limited()
68-
return False
69-
70-
def _is_transport_worker_full(self):
71-
# type: () -> bool
72-
if self.transport and hasattr(self.transport, "is_worker_full"):
73-
return self.transport.is_worker_full()
74-
return False
75-
76-
def _set_downsample_factor(self):
64+
def set_downsample_factor(self):
7765
# type: () -> None
7866
if self._healthy:
7967
if self._downsample_factor > 1:
@@ -95,10 +83,7 @@ def check_health(self):
9583
currently only checks if the transport is rate-limited.
9684
TODO: augment in the future with more checks.
9785
"""
98-
if self._is_transport_worker_full() or self._is_transport_rate_limited():
99-
self._healthy = False
100-
else:
101-
self._healthy = True
86+
self._healthy = self.transport.is_healthy()
10287

10388
def is_healthy(self):
10489
# type: () -> bool

sentry_sdk/transport.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@ def record_lost_event(
107107
"""
108108
return None
109109

110+
def is_healthy(self):
111+
# type: () -> bool
112+
return True
113+
110114
def __del__(self):
111115
# type: () -> None
112116
try:
@@ -311,14 +315,18 @@ def _disabled(bucket):
311315

312316
return _disabled(category) or _disabled(None)
313317

314-
def is_rate_limited(self):
318+
def _is_rate_limited(self):
315319
# type: () -> bool
316320
return any(ts > datetime.utcnow() for ts in self._disabled_until.values())
317321

318-
def is_worker_full(self):
322+
def _is_worker_full(self):
319323
# type: () -> bool
320324
return self._worker.full()
321325

326+
def is_healthy(self):
327+
# type: () -> bool
328+
return not (self._is_worker_full() or self._is_rate_limited())
329+
322330
def _send_event(
323331
self, event # type: Event
324332
):

tests/test_monitor.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ def _send_event(self, event):
1111
def _send_envelope(self, envelope):
1212
pass
1313

14-
def is_worker_full(self):
15-
return False
14+
def is_healthy(self):
15+
return True
1616

1717

1818
class UnhealthyTestTransport(HealthyTestTransport):
19-
def is_worker_full(self):
20-
return True
19+
def is_healthy(self):
20+
return False
2121

2222

2323
def test_no_monitor_if_disabled(sentry_init):

0 commit comments

Comments
 (0)