Note: This package requires you to be using the Vercel AI SDK version 3.3 or higher.
Getting Started
Installation
You will need to install the@arizeai/openinference-vercel package as well as a few packages from opentelemetry.
- npm
- pnpm
- yarn
registerOtel function from @vercel/otel (see Runtimes below) you must ensure that opentelemetry packages match those used by @vercel/otel . You must use opentelemetry packages of version 1.x or 0.1.x with version 1.x of @vercel/otel . Keep this in mind during your installs
| @vercel/otel | opentelemetry v1.x (0.1.x) | opentelemetry v2.x (0.2.x) |
|---|---|---|
| 1.x | ✅ | ❌ |
| 2.x | ❌ | ✅ |
AI SDK Setup
In order to trace calls to the AI SDK you must set theexperimental_telemetry flag on each call.
Runtimes
Depending on your runtime, you may need to set up instrumentation differently. If you’re using Next.js and are tracing AI SDK calls in edge runtimes you will need to use theregisterOtel function from @vercel/otel . Otherwise in Node runtimes you can use the NodeTracerProvider or the NodeSDK .
- @vercel/otel
- @opentelemetry/sdk-trace-node
- @opentelemetry/sdk-node
Additional DependenciesAdd the following
instrumentation.ts at the top level of your src directory.Further Documentation
- Next.js telemetry setup - https://nextjs.org/docs/app/guides/open-telemetry
- @vercel/otel - https://www.npmjs.com/package/@vercel/otel
- @opentelemetry/sdk-trace-node - https://www.npmjs.com/package/@opentelemetry/sdk-trace-node/v/1.17.0
- @opentelemetry/sdk-node - https://www.npmjs.com/package/@opentelemetry/sdk-node/v/0.49.1
Span Filter
In some environments, enabling telemetry on the AI SDK will enable tracing on more than AI related calls. Most commonly there will be http spans forPOST and GET requests.
The @arizeai/openinference-vercel package exports the isOpenInferenceSpan helper function to filter these non-ai spans out.
In the above examples it is included. Filtering spans in this way may cause spans in AX to be orphaned (no parent trace) as the root spans are filtered out. Because of this you won’t see any spans on the traces tab. If you find yourself in this situation, navigate to the spans tab to view your AI SDK spans.