Skip to main content
Applies to:
  • Plan -
  • Deployment -

Summary

Issue: The Download this trace option in the UI can fail for very large traces, sometimes showing an Invalid string length error. Cause: The UI fetches the trace spans through /btql and then serializes the full trace payload to JSON for download. For very large traces, that serialization can exceed the JavaScript runtime’s maximum string size. Resolution: Fetch the trace spans through the Braintrust API with pagination instead of using the UI download button.

Diagnosing the failure

Open browser DevTools and check the Network and Console tabs when the download fails. An Invalid string length error is consistent with a very large trace payload failing during JSON serialization.

Resolution steps

Fetch the trace via SQL

Use SQL to retrieve spans for the trace with full payloads and stable ordering:
SELECT *
FROM project_logs('<PROJECT_ID>', shape => 'spans')
WHERE root_span_id = '<ROOT_SPAN_ID>'
ORDER BY _pagination_key ASC
LIMIT 100
SETTINGS preview_length = -1;
If pagination is required, fetch the next page with the returned cursor:
SELECT *
FROM project_logs('<PROJECT_ID>', shape => 'spans')
WHERE root_span_id = '<ROOT_SPAN_ID>'
ORDER BY _pagination_key ASC
LIMIT 100
OFFSET '<CURSOR_FROM_PREVIOUS_RESPONSE>'
SETTINGS preview_length = -1;

Reduce trace size at logging time

If large inline payloads are causing repeated issues, move large data to attachments to reduce the size of span payloads during logging and export. See “Optimize large trace logging with attachments” troubleshooting article.

Notes

  • Filtering by root_span_id is an efficient way to retrieve a known trace.
  • _pagination_key provides a stable ordering for pagination.