> ## Documentation Index
> Fetch the complete documentation index at: https://braintrust.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Add to dataset captures root span only

export const plans_0 = "Any"

export const deployments_0 = "Braintrust-hosted, Self-hosted"

export const data_plane_version_0 = undefined

export const use_case_0 = "Use case - Adding full traces to datasets via UI"

<Note>
  **Applies to:**

  * Plan - {plans_0}
  * Deployment - {deployments_0}
  * {data_plane_version_0}
  * {use_case_0}
</Note>

## 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.

```python theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
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.

```text theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
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
        }
    )

```
