Skip to content
Closed
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
2 changes: 1 addition & 1 deletion sentry_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
6 changes: 6 additions & 0 deletions sentry_sdk/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
"""
Comment thread
alexander-alderman-webb marked this conversation as resolved.

GEN_AI_AGENT_NAME = "gen_ai.agent.name"
"""
The name of the agent being used.
Expand Down
2 changes: 1 addition & 1 deletion sentry_sdk/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment thread
alexander-alderman-webb marked this conversation as resolved.

environment = options.get("environment")
if environment:
Expand Down
4 changes: 2 additions & 2 deletions tests/integrations/boto3/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
}
Expand Down
8 changes: 4 additions & 4 deletions tests/integrations/grpc/test_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions tests/integrations/grpc/test_grpc_aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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,
}
Expand Down
14 changes: 7 additions & 7 deletions tests/integrations/huggingface_hub/test_huggingface_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
}
Expand Down
8 changes: 4 additions & 4 deletions tests/integrations/logging/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions tests/integrations/loguru/test_loguru.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions tests/test_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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",
},
Expand Down Expand Up @@ -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",
},
Expand Down
4 changes: 2 additions & 2 deletions tests/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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",
},
Expand Down
14 changes: 7 additions & 7 deletions tests/tracing/test_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
}
Expand All @@ -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,
}
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
}
Expand All @@ -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,
}
Expand Down Expand Up @@ -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,
}
Expand Down
3 changes: 2 additions & 1 deletion tests/tracing/test_span_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"},
Expand Down
Loading