Skip to content

fix(logging): Send raw logging parameters #4291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2025
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
6 changes: 1 addition & 5 deletions sentry_sdk/integrations/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,11 +265,7 @@ def _emit(self, record):
else:
event["logentry"] = {
"message": to_string(record.msg),
"params": (
tuple(str(arg) if arg is None else arg for arg in record.args)
if record.args
else ()
),
"params": record.args,
}

event["extra"] = self._extra_from_record(record)
Expand Down
30 changes: 30 additions & 0 deletions tests/integrations/logging/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,33 @@ def test_ignore_logger_wildcard(sentry_init, capture_events):

(event,) = events
assert event["logentry"]["message"] == "hi"


def test_logging_dictionary_interpolation(sentry_init, capture_events):
"""Here we test an entire dictionary being interpolated into the log message."""
sentry_init(integrations=[LoggingIntegration()], default_integrations=False)
events = capture_events()

logger.error("this is a log with a dictionary %s", {"foo": "bar"})

(event,) = events
assert event["logentry"]["message"] == "this is a log with a dictionary %s"
assert event["logentry"]["params"] == {"foo": "bar"}


def test_logging_dictionary_args(sentry_init, capture_events):
"""Here we test items from a dictionary being interpolated into the log message."""
sentry_init(integrations=[LoggingIntegration()], default_integrations=False)
events = capture_events()

logger.error(
"the value of foo is %(foo)s, and the value of bar is %(bar)s",
{"foo": "bar", "bar": "baz"},
)

(event,) = events
assert (
event["logentry"]["message"]
== "the value of foo is %(foo)s, and the value of bar is %(bar)s"
)
assert event["logentry"]["params"] == {"foo": "bar", "bar": "baz"}
Loading