8000 fix(logging): Send raw logging parameters · getsentry/sentry-python@e71ccbf · GitHub
[go: up one dir, main page]

Skip to content

Commit e71ccbf

Browse files
fix(logging): Send raw logging parameters
This reverts commit 4c9731b, adding tests to ensure the correct behavior going forward. That commit caused a regression when `record.args` contains a dictionary. Because we iterate over `record.args`, that change caused us to only send the dictionary's keys, not the values. A more robust fix for #3660 will be to send the formatted message in the [`formatted` field](https://develop.sentry.dev/sdk/data-model/event-payloads/message/) (which we have not been doing yet). I will open a follow-up PR to do this. Fixes #4267
1 parent a3d4b89 commit e71ccbf

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

sentry_sdk/integrations/logging.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,7 @@ def _emit(self, record):
265265
else:
266266
event["logentry"] = {
267267
"message": to_string(record.msg),
268-
"params": (
269-
tuple(str(arg) if arg is None else arg for arg in record.args)
270-
if record.args
271-
else ()
272-
),
268+
"params": record.args,
273269
}
274270

275271
event["extra"] = self._extra_from_record(record)

tests/integrations/logging/test_logging.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,33 @@ def test_ignore_logger_wildcard(sentry_init, capture_events):
234234

235235
(event,) = events
236236
assert event["logentry"]["message"] == "hi"
237+
238+
239+
def test_logging_dictionary_interpolation(sentry_init, capture_events):
240+
"""Here we test an entire dictionary being interpolated into the log message."""
241+
sentry_init(integrations=[LoggingIntegration()], default_integrations=False)
242+
events = capture_events()
243+
244+
logger.error("this is a log with a dictionary %s", {"foo": "bar"})
245+
246+
(event,) = events
247+
assert event["logentry"]["message"] == "this is a log with a dictionary %s"
248+
assert event["logentry"]["params"] == {"foo": "bar"}
249+
250+
251+
def test_logging_dictionary_args(sentry_init, capture_events):
252+
"""Here we test items from a dictionary being interpolated into the log message."""
253+
sentry_init(integrations=[LoggingIntegration()], default_integrations=False)
254+
events = capture_events()
255+
256+
logger.error(
257+
"the value of foo is %(foo)s, and the value of bar is %(bar)s",
258+
{"foo": "bar", "bar": "baz"},
259+
)
260+
261+
(event,) = events
262+
assert (
263+
event["logentry"]["message"]
264+
== "the value of foo is %(foo)s, and the value of bar is %(bar)s"
265+
)
266+
assert event["logentry"]["params"] == {"foo": "bar", "bar": "baz"}

0 commit comments

Comments
 (0)
0