-
Notifications
You must be signed in to change notification settings - Fork 3.4k
fix(tracing): prevent RecursionError in truncation of truncated previews #2857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -291,6 +291,11 @@ def _truncate_json_value_for_limit(self, value: Any, max_bytes: int) -> Any: | |
| return self._truncate_string_for_json_limit(value, max_bytes) | ||
|
|
||
| if isinstance(value, dict): | ||
| # Avoid re-truncating our own truncated preview dicts, which | ||
| # would cause infinite recursion (the preview dict contains bool | ||
| # values that get wrapped into new preview dicts, and so on). | ||
| if value.get("truncated") is True and "original_type" in value and "preview" in value: | ||
| return value | ||
|
Comment on lines
+302
to
+303
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Fresh evidence: although this guard now also checks Useful? React with 👍 / 👎. |
||
| return self._truncate_mapping_for_json_limit(value, max_bytes) | ||
|
|
||
| if isinstance(value, list): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The early return in
_truncate_json_value_for_limitnow treats any dict withtruncated=True,original_type, andpreviewas an internal preview object and skips truncation. If user-provided span data legitimately uses those keys and also contains large additional fields, root-level truncation returns the oversized dict unchanged, which can exceed_OPENAI_TRACING_MAX_FIELD_BYTESand cause export rejection or dropped tracing data. This check should only bypass truncation for SDK-created preview dicts (for example by requiring the exact key set or using a dedicated sentinel).Useful? React with 👍 / 👎.