Skip to content

Commit c5f0903

Browse files
committed
fix(logs): Set span_id instead of sentry.trace.parent_span_id
1 parent 6046f2d commit c5f0903

File tree

4 files changed

+13
-19
lines changed

4 files changed

+13
-19
lines changed

sentry_sdk/client.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -927,11 +927,8 @@ def _capture_log(self, log: "Optional[Log]") -> None:
927927
if trace_id is not None and log.get("trace_id") is None:
928928
log["trace_id"] = trace_id
929929

930-
if (
931-
span_id is not None
932-
and "sentry.trace.parent_span_id" not in log["attributes"]
933-
):
934-
log["attributes"]["sentry.trace.parent_span_id"] = span_id
930+
if span_id is not None and not log.get("span_id"):
931+
log["attributes"]["span_id"] = span_id
935932

936933
# The user, if present, is always set on the isolation scope.
937934
if isolation_scope._user is not None:

tests/integrations/logging/test_logging.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,9 @@ def test_logger_with_all_attributes(sentry_init, capture_envelopes):
438438

439439
logs = envelopes_to_logs(envelopes)
440440

441+
assert "span_id" in logs[0]
442+
assert isinstance(logs[0]["span_id"], str)
443+
441444
attributes = logs[0]["attributes"]
442445

443446
assert "process.pid" in attributes
@@ -478,10 +481,6 @@ def test_logger_with_all_attributes(sentry_init, capture_envelopes):
478481

479482
assert attributes.pop("sentry.sdk.name").startswith("sentry.python")
480483

481-
assert "sentry.trace.parent_span_id" in attributes
482-
assert isinstance(attributes["sentry.trace.parent_span_id"], str)
483-
del attributes["sentry.trace.parent_span_id"]
484-
485484
# Assert on the remaining non-dynamic attributes.
486485
assert attributes == {
487486
"foo": "bar",

tests/integrations/loguru/test_loguru.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,9 @@ def test_logger_with_all_attributes(
420420

421421
attributes = logs[0]["attributes"]
422422

423+
assert "span_id" in logs[0]
424+
assert isinstance(logs[0]["span_id"], str)
425+
423426
assert "process.pid" in attributes
424427
assert isinstance(attributes["process.pid"], int)
425428
del attributes["process.pid"]
@@ -458,10 +461,6 @@ def test_logger_with_all_attributes(
458461

459462
assert attributes.pop("sentry.sdk.name").startswith("sentry.python")
460463

461-
assert "sentry.trace.parent_span_id" in attributes
462-
assert isinstance(attributes["sentry.trace.parent_span_id"], str)
463-
del attributes["sentry.trace.parent_span_id"]
464-
465464
# Assert on the remaining non-dynamic attributes.
466465
assert attributes == {
467466
"logger.name": "tests.integrations.loguru.test_loguru",

tests/test_logs.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,9 @@ def test_logs_tied_to_transactions(sentry_init, capture_envelopes):
319319

320320
get_client().flush()
321321
logs = envelopes_to_logs(envelopes)
322-
assert logs[0]["attributes"]["sentry.trace.parent_span_id"] == trx.span_id
322+
323+
assert "span_id" in logs[0]
324+
assert logs[0]["span_id"] == trx.span_id
323325

324326

325327
@minimum_python_37
@@ -336,7 +338,7 @@ def test_logs_tied_to_spans(sentry_init, capture_envelopes):
336338

337339
get_client().flush()
338340
logs = envelopes_to_logs(envelopes)
339-
assert logs[0]["attributes"]["sentry.trace.parent_span_id"] == span.span_id
341+
assert logs[0]["span_id"] == span.span_id
340342

341343

342344
def test_auto_flush_logs_after_100(sentry_init, capture_envelopes):
@@ -491,6 +493,7 @@ def record_lost_event(reason, data_category=None, item=None, *, quantity=1):
491493
"level": "info",
492494
"timestamp": mock.ANY,
493495
"trace_id": mock.ANY,
496+
"span_id": mock.ANY,
494497
"attributes": {
495498
"sentry.environment": {
496499
"type": "string",
@@ -516,10 +519,6 @@ def record_lost_event(reason, data_category=None, item=None, *, quantity=1):
516519
"type": "string",
517520
"value": "info",
518521
},
519-
"sentry.trace.parent_span_id": {
520-
"type": "string",
521-
"value": mock.ANY,
522-
},
523522
"server.address": {
524523
"type": "string",
525524
"value": "test-server",

0 commit comments

Comments
 (0)