This cookbook provides practical examples for using the ABV JS/TS SDK.
- Uses the core features of the ABV JS/TS SDK
- Shows how to log any LLM call via the low-level SDK
Set Up Environment
Get your ABV API key by signing up for ABV. You’ll also need your OpenAI API key. Note: This cookbook uses Deno.js for execution, which requires different syntax for importing packages and setting environment variables. For Node.js applications, the setup process is similar but uses standardnpm packages and process.env.
Add your ABV credentials to your environment variables. Make sure that you have a .env file in your project root and a package like dotenv to load the variables.
.env
abvSpanProcessor which is passed to the main OpenTelemetry SDK that orchestrates tracing.
instrumentation.ts
Log LLM Calls
You can use the SDK to log any LLM call or any of the integrations that are interoperable with it. In the following, we will demonstrate how to log LLM calls using the SDK, LangChain, Vercel AI SDK, and OpenAI integrations.Option 1: Context Manager
To simplify nesting and context management, you can use startActiveObservation. These functions take a callback and automatically manage the observation’s lifecycle and the OpenTelemetry context. Any observation created inside the callback will automatically be nested under the active observation, and the observation will be ended when the callback finishes. This is the recommended approach for most use cases as it prevents context leakage and ensures observations are properly ended.apps.ts
Option 2: observe Decorator
Theobserve wrapper is a powerful tool for tracing existing functions without modifying their internal logic. It acts as a decorator that automatically creates a span or generation around the function call. You can use the updateActiveObservation function to add attributes to the observation from within the wrapped function.
Option 3: Manual Spans
This part shows how to log any LLM call by passing the model in and outputs via the ABV SDK. Steps:- Create span to contain this section within the trace
- Create generation, log input and model name as it is already known
- Call the LLM SDK and log the output
- End generation and span
View the Trace in ABV
After ingesting your spans, you can view them in your ABV dashboard.
in the ABV UI.
Learn More
- ABV JS/TS SDK Guide
- Support