fix(propagation): coerce non-string metadata values to string#1681
Open
aryxnn wants to merge 1 commit into
Open
fix(propagation): coerce non-string metadata values to string#1681aryxnn wants to merge 1 commit into
aryxnn wants to merge 1 commit into
Conversation
|
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. |
076e5a2 to
1671682
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 fixes
propagate_attributesto accept non-string metadata values (int, float, bool) and coerce them to strings rather than silently dropping them, improving compatibility with LangGraph integrations that pass typed metadata.propagation.py: Widens themetadatatype hint fromDict[str, str]toDict[str, Any], adds an explicitNone-skip guard, and converts non-string values withstr()before the existing_validate_string_valuecheck.test_propagate_attributes.py: Adds a new test covering int, float, and bool coercion; note that the asserted"True"forbool_valmatches Python'sstr(True)behaviour, not JSON-canonical"true".Confidence Score: 4/5
Safe to merge with minor follow-up consideration around bool stringification format.
The coercion logic is straightforward and an improvement over silently dropping values. The main open question is whether str(True) → 'True' is the right representation for downstream consumers that expect JSON-canonical 'true', and whether complex types (dict, list) should be explicitly rejected rather than stringified with Python repr. Neither concern blocks existing functionality — they are edge-case surprises rather than regressions.
The coercion path in langfuse/_client/propagation.py lines 287-291 deserves a second look specifically for bool and complex-type handling.
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[metadata dict entry] --> B{value is None?} B -- yes --> C[skip / drop] B -- no --> D{isinstance str?} D -- yes --> E[use as-is] D -- no --> F["str(value) — coerce to string\n(bool→'True', int→'42', dict→repr)"] E --> G[_validate_string_value] F --> G G -- len > 200 chars --> H[warn + drop] G -- not a str --> I[warn + drop] G -- valid --> J[add to validated_metadata] J --> K[set propagated attribute on context]Prompt To Fix All With AI
Reviews (1): Last reviewed commit: "fix(propagation): coerce non-string meta..." | Re-trigger Greptile