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

# Middleware

> Learn how to export LLM Gateway traces to Middleware using OpenTelemetry integration.

This guide provides instructions for integrating [Middleware](https://middleware.io/) with the TrueFoundry AI Gateway to export OpenTelemetry traces.

## What is Middleware?

Middleware provides observability and monitoring for cloud-native workloads. Connecting the TrueFoundry AI Gateway lets you ingest LLM and gateway spans into your Middleware environment for analysis alongside the rest of your stack.

### Key Features of Middleware

* **Unified observability**: Consolidate traces, logs, and infrastructure signals in one place
* **OpenTelemetry ingestion**: Receive OTLP spans from gateways and SDKs compatible with OTLP HTTP
* **Operational visibility**: Correlate latency, errors, and usage patterns across services and AI workloads

## Prerequisites

Before integrating Middleware with TrueFoundry, ensure you have:

1. **TrueFoundry Account**: Create a [Truefoundry account](https://www.truefoundry.com/register) and follow the instructions in our [Gateway Quick Start Guide](https://docs.truefoundry.com/gateway/quick-start)
2. **Middleware access**: Log in to Middleware with your **work email** (the account your organization uses for Middleware).
3. **Middleware API key**: Obtain the API key Middleware issued for OTLP trace ingestion (typically from Middleware project or organization settings — use the credential they designate for traces).

<Frame>
  <img src="https://mintcdn.com/truefoundry/oV4Gs2xiqZzXmojM/images/middleware-ingestion-api-key.png?fit=max&auto=format&n=oV4Gs2xiqZzXmojM&q=85&s=dcb113d809c28b952bca28abc7bc5b56" alt="Middleware Settings with Ingestion key tab and API key list including Create New Key" width="1024" height="526" data-path="images/middleware-ingestion-api-key.png" />
</Frame>

## Integration Steps

TrueFoundry AI Gateway supports exporting OpenTelemetry traces to Middleware using your tenant OTLP ingest URL.

<Steps>
  <Step title="Collect your Middleware API key">
    1. Log in to Middleware with your work email and open your API key or organization settings (your admin may point you to the credential used for trace ingestion).
    2. Copy the secret and store it in a credential manager until you paste it into TrueFoundry gateway settings — you typically cannot retrieve the full secret again once generated.

    <Tip>
      If you are unsure which key fits this integration, confirm with Middleware support — this flow expects the key mapped to OTLP ingestion at **`https://<your-domain>.middleware.io:443/v1/traces`** (replace `<your-domain>` with your Middleware hostname prefix).
    </Tip>
  </Step>

  <Step title="Configure OTEL Export in TrueFoundry">
    1. In the TrueFoundry dashboard, go to **AI Engineering** → **Settings** → **OTEL Config** (under **Organisation**, in the AI Gateway section).

    <Frame>
      <img src="https://mintcdn.com/truefoundry/oV4Gs2xiqZzXmojM/images/middleware-truefoundry-settings-otel-config.png?fit=max&auto=format&n=oV4Gs2xiqZzXmojM&q=85&s=3ee071781038f3edeb9d7a0ebda656c2" alt="TrueFoundry AI Engineering and Settings navigation to Organisation OTEL Config with Middleware traces endpoint and authorization header" width="1024" height="515" data-path="images/middleware-truefoundry-settings-otel-config.png" />
    </Frame>

    2. Click **edit** on the **OTEL Config** section to open the exporter form (if it is not already open).
    3. Enable the **OTEL Traces Exporter Configuration** toggle.
    4. Select **HTTP Configuration**.
    5. Enter the Middleware traces endpoint: `https://<your-domain>.middleware.io:443/v1/traces`
    6. Set **Encoding** to `Proto`.

    <Frame>
      <img src="https://mintcdn.com/truefoundry/2k3td5m0XnsQ8bTs/images/Middleware.png?fit=max&auto=format&n=2k3td5m0XnsQ8bTs&q=85&s=34d6e5f3465c16f7d625cb601e64197e" alt="TrueFoundry OTEL Traces Exporter Configuration with Middleware HTTPS traces endpoint, Proto encoding, and Authorization header set to the Middleware API key" width="994" height="656" data-path="images/Middleware.png" />
    </Frame>
  </Step>

  <Step title="Configure Headers">
    Middleware expects authentication through the `Authorization` header only. Paste the raw API key as the header value (do **not** add a `Bearer` prefix unless Middleware explicitly instructed you otherwise).

    | Header          | Value                       |
    | --------------- | --------------------------- |
    | `Authorization` | `<YOUR_MIDDLEWARE_API_KEY>` |

    Click **Save** to apply your configuration.
  </Step>

  <Step title="Verify the Integration">
    1. Make some requests through the TrueFoundry AI Gateway.
    2. Navigate to the **Monitor** section in TrueFoundry to verify traces are being generated.
    3. Open Middleware and drill into traces for your project or environment to confirm spans sourced from TrueFoundry are appearing.

    <Frame>
      <img src="https://mintcdn.com/truefoundry/oV4Gs2xiqZzXmojM/images/middleware-traces-dashboard.png?fit=max&auto=format&n=oV4Gs2xiqZzXmojM&q=85&s=105459ae2e2d7bbb9aee378af7778463" alt="Middleware Traces dashboard showing gateway spans, metrics, and trace list from TrueFoundry" width="1024" height="532" data-path="images/middleware-traces-dashboard.png" />
    </Frame>
  </Step>
</Steps>

## Configuration Options

### Middleware Endpoint

Middleware exposes ingest configuration similar to the following (use your tenant hostname):

| Configuration       | Value                                                                      |
| ------------------- | -------------------------------------------------------------------------- |
| **Traces Endpoint** | `https://<your-domain>.middleware.io:443/v1/traces`                        |
| **Protocol**        | HTTP                                                                       |
| **Encoding**        | `Proto`                                                                    |
| **Authentication**  | `Authorization` set to your Middleware API key (no extra headers required) |
