Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
7 changes: 7 additions & 0 deletions sentry_sdk/client.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import json
import os
import platform
import random
import socket
import sys
import uuid
import warnings
from collections.abc import Iterable, Mapping
Expand Down Expand Up @@ -241,6 +243,11 @@ def _serialized_v1_span_to_serialized_v2_span(
if "version" in sdk_info:
attributes["sentry.sdk.version"] = sdk_info["version"]

attributes["process.runtime.name"] = platform.python_implementation()
attributes["process.runtime.version"] = (
f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}"
)

if not attributes:
return res

Expand Down
14 changes: 13 additions & 1 deletion sentry_sdk/integrations/stdlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import TYPE_CHECKING

import sentry_sdk
from sentry_sdk.api import get_current_scope
from sentry_sdk.consts import OP, SPANDATA
from sentry_sdk.integrations import Integration
from sentry_sdk.scope import add_global_event_processor
Expand Down Expand Up @@ -52,7 +53,18 @@ def setup_once() -> None:
def add_python_runtime_context(
event: "Event", hint: "Hint"
) -> "Optional[Event]":
if sentry_sdk.get_client().get_integration(StdlibIntegration) is not None:
client = sentry_sdk.get_client()
if client.get_integration(StdlibIntegration) is not None:
is_span_streaming_enabled = has_span_streaming_enabled(client.options)
if is_span_streaming_enabled:
current_scope = get_current_scope()
segment = getattr(current_scope.streamed_span, "_segment", None)

if segment:
segment.set_attribute(
"process.runtime.description", sys.version
Comment thread
ericapisani marked this conversation as resolved.
Outdated
)
Comment thread
ericapisani marked this conversation as resolved.
Outdated
Comment thread
ericapisani marked this conversation as resolved.
Outdated
Comment thread
ericapisani marked this conversation as resolved.
Outdated
Comment thread
ericapisani marked this conversation as resolved.
Outdated

contexts = event.setdefault("contexts", {})
if isinstance(contexts, dict) and "runtime" not in contexts:
contexts["runtime"] = _RUNTIME_CONTEXT
Expand Down
10 changes: 10 additions & 0 deletions sentry_sdk/scope.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import platform
import sys
import warnings
from collections import deque
Expand Down Expand Up @@ -379,6 +380,15 @@ def set_global_attributes(self) -> None:
self.set_attribute(SPANDATA.SENTRY_SDK_NAME, SDK_INFO["name"])
self.set_attribute(SPANDATA.SENTRY_SDK_VERSION, SDK_INFO["version"])

self.set_attribute(
"process.runtime.name",
platform.python_implementation(),
)
self.set_attribute(
"process.runtime.version",
f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}",
)

options = sentry_sdk.get_client().options

server_name = options.get("server_name")
Expand Down
4 changes: 4 additions & 0 deletions tests/integrations/logging/test_logging.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import logging
import platform
import sys
import warnings

import pytest
Expand Down Expand Up @@ -537,6 +539,8 @@ def test_logger_with_all_attributes(sentry_init, capture_items):
"logger.name": "test-logger",
"sentry.origin": "auto.log.stdlib",
"sentry.message.template": "log #%d",
"process.runtime.name": platform.python_implementation(),
"process.runtime.version": f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}",
"sentry.message.parameter.0": 1,
"sentry.environment": "production",
"sentry.sdk.version": VERSION,
Expand Down
4 changes: 4 additions & 0 deletions tests/integrations/loguru/test_loguru.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import platform
import re
import sys
from unittest.mock import MagicMock, patch

import pytest
Expand Down Expand Up @@ -466,6 +468,8 @@ def test_logger_with_all_attributes(
"logger.name": "tests.integrations.loguru.test_loguru",
"sentry.origin": "auto.log.loguru",
"sentry.environment": "production",
"process.runtime.name": platform.python_implementation(),
"process.runtime.version": f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}",
"sentry.sdk.version": VERSION,
"sentry.severity_number": 13,
"sentry.severity_text": "warn",
Expand Down
16 changes: 16 additions & 0 deletions tests/integrations/openai/test_openai.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import json
import platform
import sys

import pytest

Expand Down Expand Up @@ -3832,6 +3834,8 @@ def test_ai_client_span_responses_api_no_pii(
"gen_ai.usage.output_tokens": 10,
"gen_ai.usage.output_tokens.reasoning": 8,
"gen_ai.usage.total_tokens": 30,
"process.runtime.name": platform.python_implementation(),
"process.runtime.version": f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}",
"sentry.environment": "production",
"sentry.op": "gen_ai.responses",
"sentry.origin": "auto.ai.openai",
Expand Down Expand Up @@ -3878,6 +3882,8 @@ def test_ai_client_span_responses_api_no_pii(
"gen_ai.usage.output_tokens": 10,
"gen_ai.usage.output_tokens.reasoning": 8,
"gen_ai.usage.total_tokens": 30,
"process.runtime.name": platform.python_implementation(),
"process.runtime.version": f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}",
"sentry.environment": "production",
"sentry.op": "gen_ai.responses",
"sentry.origin": "auto.ai.openai",
Expand Down Expand Up @@ -4139,6 +4145,8 @@ def test_ai_client_span_responses_api(
"gen_ai.request.messages": safe_serialize(expected_request_messages),
"gen_ai.request.model": "gpt-4o",
"gen_ai.response.text": "the model response",
"process.runtime.name": platform.python_implementation(),
"process.runtime.version": f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}",
"sentry.environment": "production",
"sentry.op": "gen_ai.responses",
"sentry.origin": "auto.ai.openai",
Expand Down Expand Up @@ -4191,6 +4199,8 @@ def test_ai_client_span_responses_api(
"gen_ai.request.messages": safe_serialize(expected_request_messages),
"gen_ai.request.model": "gpt-4o",
"gen_ai.response.text": "the model response",
"process.runtime.name": platform.python_implementation(),
"process.runtime.version": f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}",
"sentry.environment": "production",
"sentry.op": "gen_ai.responses",
"sentry.origin": "auto.ai.openai",
Expand Down Expand Up @@ -4626,6 +4636,8 @@ async def test_ai_client_span_responses_async_api(
"gen_ai.usage.output_tokens.reasoning": 8,
"gen_ai.usage.total_tokens": 30,
"gen_ai.response.text": "the model response",
"process.runtime.name": platform.python_implementation(),
"process.runtime.version": f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}",
"sentry.environment": "production",
"sentry.op": "gen_ai.responses",
"sentry.origin": "auto.ai.openai",
Expand Down Expand Up @@ -4678,6 +4690,8 @@ async def test_ai_client_span_responses_async_api(
"gen_ai.usage.output_tokens.reasoning": 8,
"gen_ai.usage.total_tokens": 30,
"gen_ai.response.text": "the model response",
"process.runtime.name": platform.python_implementation(),
"process.runtime.version": f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}",
"sentry.environment": "production",
"sentry.op": "gen_ai.responses",
"sentry.origin": "auto.ai.openai",
Expand Down Expand Up @@ -4975,6 +4989,8 @@ async def test_ai_client_span_streaming_responses_async_api(
"sentry.environment": "production",
"sentry.op": "gen_ai.responses",
"sentry.origin": "auto.ai.openai",
"process.runtime.name": platform.python_implementation(),
"process.runtime.version": f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}",
"sentry.release": mock.ANY,
"sentry.sdk.name": "sentry.python",
"sentry.sdk.version": mock.ANY,
Expand Down
17 changes: 17 additions & 0 deletions tests/test_logs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os
import platform
import sys
import time
from unittest import mock
Expand Down Expand Up @@ -495,6 +496,14 @@ def test_transport_format(sentry_init, capture_envelopes):
"type": "integer",
"value": 13,
},
"process.runtime.name": {
"type": "string",
"value": platform.python_implementation(),
},
"process.runtime.version": {
"type": "string",
"value": f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}",
},
"sentry.severity_text": {
"type": "string",
"value": "warn",
Expand Down Expand Up @@ -574,6 +583,14 @@ def record_lost_event(reason, data_category=None, item=None, *, quantity=1):
"type": "integer",
"value": 9,
},
"process.runtime.name": {
"type": "string",
"value": platform.python_implementation(),
},
"process.runtime.version": {
"type": "string",
"value": f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}",
},
"sentry.severity_text": {
"type": "string",
"value": "info",
Expand Down
9 changes: 9 additions & 0 deletions tests/test_metrics.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import platform
import sys
from unittest import mock

Expand Down Expand Up @@ -284,6 +285,14 @@ def test_transport_format(sentry_init, capture_envelopes):
"type": "string",
"value": "1.0.0",
},
"process.runtime.name": {
"type": "string",
"value": platform.python_implementation(),
},
"process.runtime.version": {
"type": "string",
"value": f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}",
},
"sentry.sdk.name": {
"type": "string",
"value": mock.ANY,
Expand Down
9 changes: 9 additions & 0 deletions tests/tracing/test_span_streaming.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import platform
import re
import sys
import time
Expand Down Expand Up @@ -1722,4 +1723,12 @@ def test_default_attributes(sentry_init, capture_envelopes):
"sentry.dist": {"value": "1.0", "type": "string"},
"sentry.origin": {"value": "manual", "type": "string"},
"sentry.sdk.integrations": {"value": mock.ANY, "type": "array"},
"process.runtime.name": {
"type": "string",
"value": platform.python_implementation(),
},
"process.runtime.version": {
"type": "string",
"value": f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}",
},
}
Loading