8000 feat(logs): Add sdk name and version as log attributes (#4262) · getsentry/sentry-python@97c435a · GitHub
[go: up one dir, main page]

Skip to content

Commit 97c435a

Browse files
authored
feat(logs): Add sdk name and version as log attributes (#4262)
Docs: https://develop-docs-git-abhi-logs-sdk-developer-documentation.sentry.dev/sdk/telemetry/logs/#default-attributes > sentry.sdk.name: The name of the SDK that sent the log > sentry.sdk.version: The version of the SDK that sent the log convention docs: - `sentry.sdk.name`: https://getsentry.github.io/sentry-conventions/generated/attributes/sentry.html#sentrysdkname - `sentry.sdk.version`: https://getsentry.github.io/sentry-conventions/generated/attributes/sentry.html#sentrysdkversion resolves https://linear.app/getsentry/issue/PY-1/
1 parent acf508c commit 97c435a

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

sentry_sdk/client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,9 @@ def _capture_experimental_log(self, current_scope, log):
895895
return
896896
isolation_scope = current_scope.get_isolation_scope()
897897

898+
log["attributes"]["sentry.sdk.name"] = SDK_INFO["name"]
899+
log["attributes"]["sentry.sdk.version"] = SDK_INFO["version"]
900+
898901
server_name = self.options.get("server_name")
899902
if server_name is not None and SPANDATA.SERVER_ADDRESS not in log["attributes"]:
900903
log["attributes"][SPANDATA.SERVER_ADDRESS] = server_name

tests/test_logs.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +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
14+
from sentry_sdk.consts import SPANDATA, VERSION
1515

1616
minimum_python_37 = pytest.mark.skipif(
1717
sys.version_info < (3, 7), reason="Asyncio tests need Python >= 3.7"
@@ -186,6 +186,8 @@ def test_logs_attributes(sentry_init, capture_envelopes):
186186
assert "sentry.release" in logs[0]["attributes"]
187187
assert logs[0]["attributes"]["sentry.message.parameters.my_var"] == "some value"
188188
assert logs[0]["attributes"][SPANDATA.SERVER_ADDRESS] == "test-server"
189+
assert logs[0]["attributes"]["sentry.sdk.name"] == "sentry.python"
190+
assert logs[0]["attributes"]["sentry.sdk.version"] == VERSION
189191

190192

191193
@minimum_python_37

0 commit comments

Comments
 (0)
0