OpenLIT SDK - Setup Guide for TypeScript
This guide walks you through wiring the OpenLIT SDK to Middleware so you can observe TypeScript LLM workloads end-to-end. You’ll learn how to install the SDK, initialize it (via function args or environment variables), and then run a first request so traces/metrics appear in LLM Observability.
Before you begin
- Have credentials ready: Your Middleware UID (for the OTLP endpoint) and Middleware API key (for the
Authorization
header). - Choose one init style: Configure via function arguments or via environment variables. Both are supported and shown below.
- Metrics toggle: You can disable metrics with
disableMetrics: true
or setOPENLIT_DISABLE_METRICS=true
.
1. Install the SDK
Run this in your project to add OpenLIT:
1npm install openlit
2. Initialize the SDK
Choose between function arguments or environment variables, and stick with one for consistency.
Set up using function arguments
In your LLM application, initialise the OpenLIT SDK like this:
1import Openlit from "openlit"
2
3Openlit.init({
4 otlpEndpoint: "https://<MW_UID>.middleware.io:443",
5 applicationName: "YOUR_APPLICATION_NAME",
6 otlpHeaders: {
7 "Authorization": "<MW_API_KEY>",
8 "X-Trace-Source": "openlit",
9 },
10})
Set up using Environment Variables
First, export the required variables so OpenLIT can auto-read them at runtime:
1export OPENLIT_OTLP_ENDPOINT="https://<MW_UID>.middleware.io:443"
2export OPENLIT_APPLICATION_NAME="YOUR_APPLICATION_NAME"
3export OPENLIT_OTLP_HEADERS='{"Authorization": "<MW_API_KEY>", "X-Trace-Source": "openlit"}'
Then, in your TypeScript code, call init() with no arguments (it will use the env vars):
1import Openlit from "openlit"
2
3Openlit.init()
You can disable metrics collection by passing disableMetrics: true
to init or setting the OPENLIT_DISABLE_METRICS=true
environment variable.
3. Use the SDK
Start with the basic usage example as shown below to send your first telemetry:
1import Openlit from "openlit"
2
3Openlit.init({
4 otlpEndpoint: "https://<MW_UID>.middleware.io:443",
5 applicationName: "YOUR_APPLICATION_NAME",
6 otlpHeaders: {
7 "Authorization": "<MW_API_KEY>",
8 "X-Trace-Source": "openlit",
9 },
10})
Viewing your traces and metrics
After initialisation and at least one real LLM request, open the LLM Observability section in Middleware to see traces and metrics for your TypeScript service.
For advanced options and patterns, refer to the OpenLIT TypeScript SDK documentation.
Troubleshooting
- No data appearing: Make sure an actual LLM request ran after
Openlit.init(...)
, and verify network access tohttps://<MW_UID>.middleware.io:443
. - Auth/tenant issues: Re-check the exact
Authorization
value (Middleware API key) and thatotlpEndpoint
(orOPENLIT_OTLP_ENDPOINT
) includes your correct tenant UID. - Env-var setup not picked up: Confirm variable names (
OPENLIT_OTLP_ENDPOINT
,OPENLIT_APPLICATION_NAME
,OPENLIT_OTLP_HEADERS
) and then callOpenlit.init()
with no arguments. - Only traces, no metrics: Ensure you haven’t set
disableMetrics: true
orOPENLIT_DISABLE_METRICS=true
unintentionally.
Need assistance or want to learn more about using Traceloop with Middleware? Contact our support team at [email protected].