8000 feat(logs): Add server.address to logs by AbhiPrasad · Pull Request #4257 · getsentry/sentry-python · GitHub
[go: up one dir, main page]

Skip to content

feat(logs): Add server.address to logs #4257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 9, 2025
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. Retry
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions sentry_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from sentry_sdk.tracing import trace
from sentry_sdk.transport import BaseHttpTransport, make_transport
from sentry_sdk.consts import (
SPANDATA,
DEFAULT_MAX_VALUE_LENGTH,
DEFAULT_OPTIONS,
INSTRUMENTER,
Expand Down Expand Up @@ -894,6 +895,10 @@ def _capture_experimental_log(self, current_scope, log):
return
isolation_scope = current_scope.get_isolation_scope()

server_name = self.options.get("server_name")
if server_name is not None and SPANDATA.SERVER_ADDRESS not in log["attributes"]:
log["attributes"][SPANDATA.SERVER_ADDRESS] = server_name

environment = self.options.get("environment")
if environment is not None and "sentry.environment" not in log["attributes"]:
log["attributes"]["sentry.environment"] = environment
Expand Down
4 changes: 3 additions & 1 deletion tests/test_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from sentry_sdk.envelope import Envelope
from sentry_sdk.integrations.logging import LoggingIntegration
from sentry_sdk.types import Log
from sentry_sdk.consts import SPANDATA

minimum_python_37 = pytest.mark.skipif(
sys.version_info < (3, 7), reason="Asyncio tests need Python >= 3.7"
Expand Down Expand Up @@ -161,7 +162,7 @@ def test_logs_attributes(sentry_init, capture_envelopes):
"""
Passing arbitrary attributes to log messages.
"""
sentry_init(_experiments={"enable_logs": True})
sentry_init(_experiments={"enable_logs": True}, server_name="test-server")
envelopes = capture_envelopes()

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


@minimum_python_37
Expand Down
Loading
0