diff --git a/sentry_sdk/client.py b/sentry_sdk/client.py index 8ec83e267e..83974fc5f8 100644 --- a/sentry_sdk/client.py +++ b/sentry_sdk/client.py @@ -232,7 +232,7 @@ def _serialized_v1_span_to_serialized_v2_span( if "environment" in event: attributes["sentry.environment"] = event["environment"] if "server_name" in event: - attributes["server.address"] = event["server_name"] + attributes[SPANDATA.DEVICE_NAME] = event["server_name"] if "transaction" in event: attributes["sentry.segment.name"] = event["transaction"] diff --git a/sentry_sdk/consts.py b/sentry_sdk/consts.py index 82a9f27ec8..871c36ede8 100644 --- a/sentry_sdk/consts.py +++ b/sentry_sdk/consts.py @@ -539,6 +539,12 @@ class SPANDATA: Example: my_user """ + DEVICE_NAME = "device.name" + """ + The name of the device. On mobile, this is the user-assigned device name. On servers and desktops, this is typically the hostname. + Example: "localhost" + """ + GEN_AI_AGENT_NAME = "gen_ai.agent.name" """ The name of the agent being used. diff --git a/sentry_sdk/scope.py b/sentry_sdk/scope.py index 9587ed84fd..11bb01631f 100644 --- a/sentry_sdk/scope.py +++ b/sentry_sdk/scope.py @@ -392,7 +392,7 @@ def set_global_attributes(self) -> None: server_name = options.get("server_name") if server_name: - self.set_attribute(SPANDATA.SERVER_ADDRESS, server_name) + self.set_attribute(SPANDATA.DEVICE_NAME, server_name) environment = options.get("environment") if environment: diff --git a/tests/integrations/boto3/test_s3.py b/tests/integrations/boto3/test_s3.py index aeab5f58a1..1f2c77f944 100644 --- a/tests/integrations/boto3/test_s3.py +++ b/tests/integrations/boto3/test_s3.py @@ -125,7 +125,7 @@ def test_streaming( "sentry.sdk.version": mock.ANY, "sentry.segment.id": mock.ANY, "sentry.segment.name": "custom parent", - "server.address": mock.ANY, + SPANDATA.DEVICE_NAME: mock.ANY, "thread.id": mock.ANY, "thread.name": mock.ANY, } @@ -283,7 +283,7 @@ def test_omit_url_data_if_parsing_fails( "sentry.sdk.version": mock.ANY, "sentry.segment.id": mock.ANY, "sentry.segment.name": "custom parent", - "server.address": mock.ANY, + SPANDATA.DEVICE_NAME: mock.ANY, "thread.id": mock.ANY, "thread.name": mock.ANY, } diff --git a/tests/integrations/grpc/test_grpc.py b/tests/integrations/grpc/test_grpc.py index f50a2f62d1..448e2d9c87 100644 --- a/tests/integrations/grpc/test_grpc.py +++ b/tests/integrations/grpc/test_grpc.py @@ -8,7 +8,7 @@ import sentry_sdk from sentry_sdk import start_span, start_transaction -from sentry_sdk.consts import OP +from sentry_sdk.consts import OP, SPANDATA from sentry_sdk.integrations.grpc import GRPCIntegration from sentry_sdk.integrations.grpc.client import ClientInterceptor from sentry_sdk.tracing_utils import has_span_streaming_enabled @@ -316,7 +316,7 @@ def test_grpc_client_starts_span( "sentry.sdk.version": mock.ANY, "sentry.segment.id": mock.ANY, "sentry.segment.name": "custom parent", - "server.address": mock.ANY, + SPANDATA.DEVICE_NAME: mock.ANY, "thread.id": mock.ANY, "thread.name": mock.ANY, "rpc.response.status_code": "OK", @@ -400,7 +400,7 @@ def test_grpc_client_unary_stream_starts_span( "sentry.sdk.version": mock.ANY, "sentry.segment.id": mock.ANY, "sentry.segment.name": "custom parent", - "server.address": mock.ANY, + SPANDATA.DEVICE_NAME: mock.ANY, "thread.id": mock.ANY, "thread.name": mock.ANY, } @@ -494,7 +494,7 @@ def test_grpc_client_other_interceptor( "sentry.sdk.version": mock.ANY, "sentry.segment.id": mock.ANY, "sentry.segment.name": "custom parent", - "server.address": mock.ANY, + SPANDATA.DEVICE_NAME: mock.ANY, "thread.id": mock.ANY, "thread.name": mock.ANY, "rpc.response.status_code": "OK", diff --git a/tests/integrations/grpc/test_grpc_aio.py b/tests/integrations/grpc/test_grpc_aio.py index 217dc110d2..e7a8d0db0e 100644 --- a/tests/integrations/grpc/test_grpc_aio.py +++ b/tests/integrations/grpc/test_grpc_aio.py @@ -8,7 +8,7 @@ import sentry_sdk from sentry_sdk import start_span, start_transaction -from sentry_sdk.consts import OP +from sentry_sdk.consts import OP, SPANDATA from sentry_sdk.integrations.grpc import GRPCIntegration from sentry_sdk.tracing_utils import has_span_streaming_enabled from tests.conftest import ApproxDict @@ -341,7 +341,7 @@ async def test_grpc_client_starts_span( "sentry.sdk.version": mock.ANY, "sentry.segment.id": mock.ANY, "sentry.segment.name": "custom parent", - "server.address": mock.ANY, + SPANDATA.DEVICE_NAME: mock.ANY, "thread.id": mock.ANY, "thread.name": mock.ANY, "rpc.response.status_code": "OK", @@ -416,7 +416,7 @@ async def test_grpc_client_unary_stream_starts_span( "sentry.sdk.version": mock.ANY, "sentry.segment.id": mock.ANY, "sentry.segment.name": "custom parent", - "server.address": mock.ANY, + SPANDATA.DEVICE_NAME: mock.ANY, "thread.id": mock.ANY, "thread.name": mock.ANY, } diff --git a/tests/integrations/huggingface_hub/test_huggingface_hub.py b/tests/integrations/huggingface_hub/test_huggingface_hub.py index 8d8e6a9b2e..13f3ce25fc 100644 --- a/tests/integrations/huggingface_hub/test_huggingface_hub.py +++ b/tests/integrations/huggingface_hub/test_huggingface_hub.py @@ -532,7 +532,7 @@ def test_text_generation( "sentry.sdk.version": mock.ANY, "sentry.segment.id": mock.ANY, "sentry.segment.name": "test", - "server.address": mock.ANY, + SPANDATA.DEVICE_NAME: mock.ANY, "thread.id": mock.ANY, "thread.name": mock.ANY, } @@ -671,7 +671,7 @@ def test_text_generation_streaming( "sentry.sdk.version": mock.ANY, "sentry.segment.id": mock.ANY, "sentry.segment.name": "test", - "server.address": mock.ANY, + SPANDATA.DEVICE_NAME: mock.ANY, "thread.id": mock.ANY, "thread.name": mock.ANY, } @@ -814,7 +814,7 @@ def test_chat_completion( "sentry.sdk.version": mock.ANY, "sentry.segment.id": mock.ANY, "sentry.segment.name": "test", - "server.address": mock.ANY, + SPANDATA.DEVICE_NAME: mock.ANY, "thread.id": mock.ANY, "thread.name": mock.ANY, } @@ -965,7 +965,7 @@ def test_chat_completion_streaming( "sentry.sdk.version": mock.ANY, "sentry.segment.id": mock.ANY, "sentry.segment.name": "test", - "server.address": mock.ANY, + SPANDATA.DEVICE_NAME: mock.ANY, "thread.id": mock.ANY, "thread.name": mock.ANY, } @@ -1114,7 +1114,7 @@ def test_chat_completion_api_error( "sentry.sdk.version": mock.ANY, "sentry.segment.id": mock.ANY, "sentry.segment.name": "test", - "server.address": mock.ANY, + SPANDATA.DEVICE_NAME: mock.ANY, "thread.id": mock.ANY, "thread.name": mock.ANY, } @@ -1315,7 +1315,7 @@ def test_chat_completion_with_tools( "sentry.sdk.version": mock.ANY, "sentry.segment.id": mock.ANY, "sentry.segment.name": "test", - "server.address": mock.ANY, + SPANDATA.DEVICE_NAME: mock.ANY, "thread.id": mock.ANY, "thread.name": mock.ANY, } @@ -1477,7 +1477,7 @@ def test_chat_completion_streaming_with_tools( "sentry.sdk.version": mock.ANY, "sentry.segment.id": mock.ANY, "sentry.segment.name": "test", - "server.address": mock.ANY, + SPANDATA.DEVICE_NAME: mock.ANY, "thread.id": mock.ANY, "thread.name": mock.ANY, } diff --git a/tests/integrations/logging/test_logging.py b/tests/integrations/logging/test_logging.py index 661fc53f57..02ed6adcb0 100644 --- a/tests/integrations/logging/test_logging.py +++ b/tests/integrations/logging/test_logging.py @@ -5,7 +5,7 @@ import pytest from sentry_sdk import get_client -from sentry_sdk.consts import VERSION +from sentry_sdk.consts import SPANDATA, VERSION from sentry_sdk.integrations.logging import ( LoggingIntegration, ignore_logger, @@ -572,9 +572,9 @@ def test_logger_with_all_attributes(sentry_init, capture_items): assert isinstance(attributes["sentry.release"], str) del attributes["sentry.release"] - assert "server.address" in attributes - assert isinstance(attributes["server.address"], str) - del attributes["server.address"] + assert SPANDATA.DEVICE_NAME in attributes + assert isinstance(attributes[SPANDATA.DEVICE_NAME], str) + del attributes[SPANDATA.DEVICE_NAME] assert "thread.id" in attributes assert isinstance(attributes["thread.id"], int) diff --git a/tests/integrations/loguru/test_loguru.py b/tests/integrations/loguru/test_loguru.py index 2db777d3c3..23f17e18f5 100644 --- a/tests/integrations/loguru/test_loguru.py +++ b/tests/integrations/loguru/test_loguru.py @@ -6,7 +6,7 @@ from loguru._recattrs import RecordFile, RecordLevel import sentry_sdk -from sentry_sdk.consts import VERSION +from sentry_sdk.consts import SPANDATA, VERSION from sentry_sdk.integrations.loguru import LoggingLevels, LoguruIntegration logger.remove(0) # don't print to console @@ -507,9 +507,9 @@ def test_logger_with_all_attributes( assert isinstance(attributes["sentry.release"], str) del attributes["sentry.release"] - assert "server.address" in attributes - assert isinstance(attributes["server.address"], str) - del attributes["server.address"] + assert SPANDATA.DEVICE_NAME in attributes + assert isinstance(attributes[SPANDATA.DEVICE_NAME], str) + del attributes[SPANDATA.DEVICE_NAME] assert "thread.id" in attributes assert isinstance(attributes["thread.id"], int) diff --git a/tests/test_logs.py b/tests/test_logs.py index e8a098ff44..6f54b44879 100644 --- a/tests/test_logs.py +++ b/tests/test_logs.py @@ -211,7 +211,7 @@ def test_logs_attributes(sentry_init, capture_items): if sentry_sdk.get_client().options.get("release") is not None: assert "sentry.release" in logs[0]["attributes"] assert logs[0]["attributes"]["sentry.message.parameter.my_var"] == "some value" - assert logs[0]["attributes"][SPANDATA.SERVER_ADDRESS] == "test-server" + assert logs[0]["attributes"][SPANDATA.DEVICE_NAME] == "test-server" assert logs[0]["attributes"]["sentry.sdk.name"].startswith("sentry.python") assert logs[0]["attributes"]["sentry.sdk.version"] == VERSION @@ -561,7 +561,7 @@ def test_transport_format(sentry_init, capture_envelopes): "type": "string", "value": "warn", }, - "server.address": { + SPANDATA.DEVICE_NAME: { "type": "string", "value": "test-server", }, @@ -647,7 +647,7 @@ def record_lost_event(reason, data_category=None, item=None, *, quantity=1): "type": "string", "value": "info", }, - "server.address": { + SPANDATA.DEVICE_NAME: { "type": "string", "value": "test-server", }, diff --git a/tests/test_metrics.py b/tests/test_metrics.py index e07e507ba7..a906b65eef 100644 --- a/tests/test_metrics.py +++ b/tests/test_metrics.py @@ -89,7 +89,7 @@ def test_metrics_with_attributes(sentry_init, capture_items): assert metrics[0]["attributes"]["sentry.release"] == "1.0.0" assert metrics[0]["attributes"]["sentry.environment"] == "test" - assert metrics[0]["attributes"][SPANDATA.SERVER_ADDRESS] == "test-server" + assert metrics[0]["attributes"][SPANDATA.DEVICE_NAME] == "test-server" assert metrics[0]["attributes"]["sentry.sdk.name"].startswith("sentry.python") assert metrics[0]["attributes"]["sentry.sdk.version"] == VERSION @@ -342,7 +342,7 @@ def test_transport_format(sentry_init, capture_envelopes): "type": "string", "value": VERSION, }, - "server.address": { + SPANDATA.DEVICE_NAME: { "type": "string", "value": "test-server", }, diff --git a/tests/tracing/test_decorator.py b/tests/tracing/test_decorator.py index 6c66afb6be..0e4046a250 100644 --- a/tests/tracing/test_decorator.py +++ b/tests/tracing/test_decorator.py @@ -4,7 +4,7 @@ import pytest import sentry_sdk -from sentry_sdk.consts import SPANTEMPLATE +from sentry_sdk.consts import SPANDATA, SPANTEMPLATE from sentry_sdk.tracing_utils import create_span_decorator from sentry_sdk.utils import logger from tests.conftest import patch_start_tracing_child @@ -449,7 +449,7 @@ def my_agent(): "sentry.sdk.version": mock.ANY, "sentry.segment.id": mock.ANY, "sentry.segment.name": "test-transaction", - "server.address": mock.ANY, + SPANDATA.DEVICE_NAME: mock.ANY, "thread.id": mock.ANY, "thread.name": mock.ANY, } @@ -474,7 +474,7 @@ def my_agent(): "sentry.sdk.version": mock.ANY, "sentry.segment.id": mock.ANY, "sentry.segment.name": "test-transaction", - "server.address": mock.ANY, + SPANDATA.DEVICE_NAME: mock.ANY, "thread.id": mock.ANY, "thread.name": mock.ANY, } @@ -505,7 +505,7 @@ def my_agent(): "sentry.sdk.version": mock.ANY, "sentry.segment.id": mock.ANY, "sentry.segment.name": "test-transaction", - "server.address": mock.ANY, + SPANDATA.DEVICE_NAME: mock.ANY, "thread.id": mock.ANY, "thread.name": mock.ANY, } @@ -650,7 +650,7 @@ def my_agent(): "sentry.sdk.version": mock.ANY, "sentry.segment.id": mock.ANY, "sentry.segment.name": "test-transaction", - "server.address": mock.ANY, + SPANDATA.DEVICE_NAME: mock.ANY, "thread.id": mock.ANY, "thread.name": mock.ANY, } @@ -676,7 +676,7 @@ def my_agent(): "sentry.sdk.version": mock.ANY, "sentry.segment.id": mock.ANY, "sentry.segment.name": "test-transaction", - "server.address": mock.ANY, + SPANDATA.DEVICE_NAME: mock.ANY, "thread.id": mock.ANY, "thread.name": mock.ANY, } @@ -706,7 +706,7 @@ def my_agent(): "sentry.sdk.version": mock.ANY, "sentry.segment.id": mock.ANY, "sentry.segment.name": "test-transaction", - "server.address": mock.ANY, + SPANDATA.DEVICE_NAME: mock.ANY, "thread.id": mock.ANY, "thread.name": mock.ANY, } diff --git a/tests/tracing/test_span_streaming.py b/tests/tracing/test_span_streaming.py index 8aef2f7d17..6b3c826b3e 100644 --- a/tests/tracing/test_span_streaming.py +++ b/tests/tracing/test_span_streaming.py @@ -7,6 +7,7 @@ import pytest import sentry_sdk +from sentry_sdk.consts import SPANDATA from sentry_sdk.profiler.continuous_profiler import get_profiler_id from sentry_sdk.traces import ( NoOpStreamedSpan, @@ -1848,7 +1849,7 @@ def test_default_attributes(sentry_init, capture_envelopes): "sentry.segment.name": {"value": "test", "type": "string"}, "sentry.sdk.name": {"value": "sentry.python", "type": "string"}, "sentry.sdk.version": {"value": mock.ANY, "type": "string"}, - "server.address": {"value": "test-server", "type": "string"}, + SPANDATA.DEVICE_NAME: {"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"},