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

# Add to dataset captures root span only

> [!NOTE]
>
> **Applies to:**
>
> * Plan - Any
> * Deployment - Braintrust-hosted, Self-hosted
> *
> * Use case - Adding full traces to datasets via UI

## Summary

The **Add to dataset** action adds the span you selected, not every span in the trace tree. Which approach you need depends on the row shape you want:

* To capture the whole trace as a single dataset row, use **Add full trace to dataset** from project logs. The row's `input` stores a reference to the trace rather than a copy of its spans.
* To create one dataset row per span, insert the spans with the SDK, carrying `span_id`, `root_span_id`, and `span_parents` in each row's metadata.

## Resolution steps

### Option 1: Add the full trace by reference

1. Go to [** Logs**](https://www.braintrust.dev/app/~/logs) and select the trace or span.
2. Click  **Add to** >  **Add full trace to dataset**, then choose the dataset.

Braintrust creates one row per trace, so selecting several spans from the same trace does not produce duplicate rows. The row renders with the read-only **Trace** viewer, which shows the trace's metrics, input, and output inline.

Because the row holds a reference rather than a copy, it depends on the trace remaining available. If the trace is deleted or ages out of your [retention window](https://docs.braintrust.dev/admin/data-management/retention.md), the row shows **Referenced trace not found**. For details, see [Promote traces from logs](https://docs.braintrust.dev/annotate/datasets/create.md#promote-traces-from-logs).

### Option 2: Add one row per span programmatically

Use this approach when you need each span to become its own dataset row.

#### 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 it with `span_id`, `root_span_id`, and `span_parents` fields.

```python 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
        }
    )

```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.