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

# Setup claude code with OTel tracing

export const plans_0 = "Any"

export const deployments_0 = "Any"

export const data_plane_version_0 = undefined

export const use_case_0 = "Users who want Claude Code sessions to appear in Braintrust and need to use Claude Code's native OpenTelemetry export"

<Note>
  **Applies to:**

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

## Issue

You want to send **Claude Code traces** to Braintrust using Claude Code's native OpenTelemetry (OTEL) integration.

## Cause

Claude Code supports OpenTelemetry-based monitoring and tracing. By default, telemetry export is disabled and must be explicitly enabled through environment variables.

Braintrust exposes an OTLP-compatible ingestion endpoint that can receive Claude Code traces directly.

## Resolution

### Enable Claude Code Telemetry

Set the following environment variables before launching Claude Code:

```bash theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
export CLAUDE_CODE_ENABLE_TELEMETRY=1
export CLAUDE_CODE_ENHANCED_TELEMETRY_BETA=1

export OTEL_TRACES_EXPORTER=otlp
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
export OTEL_EXPORTER_OTLP_ENDPOINT="https://api.braintrust.dev/otel"

export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer <BRAINTRUST_API_KEY>, x-bt-parent=project_id:<PROJECT_ID>"
```

### Optional: Capture Prompt and Tool Content

To include prompts, tool invocations, and tool outputs in traces, also configure:

```bash theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
export OTEL_LOG_USER_PROMPTS=1
export OTEL_LOG_TOOL_DETAILS=1
export OTEL_LOG_TOOL_CONTENT=1
```

### Launch Claude Code

Once the environment variables are configured, start Claude Code normally:

```bash theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
claude
```

## Example Configuration

```bash theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
export CLAUDE_CODE_ENABLE_TELEMETRY=1
export CLAUDE_CODE_ENHANCED_TELEMETRY_BETA=1

export OTEL_TRACES_EXPORTER=otlp
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
export OTEL_EXPORTER_OTLP_ENDPOINT="https://api.braintrust.dev/otel"

export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer sk-my-api-key,x-bt-parent=project_id:4fd09578-7394-41d3-9ce2-917ce24c1fec"

export OTEL_LOG_USER_PROMPTS=1
export OTEL_LOG_TOOL_DETAILS=1
export OTEL_LOG_TOOL_CONTENT=1
```

## Notes

Enabling the following options may cause sensitive data to be included in traces:

* `OTEL_LOG_USER_PROMPTS`
* `OTEL_LOG_TOOL_DETAILS`
* `OTEL_LOG_TOOL_CONTENT`

Review your organization's data handling policies before enabling them in production environments.

The `x-bt-parent` header determines where traces are logged in Braintrust. Replace `<PROJECT_ID>` with the Braintrust project that should receive the traces.

## Additional Resources

* [Claude Code Monitoring and Usage Documentation](https://code.claude.com/docs/en/monitoring-usage#traces-beta)
* [Braintrust Tracing Documentation](https://www.braintrust.dev/docs)

## Recommended: Use the Native Braintrust Plugin

If you are able to install Claude Code plugins, we recommend using the **`trace-claude-code`** plugin from **`braintrust-claude-plugin`** instead of configuring OpenTelemetry manually.

The plugin provides native Braintrust tracing for Claude Code and automatically captures sessions, conversation turns, and tool calls as hierarchical traces in Braintrust with minimal setup. :contentReference\[oaicite:0]{index=0}

For setup instructions, see:

[https://www.braintrust.dev/docs/integrations/developer-tools/claude-code#plugin-trace-claude-code](https://www.braintrust.dev/docs/integrations/developer-tools/claude-code#plugin-trace-claude-code)

The OpenTelemetry configuration described in this article is most useful when:

* You cannot install Claude Code plugins.
* You already have an OTEL-based observability pipeline.
* You want to route Claude Code telemetry through a custom OpenTelemetry configuration.
