Skip to content

Commit acf508c

Browse files
authored
feat(logs): Add server.address to logs (#4257)
Docs: https://develop-docs-git-abhi-logs-sdk-developer-documentation.sentry.dev/sdk/telemetry/logs/#default-attributes > [BACKEND SDKS ONLY] `server.address`: The address of the server that sent the log. Equivalent to server_name we attach to errors and transactions. `server.address` convention docs: https://getsentry.github.io/sentry-conventions/generated/attributes/server.html#serveraddress resolves https://linear.app/getsentry/issue/LOGS-33
1 parent e05ed0a commit acf508c

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

sentry_sdk/client.py

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from sentry_sdk.tracing import trace
2828
from sentry_sdk.transport import BaseHttpTransport, make_transport
2929
from sentry_sdk.consts import (
30+
SPANDATA,
3031
DEFAULT_MAX_VALUE_LENGTH,
3132
DEFAULT_OPTIONS,
3233
INSTRUMENTER,
@@ -894,6 +895,10 @@ def _capture_experimental_log(self, current_scope, log):
894895
return
895896
isolation_scope = current_scope.get_isolation_scope()
896897

898+
server_name = self.options.get("server_name")
899+
if server_name is not None and SPANDATA.SERVER_ADDRESS not in log["attributes"]:
900+
log["attributes"][SPANDATA.SERVER_ADDRESS] = server_name
901+
897902
environment = self.options.get("environment")
898903
if environment is not None and "sentry.environment" not in log["attributes"]:
899904
log["attributes"]["sentry.environment"] = environment

tests/test_logs.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from sentry_sdk.envelope import Envelope
1212
from sentry_sdk.integrations.logging import LoggingIntegration
1313
from sentry_sdk.types import Log
14+
from sentry_sdk.consts import SPANDATA
1415

1516
minimum_python_37 = pytest.mark.skipif(
1617
sys.version_info < (3, 7), reason="Asyncio tests need Python >= 3.7"
@@ -161,7 +162,7 @@ def test_logs_attributes(sentry_init, capture_envelopes):
161162
"""
162163
Passing arbitrary attributes to log messages.
163164
"""
164-
sentry_init(_experiments={"enable_logs": True})
165+
sentry_init(_experiments={"enable_logs": True}, server_name="test-server")
165166
envelopes = capture_envelopes()
166167

167168
attrs = {
@@ -184,6 +185,7 @@ def test_logs_attributes(sentry_init, capture_envelopes):
184185
assert logs[0]["attributes"]["sentry.environment"] == "production"
185186
assert "sentry.release" in logs[0]["attributes"]
186187
assert logs[0]["attributes"]["sentry.message.parameters.my_var"] == "some value"
188+
assert logs[0]["attributes"][SPANDATA.SERVER_ADDRESS] == "test-server"
187189

188190

189191
@minimum_python_37

0 commit comments

Comments
 (0)