diff --git a/sentry_sdk/consts.py b/sentry_sdk/consts.py index c6e2e9f314..d93c46495d 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,48 @@ 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_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. + Example: ["AtexitIntegration", "StdlibIntegration"] + """ + class SPANSTATUS: """ 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 08a29a0f05..3ea00a6c1b 100644 --- a/sentry_sdk/traces.py +++ b/sentry_sdk/traces.py @@ -572,7 +572,18 @@ 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("dist") and SPANDATA.SENTRY_DIST not in self._attributes: + self.set_attribute( + SPANDATA.SENTRY_DIST, str(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] 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"}, }