Skip to content

Commit 54f7686

Browse files
authored
feat(span-streaming): Add more attrs to segment spans (#6432)
Add missing attrs to segment spans.
1 parent 7e27e34 commit 54f7686

5 files changed

Lines changed: 70 additions & 7 deletions

File tree

sentry_sdk/consts.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,12 @@ class SPANDATA:
917917
Example: 12345
918918
"""
919919

920+
PROCESS_COMMAND_ARGS = "process.command_args"
921+
"""
922+
All the command arguments (including the command/executable itself) as received by the process.
923+
Example: ["cmd/otecol","--config=config.yaml"]
924+
"""
925+
920926
PROFILER_ID = "profiler_id"
921927
"""
922928
Label identifying the profiler id that the span occurred in. This should be a string.
@@ -1080,6 +1086,48 @@ class SPANDATA:
10801086
Example: "a1b2c3d4e5f6"
10811087
"""
10821088

1089+
SENTRY_DIST = "sentry.dist"
1090+
"""
1091+
The Sentry dist.
1092+
Example: "1.0"
1093+
"""
1094+
1095+
SENTRY_ENVIRONMENT = "sentry.environment"
1096+
"""
1097+
The Sentry environment.
1098+
Example: "prod"
1099+
"""
1100+
1101+
SENTRY_RELEASE = "sentry.release"
1102+
"""
1103+
The Sentry release.
1104+
Example: "1.2.3"
1105+
"""
1106+
1107+
SENTRY_PLATFORM = "sentry.platform"
1108+
"""
1109+
The sdk platform that generated the event.
1110+
Example: "python"
1111+
"""
1112+
1113+
SENTRY_SDK_NAME = "sentry.sdk.name"
1114+
"""
1115+
The name of the SDK.
1116+
Example: "python"
1117+
"""
1118+
1119+
SENTRY_SDK_VERSION = "sentry.sdk.version"
1120+
"""
1121+
The SDK version.
1122+
Example: "1.2.3"
1123+
"""
1124+
1125+
SENTRY_SDK_INTEGRATIONS = "sentry.sdk.integrations"
1126+
"""
1127+
A list of names identifying enabled integrations.
1128+
Example: ["AtexitIntegration", "StdlibIntegration"]
1129+
"""
1130+
10831131

10841132
class SPANSTATUS:
10851133
"""

sentry_sdk/scope.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,8 @@ def get_global_scope(cls) -> "Scope":
376376
def set_global_attributes(self) -> None:
377377
from sentry_sdk.client import SDK_INFO
378378

379-
self.set_attribute("sentry.sdk.name", SDK_INFO["name"])
380-
self.set_attribute("sentry.sdk.version", SDK_INFO["version"])
379+
self.set_attribute(SPANDATA.SENTRY_SDK_NAME, SDK_INFO["name"])
380+
self.set_attribute(SPANDATA.SENTRY_SDK_VERSION, SDK_INFO["version"])
381381

382382
options = sentry_sdk.get_client().options
383383

@@ -387,11 +387,11 @@ def set_global_attributes(self) -> None:
387387

388388
environment = options.get("environment")
389389
if environment:
390-
self.set_attribute("sentry.environment", environment)
390+
self.set_attribute(SPANDATA.SENTRY_ENVIRONMENT, environment)
391391

392392
release = options.get("release")
393393
if release:
394-
self.set_attribute("sentry.release", release)
394+
self.set_attribute(SPANDATA.SENTRY_RELEASE, release)
395395

396396
@classmethod
397397
def last_event_id(cls) -> "Optional[str]":

sentry_sdk/traces.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,18 @@ def _set_segment_attributes(self) -> None:
572572
if not self._is_segment():
573573
return
574574

575-
self.set_attribute("process.command_args", sys.argv)
575+
client = sentry_sdk.get_client()
576+
577+
self.set_attribute(SPANDATA.SENTRY_PLATFORM, "python")
578+
self.set_attribute(SPANDATA.PROCESS_COMMAND_ARGS, sys.argv)
579+
self.set_attribute(
580+
SPANDATA.SENTRY_SDK_INTEGRATIONS, sorted(client.integrations.keys())
581+
)
582+
583+
if client.options.get("dist") and SPANDATA.SENTRY_DIST not in self._attributes:
584+
self.set_attribute(
585+
SPANDATA.SENTRY_DIST, str(client.options["dist"]).strip()
586+
)
576587

577588
def _to_json(self) -> "SpanJSON":
578589
res: "SpanJSON" = {

sentry_sdk/tracing_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,12 +1624,12 @@ def _matches(rule: "Any", value: "Any") -> bool:
16241624
name_matches = True
16251625
attributes_match = True
16261626

1627-
attributes = attributes or {}
1628-
16291627
if "name" in rule:
16301628
name_matches = _matches(rule["name"], name)
16311629

16321630
if "attributes" in rule:
1631+
attributes = attributes or {}
1632+
16331633
for attribute, value in rule["attributes"].items():
16341634
if attribute not in attributes or not _matches(
16351635
value, attributes[attribute]

tests/tracing/test_span_streaming.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,6 +1622,7 @@ def test_default_attributes(sentry_init, capture_envelopes):
16221622
sentry_init(
16231623
server_name="test-server",
16241624
release="1.0.0",
1625+
dist="1.0",
16251626
traces_sample_rate=1.0,
16261627
_experiments={"trace_lifecycle": "stream"},
16271628
)
@@ -1653,6 +1654,9 @@ def test_default_attributes(sentry_init, capture_envelopes):
16531654
"sentry.sdk.version": {"value": mock.ANY, "type": "string"},
16541655
"server.address": {"value": "test-server", "type": "string"},
16551656
"sentry.environment": {"value": "production", "type": "string"},
1657+
"sentry.platform": {"value": "python", "type": "string"},
16561658
"sentry.release": {"value": "1.0.0", "type": "string"},
1659+
"sentry.dist": {"value": "1.0", "type": "string"},
16571660
"sentry.origin": {"value": "manual", "type": "string"},
1661+
"sentry.sdk.integrations": {"value": mock.ANY, "type": "array"},
16581662
}

0 commit comments

Comments
 (0)