Use Node.js (server) instrumentation for LLM observability
Supported frameworks and libraries
OpenLLMetry automatically instruments the following provider APIs and libraries:
- OpenAI
- Azure OpenAI
- Anthropic
- Cohere
- Bedrock (AWS)
- Vertex AI (GCP)
Supported vector databases
The following
- Chroma
- Pinecone
- Qdrant
Supported frameworks
The following LLM frameworks are supported:
- LangChain
- LlamaIndex
Install and configure the Node.js instrumentation
Perform the following tasks to configure Node.js instrumentation:
- Add traceloop SDK as a dependency:
npm install --save @traceloop/node-server-sdk
- Initialize the SDK:
traceloop.initialize(
appName: "<YOUR_SERVICE_NAME>",
);
Set environment variables
Set the following environment variables:
| Environment variable | Example Values | Description | Optional? |
|---|---|---|---|
TRACELOOP_BASE_URL | http://<YOUR_OBSERVE_AGENT_HOSTNAME>:4318 | OTLP endpoint | No |
TRACELOOP_TRACE_CONTENT | true / false | Enables or disables extraction of inputs and outputs from LLM calls | Yes |
OTEL_RESOURCE_ATTRIBUTES | deployment.environment=dev,service.namespace=inference | A list of key=value resource attributes you wish to add to your spans | Yes |
Add attributes at runtime
To annotate your span data with custom attributes like customer_id, user_id, and so on, we recommend using OpenLLMetry functions. Depending on your use-case, you may choose one of the following approaches:
- For class methods
/* This example wraps a workflow span as denoted by the "workflow" decorator. To wrap spans of other types you may use the task/agent/tool decorators as desired
*/
class MyClass {
@traceloop.workflow({ associationProperties: { userId: "user123" })
myMethod() {
// Your code here
}
}
- Within attributes per workflow / task / agent / tool call spans
// Wraps workflows
// Replace with withTask / withAgent / withTool as needed
traceloop.withWorkflow(
\{
name: "workflow_name",
associationProperties: { userId: "user12345", chatId: "chat12345" },
},
() => {
// Your code here
// (function can be made async if needed)
}
);
- Directly wrapping with global attributes
traceloop.withAssociationProperties(
\{
userId: "user12345",
chatId: "chat12345",
},
() => {
// Your code here
// (can be async or sync)
}
);
Updated about 2 months ago