Setting up Traceloop SDK for Middleware (Node.js)
This guide will walk you through the process of setting up the Traceloop SDK to work with Middleware for LLM Observability in a Node.js environment.
1. Install the SDK
Run one of the following commands in your terminal:
npm
npm install @traceloop/node-server-sdk
2. Initialize the SDK
In your LLM application, initialize the Traceloop tracer:
import * as traceloop from "@traceloop/node-server-sdk"; traceloop.initialize({ appName: "YOUR_APPLICATION_NAME", apiEndpoint: "https://<MW_UID>.middleware.io:443", headers: { Authorization: "<MW_API_KEY>", "X-Trace-Source": "traceloop", }, resourceAttributes: { "key": "value" },
Due to how JavaScript works, you must import and initialize the Traceloop SDK before importing any LLM module like OpenAI.
Disable batch sending if you're testing locally and want to see traces immediately:
traceloop.initialize({ // ... other parameters ... disableBatch: true, });
3. Annotate your workflows (Optional)
For complex workflows or chains, you can use Traceloop's methods or decorators to get a better understanding of what's happening:
Functions (async / sync)
import { withWorkflow } from "@traceloop/node-server-sdk"; async function suggestAnswers(question) { return await withWorkflow({ name: "suggestAnswers" }, async () => { // Your function logic here }); }
If you're using an LLM framework like Haystack, Langchain, or LlamaIndex, Traceloop will automatically instrument your code. No need to add annotations manually.
Viewing Your Traces
After setting up the Traceloop SDK with Middleware, you'll be able to view your LLM application traces in your Middleware LLM Observability Section.
This integration provides instant visibility into everything happening within your LLM, including calls to vector databases or other external services.
For more detailed information on setting up Traceloop with NodeJS, please refer to the Traceloop Nodejs documentation.
Need assistance or want to learn more about using Traceloop with Middleware? Contact our support team in Slack.