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

# Import traces from Langfuse or Braintrust

> Connect Langfuse (cloud or self-hosted) or Braintrust with its API keys, import up to 7 days of history, and keep new traces in sync every 5 minutes without re-instrumenting

If your agent already sends traces to **Langfuse** or logs to **Braintrust**,
Agnost AI can read them from there. You connect the source with its API keys,
choose how much history to import, and Agnost AI keeps new traces in sync every
5 minutes. You don't change your code, your SDK, or your exporter, and nothing
changes in the source tool: Agnost AI only reads from it.

Imported traces become Agnost conversations and events, so Conversations,
Patterns, Alerts, Tools and the [Architecture](https://docs.agnost.ai/architecture.md) page work on them
the same way they work on data your SDK sends.

## Where to find it

* **Settings > Data sources.** The section lists connected sources. With none
  connected, choose the **Langfuse** or **Braintrust** button to open its connect
  form.
* **Onboarding.** A new project's setup page shows **1 click migration:** with the
  same two buttons. While a source is connected and nothing has arrived yet, Home
  shows the import's progress instead of the setup steps, and opens your data as
  soon as the first traces arrive.

You need to be signed in to connect a source. The demo workspace can't connect
one.

## Connect Langfuse

1. Under **Hosting**, choose **EU cloud** (`https://cloud.langfuse.com`), **US
   cloud** (`https://us.cloud.langfuse.com`), or **Self-hosted**.
2. For **Self-hosted**, enter your Langfuse **Host URL**, for example
   `https://langfuse.your-company.com`.
3. Enter the **Public key** (starts with `pk-lf-`) and **Secret key** (starts with
   `sk-lf-`). They're in **Langfuse > Project settings > API keys**. The import
   reads the Langfuse project these keys belong to.
4. Choose **Past data to import** (see [Backfill](#backfill)).
5. Choose **Import traces**, or **Connect Langfuse** if you chose **None**.

Agnost AI checks the keys with Langfuse before saving them. If Langfuse rejects
them, the form says so and nothing is saved. The most common cause is a key from
the other region: EU and US cloud keys only work on their own host.

### Self-hosted Langfuse

A self-hosted Langfuse works if Agnost AI can reach it from the internet. The Host
URL must:

* use `https://`, on port 443 or 8443;
* resolve to a public IP address (private, loopback, link-local and cloud
  metadata addresses are refused);
* not include a username or password.

Agnost AI reads the same public API your Langfuse Cloud project would serve, so
the self-hosted instance needs to be recent enough to serve
`/api/public/v2/observations`.

## Connect Braintrust

1. Under **Hosting**, choose **Braintrust cloud** (`https://api.braintrust.dev`) or
   **Self-hosted**. For **Self-hosted**, enter your Braintrust **API URL**, for
   example `https://braintrust.your-company.com`. The same rules as a self-hosted
   Langfuse URL apply.
2. Enter the **API key**. It's in **Braintrust > Settings > API keys**. Use a key
   from the Braintrust organization your agent logs to.
3. Choose **Find projects**. Agnost AI lists the projects the key can see, sorted by
   name, with a search box when there are many.
4. Under **Projects**, pick the projects your agent logs to, **1 to 10** of them.
5. Choose **Past data to import**, then **Import logs** (or **Connect Braintrust**
   if you chose **None**).

### Why you pick 1 to 10 Braintrust projects

Agnost AI reads Braintrust logs with BTQL queries. Braintrust allows 20 BTQL
queries a minute per organization, and that budget is shared with your own
scripts and tools. Every project the import reads costs at least one query on
every sync, so the import reads only the projects you pick, and at most 10, to
leave room for everything else that queries your Braintrust organization.

Connections made before project picking was added have no selection and still
read every project the key can see. To limit one, choose **Update key** on it (or
disconnect and connect again) and pick projects.

## Backfill

**Past data to import** sets where the first sync starts:

| Choice | What happens |
| - | - |
| **None** | Only traces that start after you connect are imported. The source shows as **syncing** right away. |
| **1 day**, **3 days**, **7 days** (default) | The first syncs import that much history, oldest first, then keep going with new traces. The source shows as **importing** until it catches up. |

Imported history shows up in **Events** as it arrives. Seven days is the most you
can import.

## Sync cadence

The import runs every 5 minutes. Each run:

* reads from where the last run stopped up to 2 minutes before now, so spans the
  source is still writing are read on the next run;
* re-reads the last 10 minutes before that point to catch spans that arrived
  late, and skips anything it already imported;
* waits for spans that are still running. A span that hasn't finished after an
  hour is skipped as never finished, so it can't hold the import back.

A new trace usually appears in Agnost AI within a few minutes of being written to
the source. During a backfill, each run imports as much as it can and saves its
place after every window of time it finishes, so a long backfill continues where
it stopped on the next run.

## One source per project

A project imports from one source at a time: one Langfuse connection or one
Braintrust connection. To switch from Langfuse to Braintrust (or the other way),
disconnect the current source first. Connecting the same source again, for example
with a new key, replaces the old connection.

Agnost AI remembers every record it imported, per project and source, so
reconnecting, replacing a key, or overlapping syncs never import the same span
twice.

To import from several Langfuse or Braintrust projects into separate places,
create an Agnost project for each.

## What maps to what

Agnost AI groups spans into **conversations** (sessions) and stores each span as
an **event**, with its parent so the tree is kept.

### Langfuse

Agnost AI reads Langfuse **observations** (`GET /api/public/v2/observations`) and
groups them by trace.

| In Langfuse | In Agnost AI |
| - | - |
| Session ID (`sessionId`, or a session attribute such as `langfuse.session.id`, `session.id` or `gen_ai.conversation.id`) | Conversation. With no session ID, each trace is its own conversation. |
| User ID (`userId`, or `langfuse.user.id`, `user.id`, `enduser.id`) | The conversation's user |
| Observation | Event, with its parent observation as the parent event |
| Type: `GENERATION`, `EMBEDDING`, `TOOL`, `AGENT`, `CHAIN`, `RETRIEVER`, `EVALUATOR`, `GUARDRAIL`, `SPAN`, `EVENT` | Event type: `llm`, `embedding`, `tool`, `agent`, `chain`, `retriever`, `evaluator`, `guardrail`, `span`, `event` |
| Name, input, output | Event name, input, output |
| Start time and latency | Event time and latency |
| Level `ERROR` | A failed event. The status message becomes its `error`. |
| Model, input, output and total usage | Event metadata `model`, `tokens.input`, `tokens.output`, `tokens.total` |
| Total cost | Event metadata `cost_usd` |
| OTel span attributes and resource attributes in the observation metadata | Event metadata (resource attributes as `resource.<key>`) |
| Environment | Conversation and event metadata `environment` |

Each event also keeps `langfuse.observation_id` and `langfuse.trace_id`, and each
conversation has `source: langfuse`. The wrapper span Langfuse adds around OTLP
traces is skipped, so its children become the roots.

### Braintrust

Agnost AI reads Braintrust **project logs** (`project_logs`) for the projects you
picked, and groups spans by their root span.

| In Braintrust | In Agnost AI |
| - | - |
| `session_id` or `conversation_id` in metadata | Conversation. With neither, each trace (root span) is its own conversation. |
| `user_id` in metadata | The conversation's user |
| Span | Event, with its first parent span as the parent event |
| Span type: `llm`, `tool` or `function`, `task`, `score` or `eval` | Event type: `llm`, `tool`, `agent`, `evaluator`. Other types become `span`. |
| Span name, input, output | Event name, input, output |
| `metrics.start` and `metrics.end` | Event time and latency |
| `error` | A failed event, with the error text as `error` |
| `prompt_tokens`, `completion_tokens`, `tokens` | Event metadata `tokens.input`, `tokens.output`, `tokens.total` |
| `estimated_cost` | Event metadata `cost_usd` |
| Metadata keys and tags | Event metadata, with tags as a comma-separated `tags` |

Each event also keeps `braintrust.span_id`, `braintrust.root_span_id` and
`braintrust.project_id`, and each conversation has `source: braintrust`.

### Cost

The cost on an imported event is the cost the source recorded: Langfuse's total
cost for the observation, or Braintrust's estimated cost for the span. Agnost AI
doesn't recalculate it from tokens. See [cost on spans](https://docs.agnost.ai/otel.md#additional-properties)
for how Agnost AI counts cost.

### What isn't imported

* Langfuse scores, prompts, datasets and dataset runs.
* Braintrust experiments, datasets and the `scores` on log rows. Scorer spans
  inside your logs are imported as `evaluator` events.
* Spans that never finished (still running after an hour).

## Status and progress

Each connected source shows:

| Column | Meaning |
| - | - |
| **Source** | Langfuse or Braintrust, the Langfuse project name or the Braintrust projects picked, and the hosting |
| **Status** | **importing** while it catches up on history, **syncing** once it's within 15 minutes of now, **failing** when the last run failed |
| **Last sync** | When the last run finished without an error. A source that hasn't run yet says **Starting within 5 minutes**. |
| **Imported events** | Events imported so far |

**Disconnect** stops new syncs. Events already imported stay in the project, and
you can reconnect any time.

## Limits

* **History:** up to 7 days.
* **Sources:** one connection per project, Langfuse or Braintrust.
* **Braintrust projects:** 1 to 10 per connection.
* **Rate limits:** the import shares your source's API limits with everything else
  that uses them. When Langfuse or Braintrust answers `429 Too Many Requests`, the
  import waits for the time the source asks for (up to 70 seconds), and retries
  up to 5 times before trying again on the next run.
* **Busy windows:** each window of time holds at most 20,000 records. Windows start
  at 6 hours and halve, down to 5 minutes, while they hold more. If more than
  20,000 spans started within a single 5-minute window, the sync stops with a
  "too many records in one window" error.
* **Records Agnost AI rejects** (for example, a malformed record) are skipped and
  not retried. The rest of the window still imports.
* **Keys** are stored encrypted and never shown again after you connect.

## Troubleshooting

| Message | What to do |
| - | - |
| "Langfuse rejected these keys. Check them and the region, then try again." | Check that both keys come from the same Langfuse project and that **Hosting** matches the region the project lives in. |
| "Langfuse public keys start with pk-lf-" / "Langfuse secret keys start with sk-lf-" | The keys are swapped or from a different tool. Copy them again from **Project settings > API keys**. |
| "Couldn't reach Langfuse at ..." / "Couldn't reach Braintrust at ..." | The host is wrong or not reachable from the internet. Check the URL. |
| "Langfuse host isn't allowed" / "Braintrust API URL isn't allowed" | The URL isn't `https://` on port 443 or 8443, includes credentials, or resolves to a private address. See [Self-hosted Langfuse](#self-hosted-langfuse). |
| "This API key can't see any Braintrust projects. ..." | Use a key from the Braintrust organization your agent logs to. |
| "Pick at least one Braintrust project to import." / "Pick up to 10 Braintrust projects." | Pick between 1 and 10 projects. |
| "This project already imports from Langfuse. A project imports from one source; disconnect it first." | Disconnect the current source, or use another Agnost project. |
| **Langfuse stopped syncing** with "Langfuse rejected the stored keys." (or "Braintrust rejected the stored API key.") | The key was revoked or rotated. Choose **Update key** and enter a working one. Data already imported is kept, and the import picks up where it stopped. |
| "This API key can no longer see the Braintrust projects you chose. Update the key or pick projects again." | Choose **Update key**, then **Find projects**, and pick projects the key can see. |
| "The sync ran out of time before finishing a window. It tries again every few minutes." | A run ended before it imported anything, usually because the source was slow or rate-limited. It retries on its own every 5 minutes. If it persists, reduce other load on the source's API. |
| Status stays **importing** for a long time | A large backfill takes several runs. **Imported events** should keep growing. If it doesn't, check the source's rate limits. |
| Conversations look like single traces | The source has no session ID on the spans. Set `sessionId` in Langfuse, or `session_id` in Braintrust metadata, so related traces group into one conversation. |

## Sending to Agnost AI directly

Importing is the fastest way to start, and it keeps working while you decide what
to do next. If you want Agnost AI to receive spans as they happen, point an
OpenTelemetry exporter at Agnost AI next to your current one: see
[OpenTelemetry](https://docs.agnost.ai/otel.md). If you do, disconnect the import for that project so the
same spans don't arrive twice.


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