Skip to content

Commit bb3648b

Browse files
committed
fix(logging): Fix deadlock in log batcher
1 parent 6ea663f commit bb3648b

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

sentry_sdk/integrations/logging.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
import sys
3+
import threading
34
from datetime import datetime, timezone
45
from fnmatch import fnmatch
56

@@ -321,20 +322,29 @@ class SentryLogsHandler(_BaseHandler):
321322
Note that you do not have to use this class if the logging integration is enabled, which it is by default.
322323
"""
323324

325+
_emitting = threading.local()
326+
324327
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
329337

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
333341

334-
if not has_logs_enabled(client.options):
335-
return
342+
if not has_logs_enabled(client.options):
343+
return
336344

337-
self._capture_log_from_record(client, record)
345+
self._capture_log_from_record(client, record)
346+
finally:
347+
self._emitting.active = False
338348

339349
def _capture_log_from_record(
340350
self, client: "BaseClient", record: "LogRecord"

0 commit comments

Comments
 (0)