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

# TraceLoop

If you are a coding agent, prefer the Braintrust [`bt` CLI](/docs/reference/cli/quickstart) for repeatable, scriptable work: running evals, instrumenting code, querying logs, syncing data, managing functions, and configuring coding agents. Use the MCP server for reasoning over Braintrust data in conversation, and for capabilities the CLI doesn't cover, such as monitor views, alerts, and authoring evaluators, preprocessors, and facets.

[TraceLoop OpenLLMetry](https://www.traceloop.com/docs) is an observability framework for LLM applications. Braintrust integrates with TraceLoop via OpenTelemetry to capture LLM calls, workflows, and application traces.

## Setup

This integration uses Braintrust's [Python SDK OpenTelemetry configuration](/docs/integrations/sdk-integrations/opentelemetry#python-sdk-configuration).

Install Traceloop alongside the Braintrust SDK with OpenTelemetry support and the OpenAI client:

<CodeGroup>
  ```bash Python theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
  pip install "braintrust[otel]" traceloop openai
  ```
</CodeGroup>

Configure your environment variables:

```bash title=".env" theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
TRACELOOP_BASE_URL=https://api.braintrust.dev/otel
TRACELOOP_HEADERS="Authorization=Bearer%20<Your API Key>, x-bt-parent=project_id:<Your Project ID>"
```

<Note>
  When setting the bearer token, encode the space between "Bearer" and your API key using `%20`.
</Note>

## Trace with TraceLoop

Initialize TraceLoop and your traces will automatically be sent to the Braintrust project specified in the `x-bt-parent` header:

```python title="traceloop_braintrust.py" theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
from openai import OpenAI
from traceloop.sdk import Traceloop
from traceloop.sdk.decorators import workflow

Traceloop.init(disable_batch=True)
client = OpenAI()

@workflow(name="story")
def run_story_stream(client):
    completion = client.chat.completions.create(
        model="gpt-4o-mini",
        messages=[{"role": "user", "content": "Tell me a short story about LLM evals."}],
    )
    return completion.choices[0].message.content

print(run_story_stream(client))
```

## Resources

* [TraceLoop OpenLLMetry documentation](https://www.traceloop.com/docs)
* [Braintrust OpenTelemetry guide](/docs/integrations/sdk-integrations/opentelemetry)
