Add to dataset captures root span only

Last updated: March 3, 2026

Applicable To

Plans: Free, Pro, Enterprise

Deployments: Braintrust Hosted, Hybrid

Use case: Adding full traces to datasets via UI

Summary

When using "Add to dataset" from the UI on a trace, only the root span is added to the dataset instead of all spans in the trace tree. This occurs because the UI action is designed to add individual spans rather than entire trace trees. To add all spans from a trace, use the Dataset Insert API programmatically with proper span_id, root_span_id, and span_parents metadata.

Resolution Steps

Add full trace programmatically

Step 1: Initialize dataset

Import the SDK and initialize your target dataset.

from braintrust import init_dataset

dataset = init_dataset(project="project-name", name="dataset-name")

Step 2: Insert all spans with trace metadata

Iterate through each span in the trace and insert with span_id, root_span_id, and span_parents fields.

for span in trace_spans:
    dataset.insert(
        input=span.input,
        expected=span.expected,
        metadata={
            "span_id": span.id,
            "root_span_id": trace_root_id,
            "span_parents": span.parent_ids
        }
    )