8000 explicitly assert on every attribute · getsentry/sentry-python@1b73d4c · GitHub
[go: up one dir, main page]

Skip to content

Commit 1b73d4c

Browse files
committed
explicitly assert on every attribute
1 parent 4cee7d1 commit 1b73d4c

File tree

1 file changed

+57
-6
lines changed

1 file changed

+57
-6
lines changed

tests/test_logs.py

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def _convert_attr(attr):
3030
return attr["value"]
3131
if attr["value"].startswith("{"):
3232
try:
33-
return json.loads(attr["stringValue"])
33+
return json.loads(attr["value"])
3434
except ValueError:
3535
pass
3636
return str(attr["value"])
@@ -393,9 +393,9 @@ def test_log_strips_project_root(sentry_init, capture_envelopes):
393393
assert attrs["code.file.path"] == "blah/path.py"
394394

395395

396-
def test_extra_data(sentry_init, capture_envelopes):
396+
def test_logger_with_all_attributes(sentry_init, capture_envelopes):
397397
"""
398-
The python logger should be able to log extra data
398+
The python logger should be able to log all attributes, including extra data.
399399
"""
400400
sentry_init(_experiments={"enable_logs": True})
401401
envelopes = capture_envelopes()
@@ -409,9 +409,60 @@ def test_extra_data(sentry_init, capture_envelopes):
409409
get_client().flush()
410410

411411
logs = envelopes_to_logs(envelopes)
412-
assert logs[0]["attributes"]["foo"] == "bar"
413-
assert logs[0]["attributes"]["numeric"] == 42
414-
assert logs[0]["attributes"]["more_complex"] == '{"nested": "data"}'
412+
413+
attributes = logs[0]["attributes"]
414+
415+
assert "process.pid" in attributes
416+
assert isinstance(attributes["process.pid"], int)
417+
del attributes["process.pid"]
418+
419+
assert "sentry.release" in attributes
420+
assert isinstance(attributes["sentry.release"], str)
421+
del attributes["sentry.release"]
422+
423+
assert "server.address" in attributes
424+
assert isinstance(attributes["server.address"], str)
425+
del attributes["server.address"]
426+
427+
assert "thread.id" in attributes
428+
assert isinstance(attributes["thread.id"], int)
429+
del attributes["thread.id"]
430+
431+
assert "code.file.path" in attributes
432+
assert isinstance(attributes["code.file.path"], str)
433+
del attributes["code.file.path"]
434+
435+
assert "code.function.name" in attributes
436+
assert isinstance(attributes["code.function.name"], str)
437+
del attributes["code.function.name"]
438+
439+
assert "code.line.number" in attributes
440+
assert isinstance(attributes["code.line.number"], int)
441+
del attributes["code.line.number"]
442+
443+
assert "process.executable.name" in attributes
444+
assert isinstance(attributes["process.executable.name"], str)
445+
del attributes["process.executable.name"]
446+
447+
assert "thread.name" in attributes
448+
assert isinstance(attributes["thread.name"], str)
449+
del attributes["thread.name"]
450+
451+
# Assert on the remaining non-dynamic attributes.
452+
assert attributes == {
453+
"foo": "bar",
454+
"numeric": 42,
455+
"more_complex": "{'nested': 'data'}",
456+
"logger.name": "test-logger",
457+
"sentry.origin": "auto.logger.log",
458+
"sentry.message.template": "log #%d",
459+
"sentry.message.parameters.0": 1,
460+
"sentry.environment": "production",
461+
"sentry.sdk.name": "sentry.python",
462+
"sentry.sdk.version": VERSION,
463+
"sentry.severity_number": 13,
464+
"sentry.severity_text": "warn",
465+
}
415466

416467

417468
def test_auto_flush_logs_after_100(sentry_init, capture_envelopes):

0 commit comments

Comments
 (0)
0