Skip to main content
Applies to:
  • Plan - Any
  • Deployment - Any
  • Use case - Load traces exported from another observability system or database into Braintrust project logs

Summary

To import historical traces, convert each exported trace into Braintrust span rows and upload them. For file-based imports, write the rows to JSONL and upload them with bt sync push. For programmatic imports, write the spans with the Python SDK. In both cases, derive each span’s row id from stable identifiers in the source data, such as the source trace ID combined with the span ID. A trace ID alone gives every span in the trace the same id, so each span replaces the one before it. Stable IDs let you re-run the import to fix mappings or add scores without creating duplicate traces.

What is happening

Every exporter uses its own schema, so an import needs a mapping step from the source fields to Braintrust span fields. Braintrust identifies each span row by its id. Writing a row with an id that already exists replaces that row. An import that generates random IDs creates a second copy of every trace each time it runs. An import that derives IDs from the source data updates the existing rows instead. Each row’s span_id, root_span_id, and span_parents place it in a trace. root_span_id is the span_id of the trace’s root span, and span_parents lists the parent span’s span_id. When you upload rows with bt sync push, a row without root_span_id and span_parents becomes its own single-span trace, and a row without id or span_id gets a new ID on every upload. The time a span was ingested is stored in created. bt sync push doesn’t upload the created value from your file, and the SDK sets created when it writes the span. Imported traces therefore show the import time in created. The original start and end times go in metrics.start and metrics.end.

Fix or suggestion

Option 1: Upload JSONL files with bt sync push

  1. Export the traces from the source system. Keep each child span linked to its trace and parent.
  2. Convert each source span into one JSON object per line. Use these fields: A root span and one LLM child span look like this:
  3. Save the rows to one or more .jsonl files in a directory.
  4. Upload the directory to your project’s logs:
    bt sync push saves its progress for each input path. Running the same command again after a completed upload doesn’t upload anything. To upload corrected files or added scores from the same directory, add --force. Because the row IDs are stable, the upload replaces the existing spans:
For a complete worked example, including a converter for OpenTelemetry GenAI spans and a script that runs bt sync push, see Analyzing agent traces from Hugging Face.

Option 2: Write spans with the Python SDK

The SDK sets root_span_id and span_parents when you start a child span from its parent span. Pass a stable id on each span so that a re-run replaces the rows it wrote before. On the root span, also pass a stable span_id and root_span_id. Otherwise the SDK generates a new trace ID on every run, and links to a trace from an earlier run stop working. Set the original times with the start_time parameter on start_span() and the end_time parameter on end():
For deeper trees, call start_span() on the span that is the parent in the source data.

How to confirm it worked

  • Open a few imported traces in Logs. Verify that the span tree, input, output, metadata, and metrics match the source.
  • Re-run the import for a small subset, with --force if you use bt sync push. The number of traces in the project stays the same.

Notes

  • Dashboard charts group spans by created by default, so imported traces appear at the import time. To chart them by when they ran, see Configure Monitor chart time dimension.
  • To write scores onto imported traces, add them to the rows as scores and re-run the import with the same IDs. With bt sync push, add --force. The cookbook uses this approach to attach LLM-judge results.