Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions sentry_sdk/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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:
"""
Expand Down
8 changes: 4 additions & 4 deletions sentry_sdk/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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]":
Expand Down
13 changes: 12 additions & 1 deletion sentry_sdk/traces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Comment thread
sentrivana marked this conversation as resolved.
)

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" = {
Expand Down
4 changes: 2 additions & 2 deletions sentry_sdk/tracing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
4 changes: 4 additions & 0 deletions tests/tracing/test_span_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
)
Expand Down Expand Up @@ -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"},
}
Loading