fix(logger): auto-convert non-string metadata values to strings#488
Draft
fix(logger): auto-convert non-string metadata values to strings#488
Conversation
Added auto-conversion of non-string metadata and dataset_metadata values to strings to ensure consistent logging behavior across all span methods and the add_single_llm_span_trace API. Included unit tests to prevent future regressions.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #488 +/- ##
==========================================
+ Coverage 81.82% 81.85% +0.03%
==========================================
Files 96 96
Lines 9223 9239 +16
==========================================
+ Hits 7547 7563 +16
Misses 1676 1676 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
User description
Added auto-conversion of non-string metadata and dataset_metadata values to strings to ensure consistent logging behavior across all span methods and the add_single_llm_span_trace API.
Included unit tests to prevent future regressions.
Shortcut:
sc-54947
Description:
Fixes sc-54947 - passing
intorboolmetadata values to any span method (add_llm_span,add_tool_span, etc.) caused the span to be silently dropped with no error surfaced to the user.start_trace()already auto-converts non-string metadata values to strings via_convert_metadata_value(), but none of the span methods did. When a user passed metadata like{"count": 1, "enabled": True}, the raw values reached the PydanticBaseStepmodel which expectsDict[str, str], triggering aValidationError. The@warn_catch_exceptiondecorator then swallowed the error and returnedNone- the span was never created, and the user saw nothing.Reproduction:
Fix
Applied the same conversion pattern from
start_trace()to all 7 span methods:add_single_llm_span_trace()(+dataset_metadata)add_llm_span()add_retriever_span()add_tool_span()add_protect_span()add_workflow_span()add_agent_span()For each method:
dict[str, str]->dict[str, MetadataValue](where `MetadataValue = str | bool | int | float | None)kwargsconstruction:Tests:
Generated description
Below is a concise technical summary of the changes proposed in this PR:
Ensures that non-string metadata values are automatically converted to strings across all span logging methods to prevent silent failures caused by validation errors. This change aligns the behavior of various span types with the existing trace logging logic and includes comprehensive regression tests.
add_llm_span,add_tool_span, and other span methods correctly handle and stringify diverse metadata types without dropping spans.Modified files (1)
Latest Contributors(2)
int,bool, andfloatmetadata values to strings inGalileoLoggerspan methods to ensure compatibility with the internal schema.Modified files (1)
Latest Contributors(2)