Skip to content

Conversation

@OiPunk
Copy link
Contributor

@OiPunk OiPunk commented Feb 10, 2026

Summary

Fixes #260 by making OpenAI tracing sanitization fail-safe for oversized span_data.input / span_data.output payloads.

What changed

  • Extended _sanitize_for_openai_tracing_api to also sanitize input and output fields (not just generation usage keys).
  • Added byte-size based truncation helpers:
    • Strings are truncated with a stable suffix (... [truncated]) while staying under the ingest limit.
    • Non-string oversized payloads are replaced with a compact metadata object (truncated, original_type, preview).
  • Kept behavior endpoint-aware: sanitization is only applied for the OpenAI tracing ingest endpoint, existing custom endpoint behavior is unchanged.

Tests

  • uv run ruff check src/agents/tracing/processors.py tests/test_trace_processor.py
  • uv run mypy src/agents/tracing/processors.py tests/test_trace_processor.py
  • uv run pytest tests/test_trace_processor.py -q
  • make format-check

Added test coverage for:

  • large string truncation
  • large non-string replacement
  • custom endpoint passthrough
  • unchanged small input path
  • helper edge-cases (within limit, suffix too large)

@seratch seratch marked this pull request as draft February 10, 2026 22:11
@OiPunk
Copy link
Contributor Author

OiPunk commented Feb 11, 2026

Addressed in commit aba2a66.

What changed:

  • Reworked _truncate_string_for_json_limit to use a proportional size estimate plus overflow-based trimming, instead of a binary search that repeatedly serializes many candidates.
  • This reduces repeated json.dumps() calls in the hot truncation path while preserving the same safety guarantee (<= max bytes).
  • Added regression coverage for escape-heavy strings to validate byte-limit behavior with JSON escaping.

Local verification:

  • uv run ruff check src/agents/tracing/processors.py tests/test_trace_processor.py
  • uv run mypy src/agents/tracing/processors.py
  • env -u ALL_PROXY -u all_proxy -u HTTPS_PROXY -u https_proxy -u HTTP_PROXY -u http_proxy -u NO_PROXY -u no_proxy uv run pytest tests/test_trace_processor.py -k "truncate_string_for_json_limit or truncates_large_input_for_openai_tracing" -q

@OiPunk
Copy link
Contributor Author

OiPunk commented Feb 11, 2026

Added one follow-up test commit (3f5a86c) to cover the max_bytes == suffix_size branch in _truncate_string_for_json_limit, so the updated truncation logic is fully exercised by the targeted trace run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Truncate span input when input is too large

2 participants