fix(tracing): truncate oversized span input/output for OpenAI ingest#2459
fix(tracing): truncate oversized span input/output for OpenAI ingest#2459OiPunk wants to merge 3 commits intoopenai:mainfrom
Conversation
|
Addressed in commit aba2a66. What changed:
Local verification:
|
|
Added one follow-up test commit (3f5a86c) to cover the |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3f5a86cc97
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| preview = str(value) | ||
| if len(preview) > 512: | ||
| preview = preview[:512] + self._OPENAI_TRACING_STRING_TRUNCATION_SUFFIX |
There was a problem hiding this comment.
Avoid materializing full preview for oversized non-string fields
When span_data.input/output is an oversized non-string value, this path computes preview = str(value) before truncating it, which forces Python to stringify the entire object first. For very large dict/list payloads (the exact case this sanitization is meant to handle), that can allocate a huge temporary string and add significant CPU/memory pressure, potentially stalling or crashing export before the truncated payload is sent.
Useful? React with 👍 / 👎.
Summary
Fixes #260 by making OpenAI tracing sanitization fail-safe for oversized
span_data.input/span_data.outputpayloads.What changed
_sanitize_for_openai_tracing_apito also sanitizeinputandoutputfields (not just generation usage keys).... [truncated]) while staying under the ingest limit.truncated,original_type,preview).Tests
uv run ruff check src/agents/tracing/processors.py tests/test_trace_processor.pyuv run mypy src/agents/tracing/processors.py tests/test_trace_processor.pyuv run pytest tests/test_trace_processor.py -qmake format-checkAdded test coverage for:
within limit,suffix too large)