experimental_telemetry option.
This guide shows you how to configure OTel to send traces from the Vercel AI SDK to Weave. You can use the AI SDK with Next.js or as a standalone Node.js application.
For more information on OTel tracing in Weave, see Send OTel traces to Weave.
Prerequisites
Both of the Next.js and Node.js examples in this guide require the same dependencies. To start:-
Install the following Vercel and OTel libraries:
-
Set the following environment variables:
You can get your W&B API key from User Settings.
Configure OTel tracing for Next.js
This section demonstrates how to configure Weave in a Next.js app. The example does not contain a full app, just the instrumentation configuration and how to invoke the instrumentation on a Vercel AI SDK function, in this a case, a simple call to OpenAI.Configure instrumentation
Next.js applications use aninstrumentation.ts file to set up OTel. This file runs once when the server starts and configures the tracer provider that the AI SDK uses.
To integrate Weave with Vercelโs OTeLโs functionality, create an instrumentation.ts file in your project root and add the following code to it, updating the resourceFromAttributes() function with your team and project names:
instrumentation.ts
Configure telemetry on a function
Once youโve added the instrumentation, use Vercelโsexperimental_telemetry option on any AI SDK function call to emit OTel spans:
route.ts
generateText calls with telemetry enabled produce OTel spans that are exported to Weave.
Configure OTel tracing for Node.js
For standalone Node.js applications (without Next.js), configure the tracer provider at the top of your entry file before any AI SDK calls. After meeting the prerequisites, you can run this example and generate spans without any additional configuration.test-app.ts
BatchSpanProcessor flushes spans asynchronously. In short-lived processes like standalone scripts, serverless functions, or CLI tools, call provider.shutdown() before the process exits to ensure all spans are sent to Weave. For long-running servers (like a Next.js dev server started through instrumentation.ts), this is not necessary.