Skip to content

Commit eee4cac

Browse files
authored
fix(logs): Make sentry.message.parameters singular as per spec (#4387)
As per https://develop.sentry.dev/sdk/telemetry/logs/#default-attributes we should be using `sentry.message.parameter` (singular) instead of `sentry.message.parameters`. This matches how we approach the other attributes in our conventions.
1 parent 1090eee commit eee4cac

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

sentry_sdk/integrations/logging.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ def _capture_log_from_record(self, client, record):
362362
if record.args is not None:
363363
if isinstance(record.args, tuple):
364364
for i, arg in enumerate(record.args):
365-
attrs[f"sentry.message.parameters.{i}"] = (
365+
attrs[f"sentry.message.parameter.{i}"] = (
366366
arg
367367
if isinstance(arg, str)
368368
or isinstance(arg, float)

sentry_sdk/logger.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def _capture_log(severity_text, severity_number, template, **kwargs):
1818
if "attributes" in kwargs:
1919
attrs.update(kwargs.pop("attributes"))
2020
for k, v in kwargs.items():
21-
attrs[f"sentry.message.parameters.{k}"] = v
21+
attrs[f"sentry.message.parameter.{k}"] = v
2222

2323
attrs = {
2424
k: (

tests/test_logs.py

+11-12
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def test_logs_attributes(sentry_init, capture_envelopes):
186186
assert logs[0]["attributes"][k] == v
187187
assert logs[0]["attributes"]["sentry.environment"] == "production"
188188
assert "sentry.release" in logs[0]["attributes"]
189-
assert logs[0]["attributes"]["sentry.message.parameters.my_var"] == "some value"
189+
assert logs[0]["attributes"]["sentry.message.parameter.my_var"] == "some value"
190190
assert logs[0]["attributes"][SPANDATA.SERVER_ADDRESS] == "test-server"
191191
assert logs[0]["attributes"]["sentry.sdk.name"].startswith("sentry.python")
192192
assert logs[0]["attributes"]["sentry.sdk.version"] == VERSION
@@ -214,23 +214,23 @@ def test_logs_message_params(sentry_init, capture_envelopes):
214214
logs = envelopes_to_logs(envelopes)
215215

216216
assert logs[0]["body"] == "The recorded value was '1'"
217-
assert logs[0]["attributes"]["sentry.message.parameters.int_var"] == 1
217+
assert logs[0]["attributes"]["sentry.message.parameter.int_var"] == 1
218218

219219
assert logs[1]["body"] == "The recorded value was '2.0'"
220-
assert logs[1]["attributes"]["sentry.message.parameters.float_var"] == 2.0
220+
assert logs[1]["attributes"]["sentry.message.parameter.float_var"] == 2.0
221221

222222
assert logs[2]["body"] == "The recorded value was 'False'"
223-
assert logs[2]["attributes"]["sentry.message.parameters.bool_var"] is False
223+
assert logs[2]["attributes"]["sentry.message.parameter.bool_var"] is False
224224

225225
assert logs[3]["body"] == "The recorded value was 'some string value'"
226226
assert (
227-
logs[3]["attributes"]["sentry.message.parameters.string_var"]
227+
logs[3]["attributes"]["sentry.message.parameter.string_var"]
228228
== "some string value"
229229
)
230230

231231
assert logs[4]["body"] == "The recorded error was 'some error'"
232232
assert (
233-
logs[4]["attributes"]["sentry.message.parameters.error"]
233+
logs[4]["attributes"]["sentry.message.parameter.error"]
234234
== "Exception('some error')"
235235
)
236236

@@ -287,8 +287,8 @@ def test_logger_integration_warning(sentry_init, capture_envelopes):
287287
assert "code.line.number" in attrs
288288
assert attrs["logger.name"] == "test-logger"
289289
assert attrs["sentry.environment"] == "production"
290-
assert attrs["sentry.message.parameters.0"] == "1"
291-
assert attrs["sentry.message.parameters.1"] == "2"
290+
assert attrs["sentry.message.parameter.0"] == "1"
291+
assert attrs["sentry.message.parameter.1"] == "2"
292292
assert attrs["sentry.origin"] == "auto.logger.log"
293293
assert logs[0]["severity_number"] == 13
294294
assert logs[0]["severity_text"] == "warn"
@@ -349,14 +349,13 @@ def test_logging_errors(sentry_init, capture_envelopes):
349349
logs = envelopes_to_logs(envelopes)
350350
assert logs[0]["severity_text"] == "error"
351351
assert "sentry.message.template" not in logs[0]["attributes"]
352-
assert "sentry.message.parameters.0" not in logs[0]["attributes"]
352+
assert "sentry.message.parameter.0" not in logs[0]["attributes"]
353353
assert "code.line.number" in logs[0]["attributes"]
354354

355355
assert logs[1]["severity_text"] == "error"
356356
assert logs[1]["attributes"]["sentry.message.template"] == "error is %s"
357357
assert (
358-
logs[1]["attributes"]["sentry.message.parameters.0"]
359-
== "Exception('test exc 2')"
358+
logs[1]["attributes"]["sentry.message.parameter.0"] == "Exception('test exc 2')"
360359
)
361360
assert "code.line.number" in logs[1]["attributes"]
362361

@@ -456,7 +455,7 @@ def test_logger_with_all_attributes(sentry_init, capture_envelopes):
456455
"logger.name": "test-logger",
457456
"sentry.origin": "auto.logger.log",
458457
"sentry.message.template": "log #%d",
459-
"sentry.message.parameters.0": 1,
458+
"sentry.message.parameter.0": 1,
460459
"sentry.environment": "production",
461460
"sentry.sdk.name": "sentry.python",
462461
"sentry.sdk.version": VERSION,

0 commit comments

Comments
 (0)