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:

  1. Add traceloop SDK as a dependency:
npm install --save @traceloop/node-server-sdk
  1. Initialize the SDK:
traceloop.initialize(  
    appName: "<YOUR_SERVICE_NAME>",
  );

Set environment variables

Set the following environment variables:

Environment variableExample ValuesDescriptionOptional?
TRACELOOP_BASE_URLhttp://<YOUR_OBSERVE_AGENT_HOSTNAME>:4318OTLP endpointNo
TRACELOOP_TRACE_CONTENTtrue / falseEnables or disables extraction of inputs and outputs from LLM callsYes
OTEL_RESOURCE_ATTRIBUTESdeployment.environment=dev,service.namespace=inferenceA list of key=value resource attributes you wish to add to your spansYes

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)
    }
  );