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

# Nest LLM spans beneath code scorers to preserve span context

> Check deployment and pass active span context to nest Gateway LLM calls beneath hosted scorers.

> [!NOTE]
>
> **Applies to:**
>
> * Plan - Any
> * Deployment - Braintrust-hosted
> *
> * LLM calls missing beneath hosted code scorers

## Summary

To nest a Gateway LLM call beneath a scorer, export the active span with `await currentSpan().export()` and pass it as `x-bt-parent`.

If the export is empty, check the scorer's deployment method before adding the header.

## Check the deployment method

A custom script can combine code and dependencies, then upload the result through the REST API as an inline function. This differs from `bt functions push`, which uploads a bundle referenced by the function definition.

Scorers uploaded inline via the REST API return empty span context. Deploying the same scorers with [`bt functions push`](https://docs.braintrust.dev/reference/cli/functions) provides non-empty context and enables LLM nesting.

## Resolution

1. Define your scorer using the Braintrust SDK.
2. Push the source file with [`bt functions push`](https://docs.braintrust.dev/reference/cli/functions). The CLI handles bundling.
3. Inside the scorer, export the active span and pass it on the request.

The following snippet belongs inside an existing scorer. It assumes `judgePrompt` is already defined and uses the hosted runtime's Gateway configuration.

```typescript theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
import { currentSpan } from "braintrust";

const parent = await currentSpan().export();
const baseURL = process.env.OPENAI_BASE_URL;
const apiKey = process.env.BRAINTRUST_API_KEY;

const res = await fetch(
  `${baseURL.replace(/\/+$/, "")}/responses`,
  {
    method: "POST",
    headers: {
      Authorization: `Bearer ${apiKey}`,
      "Content-Type": "application/json",
      "x-bt-parent": parent,
    },
    body: JSON.stringify({
      model: "gpt-5-mini",
      input: judgePrompt,
    }),
  },
);
```

This is a request snippet, not a complete file to push. See [Custom code scorers](https://docs.braintrust.dev/evaluate/custom-code.md) for a complete scorer definition.

## Verify

Run the uploaded scorer through your online scoring rule and check that:

* The exported context is non-empty.
* The model request succeeds.
* The LLM span appears within the scorer's trace hierarchy. A hosted runtime span may appear between them.

If no scorer span appears, check the automation separately. If the scorer runs but context remains empty, inspect the saved function type (`inline` or `bundle`), SDK version, and deployment method.

For more information, see [Advanced tracing](https://docs.braintrust.dev/instrument/advanced-tracing.md#trace-deeply-nested-code) and [Gateway logging](https://docs.braintrust.dev/deploy/gateway.md#enable-logging).


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