From 0a9ffc70737697970318d43484439ec93a4ed3ca Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Thu, 28 May 2026 10:31:43 +0200 Subject: [PATCH 1/4] feat(span-streaming): Add more attrs to segment spans --- sentry_sdk/consts.py | 36 ++++++++++++++++++++++++++++++++++++ sentry_sdk/traces.py | 21 ++++++++++++++++++++- sentry_sdk/tracing_utils.py | 4 ++-- 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/sentry_sdk/consts.py b/sentry_sdk/consts.py index c6e2e9f314..09d9daedc2 100644 --- a/sentry_sdk/consts.py +++ b/sentry_sdk/consts.py @@ -917,6 +917,12 @@ class SPANDATA: Example: 12345 """ + PROCESS_COMMAND_ARGS = "process.command_args" + """ + All the command arguments (including the command/executable itself) as received by the process. + Example: ["cmd/otecol","--config=config.yaml"] + """ + PROFILER_ID = "profiler_id" """ Label identifying the profiler id that the span occurred in. This should be a string. @@ -1080,6 +1086,36 @@ class SPANDATA: Example: "a1b2c3d4e5f6" """ + SENTRY_DIST = "sentry.dist" + """ + The Sentry dist. + Example: "1.0" + """ + + SENTRY_ENVIRONMENT = "sentry.environment" + """ + The Sentry environment. + Example: "prod" + """ + + SENTRY_RELEASE = "sentry.release" + """ + The Sentry release. + Example: "1.2.3" + """ + + SENTRY_PLATFORM = "sentry.platform" + """ + The sdk platform that generated the event. + Example: "python" + """ + + SENTRY_SDK_INTEGRATIONS = "sentry.sdk.integrations" + """ + A list of names identifying enabled integrations. + Example: ["AtexitIntegration", "StdlibIntegration"] + """ + class SPANSTATUS: """ diff --git a/sentry_sdk/traces.py b/sentry_sdk/traces.py index 08a29a0f05..3f02fa2a0e 100644 --- a/sentry_sdk/traces.py +++ b/sentry_sdk/traces.py @@ -572,7 +572,26 @@ def _set_segment_attributes(self) -> None: if not self._is_segment(): return - self.set_attribute("process.command_args", sys.argv) + client = sentry_sdk.get_client() + + self.set_attribute(SPANDATA.SENTRY_PLATFORM, "python") + self.set_attribute(SPANDATA.PROCESS_COMMAND_ARGS, sys.argv) + self.set_attribute( + SPANDATA.SENTRY_SDK_INTEGRATIONS, sorted(client.integrations.keys()) + ) + + if client.options.get("release"): + self.set_attribute( + SPANDATA.SENTRY_RELEASE, client.options["release"].strip() + ) + + if client.options.get("environment"): + self.set_attribute( + SPANDATA.SENTRY_ENVIRONMENT, client.options["environment"].strip() + ) + + if client.options.get("dist"): + self.set_attribute(SPANDATA.SENTRY_DIST, client.options["dist"].strip()) def _to_json(self) -> "SpanJSON": res: "SpanJSON" = { diff --git a/sentry_sdk/tracing_utils.py b/sentry_sdk/tracing_utils.py index 822114628a..bf74dd6de6 100644 --- a/sentry_sdk/tracing_utils.py +++ b/sentry_sdk/tracing_utils.py @@ -1624,12 +1624,12 @@ def _matches(rule: "Any", value: "Any") -> bool: name_matches = True attributes_match = True - attributes = attributes or {} - if "name" in rule: name_matches = _matches(rule["name"], name) if "attributes" in rule: + attributes = attributes or {} + for attribute, value in rule["attributes"].items(): if attribute not in attributes or not _matches( value, attributes[attribute] From 44f4862813923ca680f30852abd9547c567f930f Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Thu, 28 May 2026 10:38:25 +0200 Subject: [PATCH 2/4] tests --- sentry_sdk/traces.py | 12 +++++++++--- tests/tracing/test_span_streaming.py | 4 ++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/sentry_sdk/traces.py b/sentry_sdk/traces.py index 3f02fa2a0e..62cf54e7a8 100644 --- a/sentry_sdk/traces.py +++ b/sentry_sdk/traces.py @@ -580,17 +580,23 @@ def _set_segment_attributes(self) -> None: SPANDATA.SENTRY_SDK_INTEGRATIONS, sorted(client.integrations.keys()) ) - if client.options.get("release"): + if ( + client.options.get("release") + and SPANDATA.SENTRY_RELEASE not in self._attributes + ): self.set_attribute( SPANDATA.SENTRY_RELEASE, client.options["release"].strip() ) - if client.options.get("environment"): + if ( + client.options.get("environment") + and SPANDATA.SENTRY_ENVIRONMENT not in self._attributes + ): self.set_attribute( SPANDATA.SENTRY_ENVIRONMENT, client.options["environment"].strip() ) - if client.options.get("dist"): + if client.options.get("dist") and SPANDATA.SENTRY_DIST not in self._attributes: self.set_attribute(SPANDATA.SENTRY_DIST, client.options["dist"].strip()) def _to_json(self) -> "SpanJSON": diff --git a/tests/tracing/test_span_streaming.py b/tests/tracing/test_span_streaming.py index 734d2edeb1..c861616b70 100644 --- a/tests/tracing/test_span_streaming.py +++ b/tests/tracing/test_span_streaming.py @@ -1622,6 +1622,7 @@ def test_default_attributes(sentry_init, capture_envelopes): sentry_init( server_name="test-server", release="1.0.0", + dist="1.0", traces_sample_rate=1.0, _experiments={"trace_lifecycle": "stream"}, ) @@ -1653,6 +1654,9 @@ def test_default_attributes(sentry_init, capture_envelopes): "sentry.sdk.version": {"value": mock.ANY, "type": "string"}, "server.address": {"value": "test-server", "type": "string"}, "sentry.environment": {"value": "production", "type": "string"}, + "sentry.platform": {"value": "python", "type": "string"}, "sentry.release": {"value": "1.0.0", "type": "string"}, + "sentry.dist": {"value": "1.0", "type": "string"}, "sentry.origin": {"value": "manual", "type": "string"}, + "sentry.sdk.integrations": {"value": mock.ANY, "type": "array"}, } From c42a09aa358e745b93025602c3cf8c91aa855446 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Thu, 28 May 2026 10:39:20 +0200 Subject: [PATCH 3/4] stringify --- sentry_sdk/traces.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/sentry_sdk/traces.py b/sentry_sdk/traces.py index 62cf54e7a8..977f752765 100644 --- a/sentry_sdk/traces.py +++ b/sentry_sdk/traces.py @@ -585,7 +585,7 @@ def _set_segment_attributes(self) -> None: and SPANDATA.SENTRY_RELEASE not in self._attributes ): self.set_attribute( - SPANDATA.SENTRY_RELEASE, client.options["release"].strip() + SPANDATA.SENTRY_RELEASE, str(client.options["release"]).strip() ) if ( @@ -593,11 +593,13 @@ def _set_segment_attributes(self) -> None: and SPANDATA.SENTRY_ENVIRONMENT not in self._attributes ): self.set_attribute( - SPANDATA.SENTRY_ENVIRONMENT, client.options["environment"].strip() + SPANDATA.SENTRY_ENVIRONMENT, str(client.options["environment"]).strip() ) if client.options.get("dist") and SPANDATA.SENTRY_DIST not in self._attributes: - self.set_attribute(SPANDATA.SENTRY_DIST, client.options["dist"].strip()) + self.set_attribute( + SPANDATA.SENTRY_DIST, str(client.options["dist"]).strip() + ) def _to_json(self) -> "SpanJSON": res: "SpanJSON" = { From 69e8679b3c5b5fcac485a61c1438313ace4df6c6 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Thu, 28 May 2026 10:43:31 +0200 Subject: [PATCH 4/4] . --- sentry_sdk/consts.py | 12 ++++++++++++ sentry_sdk/scope.py | 8 ++++---- sentry_sdk/traces.py | 16 ---------------- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/sentry_sdk/consts.py b/sentry_sdk/consts.py index 09d9daedc2..d93c46495d 100644 --- a/sentry_sdk/consts.py +++ b/sentry_sdk/consts.py @@ -1110,6 +1110,18 @@ class SPANDATA: Example: "python" """ + SENTRY_SDK_NAME = "sentry.sdk.name" + """ + The name of the SDK. + Example: "python" + """ + + SENTRY_SDK_VERSION = "sentry.sdk.version" + """ + The SDK version. + Example: "1.2.3" + """ + SENTRY_SDK_INTEGRATIONS = "sentry.sdk.integrations" """ A list of names identifying enabled integrations. diff --git a/sentry_sdk/scope.py b/sentry_sdk/scope.py index 06aad5857f..b342642fc0 100644 --- a/sentry_sdk/scope.py +++ b/sentry_sdk/scope.py @@ -376,8 +376,8 @@ def get_global_scope(cls) -> "Scope": def set_global_attributes(self) -> None: from sentry_sdk.client import SDK_INFO - self.set_attribute("sentry.sdk.name", SDK_INFO["name"]) - self.set_attribute("sentry.sdk.version", SDK_INFO["version"]) + self.set_attribute(SPANDATA.SENTRY_SDK_NAME, SDK_INFO["name"]) + self.set_attribute(SPANDATA.SENTRY_SDK_VERSION, SDK_INFO["version"]) options = sentry_sdk.get_client().options @@ -387,11 +387,11 @@ def set_global_attributes(self) -> None: environment = options.get("environment") if environment: - self.set_attribute("sentry.environment", environment) + self.set_attribute(SPANDATA.SENTRY_ENVIRONMENT, environment) release = options.get("release") if release: - self.set_attribute("sentry.release", release) + self.set_attribute(SPANDATA.SENTRY_RELEASE, release) @classmethod def last_event_id(cls) -> "Optional[str]": diff --git a/sentry_sdk/traces.py b/sentry_sdk/traces.py index 977f752765..3ea00a6c1b 100644 --- a/sentry_sdk/traces.py +++ b/sentry_sdk/traces.py @@ -580,22 +580,6 @@ def _set_segment_attributes(self) -> None: SPANDATA.SENTRY_SDK_INTEGRATIONS, sorted(client.integrations.keys()) ) - if ( - client.options.get("release") - and SPANDATA.SENTRY_RELEASE not in self._attributes - ): - self.set_attribute( - SPANDATA.SENTRY_RELEASE, str(client.options["release"]).strip() - ) - - if ( - client.options.get("environment") - and SPANDATA.SENTRY_ENVIRONMENT not in self._attributes - ): - self.set_attribute( - SPANDATA.SENTRY_ENVIRONMENT, str(client.options["environment"]).strip() - ) - if client.options.get("dist") and SPANDATA.SENTRY_DIST not in self._attributes: self.set_attribute( SPANDATA.SENTRY_DIST, str(client.options["dist"]).strip()