fix(propagation): coerce non-string metadata values to string#1680
Open
aryxnn wants to merge 4 commits into
Open
fix(propagation): coerce non-string metadata values to string#1680aryxnn wants to merge 4 commits into
aryxnn wants to merge 4 commits into
Conversation
Allows propagate_attributes to accept and automatically convert non-string metadata values (int, float, bool) to strings instead of silently dropping them. This resolves tracing compatibility issues with LangGraph integrations.
|
Aryan Srivastava seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
35139d4 to
1d1910f
Compare
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.
Allows propagate_attributes to accept and automatically convert non-string metadata values (int, float, bool) to strings instead of silently dropping them. This resolves tracing compatibility issues with LangGraph integrations.
What does this PR do?
Fixes #
Type of change
Verification
List the main commands you ran:
Checklist
code_review.md..env.templateif needed.Greptile Summary
This PR allows
propagate_attributesto accept non-string metadata values (int,float,bool, and any other type) and automatically coerces them to strings viastr()rather than silently dropping them. The change fixes tracing compatibility with LangGraph integrations that inject non-string metadata.metadataparameter (and the internal_propagate_attributesequivalent) is widened fromDict[str, str]toDict[str, Any], andNonevalues in the metadata dict are now explicitly skipped before the string-length validation step.int,float, andboolvalues, verifying the resulting string representations in child spans.Confidence Score: 4/5
The change is small and well-targeted; the coercion path is safe for the common cases and the existing validation guard (200-char limit) still applies after coercion.
The core logic is correct and the new test exercises int, float, and bool. The main open question is whether Python-style 'True'/'False' is the right representation for booleans — downstream consumers expecting JSON-style 'true'/'false' would silently get wrong values. The docstring also still describes the old 'must be strings' constraint, which could confuse users reading the API docs.
langfuse/_client/propagation.py — specifically the boolean coercion representation and the outdated docstring note.
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A["propagate_attributes called with metadata dict"] --> B{metadata is None?} B -- Yes --> Z[Skip metadata] B -- No --> C[Iterate over key-value pairs] C --> D{value is None?} D -- Yes --> C D -- No --> E{value is a str?} E -- Yes --> F[string_value = value] E -- No --> G["string_value = str(value)"] F --> H{len <= 200 chars?} G --> H H -- No --> I[Log warning and drop key] H -- Yes --> J[Add to validated_metadata] J --> C J --> K[Set propagated OTel attribute]Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "fix(propagation): coerce non-string meta..." | Re-trigger Greptile