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

# Troubleshooting

> Diagnose and fix common issues when installing or using the Braintrust .NET SDK.

This page outlines common issues when setting up and using the Braintrust .NET SDK and how to resolve them.

<AccordionGroup>
  <Accordion title="No traces appear in Braintrust">
    Initialize Braintrust with `Braintrust.Get()` before you create your provider client. `Braintrust.Get()` sets up the OpenTelemetry pipeline that exports spans to Braintrust, so calls made before it runs are not traced.

    Make your AI calls on the **wrapped** client returned by the integration, not the original client:

    ```csharp #skip-compile theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
    var braintrust = Braintrust.Sdk.Braintrust.Get();
    var activitySource = braintrust.GetActivitySource();

    // Trace calls on `client`, not on a separately constructed client
    var client = BraintrustOpenAI.WrapOpenAI(activitySource, apiKey);
    ```
  </Accordion>

  <Accordion title="No traces when managing your own tracer provider">
    By default, the SDK manages OpenTelemetry and registers a process-exit hook that flushes traces when your app terminates, so even short-lived processes export correctly with no extra work.

    If you opt out of auto-management and wire Braintrust into your own `TracerProviderBuilder` (via `OpenTelemetryEnable`), that hook isn't registered. In that case, force a flush before the process exits:

    ```csharp #skip-compile theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
    using Braintrust.Sdk.Trace;

    BraintrustTracing.ForceFlush();
    ```

    `ForceFlush` returns `true` when the flush completes within the timeout (10 seconds by default).
  </Accordion>

  <Accordion title="Traces are written to the wrong project">
    Spans route to `BRAINTRUST_DEFAULT_PROJECT_NAME`, which defaults to `default-dotnet-project` when unset. Set the project in the environment:

    ```bash theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
    BRAINTRUST_DEFAULT_PROJECT_NAME="My project"
    ```

    Or pass it through configuration:

    ```csharp #skip-compile theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
    using Braintrust.Sdk;
    using Braintrust.Sdk.Config;

    var config = BraintrustConfig.Of(("BRAINTRUST_DEFAULT_PROJECT_NAME", "My project"));
    var braintrust = Braintrust.Sdk.Braintrust.Get(config);
    ```
  </Accordion>

  <Accordion title="BRAINTRUST_API_KEY is required error">
    The SDK looks for your API key in the `BRAINTRUST_API_KEY` environment variable, then in a `.env.braintrust` file searched upward from the working directory. Set the variable:

    ```bash theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
    BRAINTRUST_API_KEY="your-api-key"
    ```

    Create an API key in [API key settings](https://www.braintrust.dev/app/~/settings/api-keys) if you don't have one.
  </Accordion>

  <Accordion title="Debug setup and API errors">
    Enable debug logging to surface configuration and export issues, and console trace logging to confirm spans are being created before they're exported:

    ```bash theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
    BRAINTRUST_DEBUG=true
    BRAINTRUST_ENABLE_TRACE_CONSOLE_LOG=true
    ```
  </Accordion>
</AccordionGroup>
