- Configure an OpenTelemetry (OTEL) trace exporter (instructions differ for Next.js, Node.js, and Cloudflare Workers).
- Instrument your Vercel AI SDK calls and attach Raindrop metadata (common to all).
Setting up OpenTelemetry in Next.js
First, install the required OpenTelemetry packages.instrumentation.ts file.
Setting up OpenTelemetry in Node.js
For Node.js applications, first install the required OpenTelemetry packages.Setting up OpenTelemetry in Cloudflare Workers
Cloudflare’s native tracing doesn’t support custom spans, so we use@microlabs/otel-cf-workers.
nodejs_compat to your wrangler.toml:
Using with Sentry (Next.js)
If you’re already using Sentry for error tracking and tracing in your Next.js app, you can add Raindrop’s trace exporter directly to Sentry’s OpenTelemetry configuration instead of setting up a separate instrumentation file. First, install the required OpenTelemetry packages alongside your existing Sentry setup:openTelemetrySpanProcessors option in your sentry.server.config.ts:
Error: @opentelemetry/api: Attempted duplicate registration of API: trace.
Instrumenting AI SDK Calls
To instrument your AI SDK calls:- Enable
experimental_telemetry: { isEnabled: true }at all AI SDK call sites - Add Raindrop metadata at the top-level call that handles user input and produces the final output using
raindrop.metadata()
Troubleshooting
Enable OpenTelemetry Debug Logging
If traces aren’t appearing in the Raindrop dashboard, enable debug logging to see what’s happening under the hood:Ensure Telemetry is Enabled at All Call Sites
A common issue is forgetting to addexperimental_telemetry: { isEnabled: true } to nested AI SDK calls. Every generateText, streamText, generateObject, etc. call must have telemetry enabled for traces to be captured:
Cloudflare Workers: Spans Incomplete or Missing
Streaming responses requirewaitUntil
The instrument() wrapper flushes spans when the handler returns. With streaming, the handler returns immediately while the LLM is still generating. Without waitUntil, spans get flushed before they complete: