Repository navigation
fix: preserve surrogate-containing metadata in OTLP - #2084
Open
DiadkoShmek wants to merge 2 commits into
Open
DiadkoShmek wants to merge 2 commits into
DiadkoShmek wants to merge 2 commits into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Keep metadata values containing surrogate code points when encoding spans as OTLP. For example, a filename returned by
os.fsdecode(b"file_\xff.txt")contains U+DCFF.ensure_ascii=Falseleaves it literally in the JSON string; protobuf rejects that invalid UTF-8 attribute, so the metadata key disappears while the span and sibling attributes survive.After JSON serialization, escape surrogate code points while retaining ordinary Unicode characters, compact structured values, and the existing plain-string/EventSerializer dispatch. Both plain strings and nested values follow the same transport-safe path. This is a metadata-value fix; attribute names and other span fields are unchanged.
Verification
encode_spans, with lone high/low surrogates, nested values, mixed Unicode/surrogates, and an ordinary Unicode control.1fc854dd2b241cf8e3dac38bfd5907ff2fe365e3: 4 failed, 1 passed, specifically because the affected metadata key is missing after OTLP encoding. Sibling metadata and the span are preserved.uv run --frozen pytest tests/unit/test_otel.py -q: 102 passed, 2 skipped.uv run --frozen ruff check .: passed.uv run --frozen mypy langfuse --no-error-summary: passed.git diff --check: passed.uv sync --locked.A separate AI review reran 13 focused OTLP/string-subclass/masking cases and checked protobuf byte roundtrips. Full unit, e2e and live-provider suites were not run; the tests above need no server or provider. No generated API files changed.
AI disclosure: Codex prepared and tested this change, with a separate AI review of the complete diff. No personal human code review is claimed.
The metadata fix appears sound, but the new test's import must move before merging to satisfy the repository rule.
Summary
Escapes surrogate code points after metadata values become JSON, allowing those values to reach OTLP without escaping ordinary Unicode.
Reviews (1) · Last reviewed commit: "fix: preserve surrogate-containing metad..." · Reviewed by Greptile