---
title: 'Middleware'
description: 'LLM Observability with Middleware and OpenLIT'
---

<Frame>
  <img src="/images/middleware-dashboard-1.png" />
  <img src="/images/middleware-dashboard-2.png" />
</Frame>
<Frame>
  <img src="/images/middleware-dashboard-3.png" />
  <img src="/images/middleware-dashboard-4.png" />
</Frame>

To directly send OpenTelemetry metrics and traces generated by OpenLIT SDK from your LLM Application to Middleware, Follow the below steps.
<Steps>
  <Step title="Get your Middleware credentials">
    <Steps>
      1. Sign in to your [Middleware](https://app.middleware.io/) account.
      2. Go to settings and click on API Key. [Link](https://app.middleware.io/settings/api-keys)
      3. Copy and save the value for `MW_API_KEY` and `MW_TARGET`
    </Steps>
  </Step>
  <Step title="Add the following lines to your application code:">
    <Tabs>
      <Tab title="Setup using function arguments">
      ```python
      import openlit

      openlit.init(
        otlp_endpoint="MW_TARGET",
        application_name="YOUR_APPLICATION_NAME",
        otlp_headers={
            "Authorization": "MW_API_KEY",
            "X-Trace-Source": "openlit",
        },
    )
      ```
      </Tab>
      <Tab title="Setup using Environment Variables">
      ```python
      import openlit

      openlit.init()
      ```

      Run the following command to configure the OTEL endpoint and headers to send metrics and traces to Middleware:
      ```shell
    export OPENLIT_OTLP_ENDPOINT="MW_TARGET"
    export OPENLIT_APPLICATION_NAME="YOUR_APPLICATION_NAME"
    export OPENLIT_OTLP_HEADERS='{"Authorization": "MW_API_KEY", "X-Trace-Source": "openlit"}'
      ```
      </Tab>

    </Tabs>

    Replace:
    1. `MW_TARGET` with your middleware target URL
    * Example - `https://abcd.middleware.io:443`
    2. `MW_API_KEY` with your middleware API key. 
    * Example - dxyxsdojzrgpsvizzzcsvhrwnmzqdsdsd

  Refer to the OpenLIT [Python SDK repository](https://github.com/openlit/openlit/tree/main/sdk/python) for more advanced configurations and use cases.

  For detailed information on LLM Observability with Middleware and OpenLIT, consult Middleware Documentation:
  [LLM Observability Documentation](https://docs.middleware.io/llm-observability/overview).
  </Step>

  <Step title="Visualize in Middleware">
    Once your LLM application is instrumented, you can view the traces, metrics and dashboards in the Middleware LLM Observability section. To access this:
    1. Log in to your Middleware account
    2. Navigate to the [LLM Observability Section](https://app.middleware.io/llm) in the sidebar
  </Step>
</Steps>

---

<CardGroup cols={2}>
<Card title="Integrations" href="/latest/integrations/introduction" icon='circle-nodes'>
Start Monitoring your LLM Application 
</Card>
</CardGroup>