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
47 changes: 47 additions & 0 deletions sdk-repro-test-python/24/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Reproduction for sdk-repro-test-python#24

**Issue:** https://github.com/getsentry/sdk-repro-test-python/issues/24

## Description

With `send_default_pii=True` and `enable_logs=True`, calling
`set_user({"email": "ada@example.com", "username": None})` adds
`user.name: "None"` (a string) to every log. The scope copies each user field
into telemetry attributes when the key is present, even when its value is
`None`, and attribute serialization then turns `None` into the string `"None"`.
Spans in streaming mode get the user attributes the same way.

`repro.py` records envelopes with an in-memory transport, sends one log, and
prints the `user.*` attributes on it. It exits 1 while the bug is present and
0 once it is fixed.

## Steps to Reproduce

1. Run the reproduction against the published SDK version from the issue:
```bash
uv run repro.py
```

2. To run it against an SDK checkout instead, clone
`getsentry/sdk-repro-test-python` next to this repo and install it into a
fresh environment:
```bash
uv venv --python 3.12 .venv-sdk
VIRTUAL_ENV=.venv-sdk uv pip install -e ../../../sdk-repro-test-python
.venv-sdk/bin/python repro.py
```

## Expected Behavior

Only `user.email` is set on the log. `user.name` is left out.

## Actual Behavior

```
user attributes on the log: {'user.name': {'value': 'None', 'type': 'string'}, 'user.email': {'value': 'ada@example.com', 'type': 'string'}}
```

## Environment

- Python: 3.12
- sentry-sdk: 2.64.0 (also on `main` of getsentry/sdk-repro-test-python, version 2.75.0)
10 changes: 10 additions & 0 deletions sdk-repro-test-python/24/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[project]
name = "repro-sdk-repro-test-python-24"
version = "0.0.0"
requires-python = ">=3.12"
dependencies = [
"sentry-sdk==2.64.0",
]

[tool.uv]
package = false
68 changes: 68 additions & 0 deletions sdk-repro-test-python/24/repro.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""
Reproduction for getsentry/sdk-repro-test-python#24

`set_user` with a field set to `None` makes that field show up on logs as the
literal string "None" (for example `user.name: "None"`).

An in-memory transport records envelopes, so nothing leaves the machine.

Exits 1 while the bug is present, 0 once it is fixed.
"""

import sys

import sentry_sdk
from sentry_sdk.transport import Transport

envelopes = []


class Capture(Transport):
def capture_envelope(self, envelope):
envelopes.append(envelope)


def main():
sentry_sdk.init(
dsn="https://public@example.com/1",
transport=Capture(),
enable_logs=True,
send_default_pii=True,
)
print("sentry_sdk", sentry_sdk.VERSION, "from", sentry_sdk.__file__)

# `username` is None: it should be left out, not sent as "None".
sentry_sdk.set_user({"email": "ada@example.com", "username": None})
sentry_sdk.logger.info("hello")
sentry_sdk.flush()

user_attrs = {}
for envelope in envelopes:
for item in envelope.items:
if item.headers.get("type") == "log":
for log in item.payload.json["items"]:
user_attrs.update(
{
k: v
for k, v in log["attributes"].items()
if k.startswith("user.")
}
)

print("user attributes on the log:", user_attrs)

if not user_attrs:
print("FAIL: no log captured")
return 1

bad = {k: v for k, v in user_attrs.items() if v.get("value") == "None"}
if bad:
print('BUG: None user fields were sent as the string "None":', bad)
return 1

print("OK: no None user fields were stringified")
return 0


if __name__ == "__main__":
sys.exit(main())
45 changes: 45 additions & 0 deletions sdk-repro-test-python/24/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading