Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sentry_sdk/integrations/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,6 @@ def _can_record(self, record: "LogRecord") -> bool:

def emit(self, record: "LogRecord") -> "Any":
with capture_internal_exceptions():
self.format(record)
if not self._can_record(record):
return

Expand All @@ -420,6 +419,7 @@ def emit(self, record: "LogRecord") -> "Any":
if not should_capture_logs:
return

self.format(record)
self._capture_log_from_record(client, record)

def _capture_log_from_record(
Expand Down
18 changes: 18 additions & 0 deletions tests/integrations/logging/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from sentry_sdk.consts import VERSION
from sentry_sdk.integrations.logging import (
LoggingIntegration,
SentryLogsHandler,
ignore_logger,
ignore_logger_for_sentry_logs,
unignore_logger,
Expand Down Expand Up @@ -244,6 +245,23 @@ def test_sentry_logs_collection_off_by_default(sentry_init, capture_items, reque
assert not items


def test_sentry_logs_handler_skips_format_when_disabled(sentry_init):
sentry_init(integrations=[LoggingIntegration(capture_sentry_logs=False)])
handler = SentryLogsHandler()
record = logging.LogRecord(
name="test-logger",
level=logging.INFO,
pathname=__file__,
lineno=1,
msg="hello %s",
args=("world",),
exc_info=None,
)
with mock.patch.object(handler, "format") as formatted:
handler.emit(record)
formatted.assert_not_called()


def test_sentry_logs_collection_opt_in(sentry_init, capture_items, request):
"""Automatic logs capture by Sentry logs needs explicit opt-in via capture_sentry_logs."""
sentry_init(integrations=[LoggingIntegration(capture_sentry_logs=True)])
Expand Down
Loading