fix(tracing): preserve empty-string metadata values#834
Open
i-anubhav-anand wants to merge 1 commit into
Open
Conversation
_flattenAndSerializeMetadata gated each serialized metadata value behind a
truthiness check (`if (serialized)`), which silently dropped empty-string
values while keeping 0 and false. So metadata { a: "", b: "x" } emitted only
b. _serialize only returns undefined for null/undefined, so checking
`!== undefined` keeps "" (and other falsy-but-present values) while still
skipping null/undefined. Applied to both the scalar and object-entry paths.
Adds an integration test asserting an empty-string metadata value is exported
(fails before: the attribute was absent).
|
@i-anubhav-anand is attempting to deploy a commit to the langfuse Team on Vercel. A member of the Team first needs to authorize it. |
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.
Empty-string metadata values are silently dropped. In
_flattenAndSerializeMetadata:So
metadata: { a: "", b: "x", c: 0, d: false }emitsb,c("0"),d("false") but silently dropsa— inconsistent, since0andfalsesurvive._serializereturnsundefinedonly fornull/undefined, so switching the guard toif (serialized !== undefined)preserves""(and any other falsy-but-present value) while still skippingnull/undefined. Applied to both the scalar-metadata branch and the object-entry loop.Test
Adds an integration test (
tracing.integration.test.ts) asserting an empty-string metadata value is exported. Fails before (attribute absent), passes after.prettier/eslint/tscclean (pre-commit hook).Type of change
Greptile Summary
This PR fixes a silent data-loss bug in
_flattenAndSerializeMetadatawhere empty-string metadata values ("") were dropped because the truthiness guardif (serialized)evaluated""as falsy. The fix changes both guards toserialized !== undefined, which aligns with_serialize's contract of returningundefinedonly fornull/undefinedinputs.packages/tracing/src/attributes.ts: Twoif (serialized)guards replaced withif (serialized !== undefined)in the scalar and object-entry branches of_flattenAndSerializeMetadata.tests/integration/tracing.integration.test.ts: Integration test added that verifies an empty-string metadata value appears as a span attribute after export.Confidence Score: 5/5
Safe to merge — the change is a minimal, targeted guard fix that preserves existing behavior for all non-empty values while correctly retaining empty strings.
The two-line change is narrowly scoped:
_serializeis guaranteed to return either astringorundefined, so!== undefinedis the correct predicate. All previously-passing values (non-empty strings, numbers, booleans, objects) continue to pass the new guard unchanged, and only the previously-dropped""case is now correctly preserved. The integration test directly validates the fixed scenario.No files require special attention — both changed files are straightforward and self-contained.
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A["_flattenAndSerializeMetadata(metadata, type)"] --> B{metadata null/undefined?} B -- Yes --> C[return empty object] B -- No --> D{Is metadata non-object or Array?} D -- Yes --> E["serialized = _serialize(metadata)"] E --> F{"serialized !== undefined?\n(was: if serialized)"} F -- Yes --> G["metadataAttributes[prefix] = serialized"] F -- No --> C D -- No --> H["for each [key, value] in metadata"] H --> I{"typeof value === 'string'?"} I -- Yes --> J["serialized = value (direct, e.g. '')"] I -- No --> K["serialized = _serialize(value)"] J --> L{"serialized !== undefined?\n(was: if serialized — dropped '')"} K --> L L -- Yes --> M["metadataAttributes[prefix.key] = serialized"] L -- No --> H G --> N[return metadataAttributes] M --> NReviews (1): Last reviewed commit: "fix(tracing): preserve empty-string meta..." | Re-trigger Greptile