|
1 | 1 | import logging |
2 | 2 | import sys |
| 3 | +import threading |
3 | 4 | from datetime import datetime, timezone |
4 | 5 | from fnmatch import fnmatch |
5 | 6 |
|
@@ -321,20 +322,29 @@ class SentryLogsHandler(_BaseHandler): |
321 | 322 | Note that you do not have to use this class if the logging integration is enabled, which it is by default. |
322 | 323 | """ |
323 | 324 |
|
| 325 | + _emitting = threading.local() |
| 326 | + |
324 | 327 | def emit(self, record: "LogRecord") -> "Any": |
325 | | - with capture_internal_exceptions(): |
326 | | - self.format(record) |
327 | | - if not self._can_record(record): |
328 | | - return |
| 328 | + if getattr(self._emitting, "active", False): |
| 329 | + return |
| 330 | + |
| 331 | + self._emitting.active = True |
| 332 | + try: |
| 333 | + with capture_internal_exceptions(): |
| 334 | + self.format(record) |
| 335 | + if not self._can_record(record): |
| 336 | + return |
329 | 337 |
|
330 | | - client = sentry_sdk.get_client() |
331 | | - if not client.is_active(): |
332 | | - return |
| 338 | + client = sentry_sdk.get_client() |
| 339 | + if not client.is_active(): |
| 340 | + return |
333 | 341 |
|
334 | | - if not has_logs_enabled(client.options): |
335 | | - return |
| 342 | + if not has_logs_enabled(client.options): |
| 343 | + return |
336 | 344 |
|
337 | | - self._capture_log_from_record(client, record) |
| 345 | + self._capture_log_from_record(client, record) |
| 346 | + finally: |
| 347 | + self._emitting.active = False |
338 | 348 |
|
339 | 349 | def _capture_log_from_record( |
340 | 350 | self, client: "BaseClient", record: "LogRecord" |
|
0 commit comments