{"slug": "observing-vercel-ai-sdk-with-opentelemetry-signoz", "title": "Observing Vercel AI SDK with OpenTelemetry + SigNoz", "summary": "SigNoz announced a new integration with the Vercel AI SDK and OpenTelemetry to provide observability for LLM-powered applications, enabling developers to monitor latency, errors, and model behavior in production. The solution uses OpenTelemetry for standard instrumentation and SigNoz for real-time visualization and alerting, demonstrated through a product support chatbot example.", "body_md": "# Observing Vercel AI SDK with OpenTelemetry + SigNoz\n\nLLM-powered apps are growing fast, and frameworks like the Vercel AI SDK make it easy to build them. But with AI comes complexity. Latency issues, unpredictable outputs, and opaque failures can impact user experience. That’s why monitoring is essential. By using OpenTelemetry for standard instrumentation and SigNoz for observability, you can track performance, detect errors, and gain insights into your AI app’s behavior with minimal setup.\n\nWhat is the Vercel AI SDK? Why Monitoring Matters\n\nThe Vercel AI SDK makes it easy to build LLM-powered apps with support for providers like OpenAI, Anthropic, and Hugging Face. It handles streaming, tool use, and agent flows out of the box. But while development is simple, production observability is often overlooked. LLMs can be slow, unpredictable, and error-prone, making monitoring critical. Tracking latency, errors, and model behavior helps ensure reliability and a better user experience. In this blog, we will use OpenTelemetry and SigNoz to monitor this data, helping you gain actionable insights into your app’s performance and troubleshoot issues effectively.\n\nQuick Overview: OpenTelemetry and SigNoz\n\n**What is OpenTelemetry?**\n\n[OpenTelemetry](https://signoz.io/opentelemetry/) (OTel) is an open-source observability framework that provides a unified standard for collecting telemetry data—traces, metrics, and logs—from across your application stack. It’s maintained by the CNCF and is supported by a wide range of tools and languages, making it a go-to choice for modern distributed systems. With OTel, developers can instrument their code once and export data to any observability backend, avoiding vendor lock-in.\n\n**What is SigNoz?**\n\n[SigNoz](https://signoz.io/) is a one-stop observability platform built on top of OpenTelemetry. It provides a rich UI to visualize traces, monitor performance metrics, and set alerts, all in real time. By combining OpenTelemetry’s standardized data collection with SigNoz’s powerful analysis and dashboards, you get a robust solution for monitoring everything from traditional web services to AI-powered applications.\n\nThe Example App - A Product Support Chatbot\n\nTo demonstrate how monitoring works in practice, we’ve built a simple product support chatbot using the Vercel AI SDK. The app allows users to ask questions about a product, choose from suggested starter prompts, and give feedback on the chatbot’s responses. A thumbs-up triggers the bot to suggest helpful follow-up questions to deepen the conversation. If the user gives a thumbs-down, the LLM regenerates a new response in an attempt to better address the query.\n\nThe chatbot leverages streaming and LLM calls under the hood—making it a great candidate for observability. By instrumenting this app with OpenTelemetry and analyzing it in SigNoz, we can gain visibility into response times, error patterns, and user interactions. You can check out the code in the [example chatbot GitHub repository](https://github.com/SigNoz/vercel-ai-sdk-opentelemetry-example).\n\nWatch our demo video showcasing the chatbot's capabilities here:\n\nWork With Our Demo Chatbot\n\nIf you'd like to get started quickly, you can clone our example Vercel chatbot application that already includes OpenTelemetry setup. This is a great way to explore how everything works end-to-end.\n\n```\ngit clone https://github.com/SigNoz/vercel-ai-sdk-opentelemetry-example.git\ncd vercel-ai-sdk-opentelemetry-example\npnpm install\n```\n\nOnce you’ve cloned the example or set up your own Next.js project, follow the steps below to instrument your application and send traces to SigNoz Cloud.\n\nInstrument your Next.js application\n\nCheck out our [OpenTelemetry Next.js instrumentation guide](https://signoz.io/docs/instrumentation/javascript/opentelemetry-nextjs/) for detailed instructions on how to set up OpenTelemetry instrumentation in your [Next.js applications](https://signoz.io/blog/opentelemetry-nextjs/) and view your application traces in SigNoz.\n\nThis blog covers the essential steps to get started. For the complete reference guide, including self-hosted SigNoz setup, custom tracers, and dashboard import, see our [Vercel AI SDK observability documentation](https://signoz.io/docs/vercel-ai-sdk-observability/).\n\nPrerequisites\n\n- Next.js app\n- Vercel AI SDK integrated into the app\n[SigNoz Cloud Account](https://signoz.io/teams/)- SigNoz Ingestion Key\n\nSend traces directly to SigNoz Cloud\n\n**Step 1.** Install OpenTelemetry packages\n\n```\npnpm add @vercel/otel @opentelemetry/api\n```\n\n**Step 2.** Update ** next.config.mjs** to include instrumentationHook\n\nThis step is only needed when using NextJs 14 and below\n\n``` js\n/** @type {import('next').NextConfig} */\nconst nextConfig = {\n\t// include instrumentationHook experimental feature\n\texperimental: {\n\t\tinstrumentationHook: true,\n\t},\n};\nexport default nextConfig;\n```\n\n**Step 3.** Create ** instrumentation.ts** file(in root project directory)\n\n``` js\nimport { registerOTel, OTLPHttpJsonTraceExporter } from '@vercel/otel';\n// Add otel logging\nimport { diag, DiagConsoleLogger, DiagLogLevel } from '@opentelemetry/api';\ndiag.setLogger(new DiagConsoleLogger(), DiagLogLevel.ERROR); // set diaglog level to DEBUG when debugging\nexport function register() {\n  registerOTel({\n    serviceName: '<service_name>',\n    traceExporter: new OTLPHttpJsonTraceExporter({\n        url: 'https://ingest.<region>.signoz.cloud:443/v1/traces',\n        headers: { 'signoz-ingestion-key': '<your-ingestion-key>' },\n    }),\n  });\n}\n```\n\nis the name of your service`<service_name>`\n\n- Set the\nto match your SigNoz Cloud`<region>`\n\n**region** - Replace\nwith your SigNoz`<your-ingestion-key>`\n\n**ingestion key**\n\nThe instrumentation file should be in the root of your project and not inside the app or pages directory. If you're using the src folder, then place the file inside src alongside pages and app.\n\nYour Next.js app should be properly instrumented now.\n\n**Step 4.** Verify Instrumentation Locally\n\nRun your Next.js application in development mode:\n\n```\nnpm run dev\n```\n\nIn your terminal, you should see output from OpenTelemetry when the application starts, confirming that the instrumentation.ts file was loaded correctly.\n\nTo see detailed trace export logs, you can temporarily set the DiagLogLevel to DEBUG in instrumentation.ts:\n\n```\ndiag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG);\n```\n\nEnable Telemetry for Vercel AI SDK\n\nThe Vercel AI SDK uses [OpenTelemetry](https://signoz.io/opentelemetry/) to collect telemetry data.\n\nEnabling Telemetry\n\nCheck out the [Vercel AI SDK telemetry options documentation](https://ai-sdk.dev/docs/ai-sdk-core/telemetry#telemetry) for more detailed information.\n\nYou can then use the `experimental_telemetry`\n\noption to enable telemetry on specific function calls while the feature is experimental:\n\n``` js\nconst result = await generateText({\n  model: openai('gpt-4-turbo'),\n  prompt: 'Write a short story about a cat.',\n  experimental_telemetry: { isEnabled: true },\n});\n```\n\nWhen telemetry is enabled, you can also control whether you want to record the input values and the output values for the function. By default, both are enabled. You can disable them by setting the `recordInputs`\n\nand `recordOutputs`\n\noptions to `false`\n\n.\n\n```\nexperimental_telemetry: { isEnabled: true, recordInputs: false, recordOutputs: false}\n```\n\nDisabling the recording of inputs and outputs can be useful for privacy, data transfer, and performance reasons. You might, for example, want to disable recording inputs if they contain sensitive information.\n\nTelemetry Metadata\n\nYou can provide a `functionId`\n\nto identify the function that the telemetry data is for, and `metadata`\n\nto include additional information in the telemetry data.\n\n``` js\nconst result = await generateText({\n  model: openai('gpt-4-turbo'),\n  prompt: 'Write a short story about a cat.',\n  experimental_telemetry: {\n    isEnabled: true,\n    functionId: 'my-awesome-function',\n    metadata: {\n      something: 'custom',\n      someOtherThing: 'other-value',\n    },\n  },\n});\n```\n\nCustom Tracer\n\nYou may provide a `tracer`\n\nwhich must return an OpenTelemetry `Tracer`\n\n. This is useful in situations where you want your traces to use a `TracerProvider`\n\nother than the one provided by the `@opentelemetry/api`\n\nsingleton.\n\n``` js\nconst tracerProvider = new NodeTracerProvider();\nconst result = await generateText({\n  model: openai('gpt-4-turbo'),\n  prompt: 'Write a short story about a cat.',\n  experimental_telemetry: {\n    isEnabled: true,\n    tracer: tracerProvider.getTracer('ai'),\n  },\n});\n```\n\nYour Vercel AI SDK commands should now automatically emit traces, spans, and events. You can find more details on the [types of spans and events generated](https://ai-sdk.dev/docs/ai-sdk-core/telemetry#collected-data) in the Vercel AI SDK telemetry reference.\n\nFinally, you should be able to view this data in Signoz Cloud under the traces tab:\n\nIf you click on any span, you can see the detailed trace of which it is a part of.\n\nAdding Logging to Your App\n\nYou can also emit logs from your Vercel AI application to track other useful info, such as starter messages selected and feedback given by the user.\n\n**Step 1.** Install OpenTelemetry packages for logging\n\n```\npnpm add @opentelemetry/sdk-logs \\\n            @opentelemetry/exporter-logs-otlp-http \\\n            @opentelemetry/api-logs\n```\n\n**Step 2.** Create ** logging.ts** file(in lib/ directory)\n\n``` js\nimport { diag, DiagConsoleLogger, DiagLogLevel } from '@opentelemetry/api';\nimport { LoggerProvider, SimpleLogRecordProcessor } from '@opentelemetry/sdk-logs';\nimport { OTLPLogExporter } from '@opentelemetry/exporter-logs-otlp-http';\nimport { logs } from '@opentelemetry/api-logs';\n\ndiag.setLogger(new DiagConsoleLogger(), DiagLogLevel.ERROR);\n\nconst exporter = new OTLPLogExporter({\n  url: 'https://ingest.in.signoz.cloud:443/v1/logs',\n  headers: {\n    'signoz-ingestion-key': process.env.SIGNOZ_INGESTION_KEY!,\n  },\n});\n\nconst loggerProvider = new LoggerProvider({\n  processors: [new SimpleLogRecordProcessor(exporter)],\n});\n\nlogs.setGlobalLoggerProvider(loggerProvider);\n\n// Get a logger instance\nconst logger = logs.getLogger('vercel-chatbot-app');\n\n// Export the logger\nexport default logger;\n```\n\n**Step 3.** Import logger and emit logs in `route.ts`\n\n``` python\nimport logger from '../../../lib/logging';\n```\n\nHere we are emitting logger information about the which starter question that the user selected.\n\n```\nlogger.emit({\n      severityNumber: SeverityNumber.INFO,\n      severityText: 'INFO',\n      body: `User asked intial question: \"${userMessage}\"`,\n      attributes: {\n        endpoint: '/api/chat',\n        \"starterMessage\" :userMessage,\n      },\n    });\n```\n\nAfter being emitted, we can see these log details in SigNoz:\n\nHere we are emitting logger information about the feedback given by the user about the chatbot responses:\n\n```\nlogger.emit({\n      severityNumber: 1, // INFO\n      severityText: 'INFO',\n      body: 'User feedback received',\n      attributes: {\n        messageId,\n        feedback,\n      },\n    });\n```\n\nThese are what the log details would look like:\n\nWhat Your Telemetry Data Tells You\n\nWhen you enable telemetry for the Vercel AI SDK, it automatically captures detailed performance data for its core functions. But what do these [spans](https://signoz.io/blog/opentelemetry-spans/) and events actually mean for you?\n\nThis data is your key to answering critical questions about your LLM's performance:\n\n- \"How long did the entire user request take?\"\n- \"What was the\n*actual*time-to-first-token for the response?\" - \"Which part is slow: my app's logic or the LLM provider?\"\n- \"What was the exact prompt that led to this strange output?\"\n\nInstead of a black box, you get a detailed, hierarchical trace that breaks down the entire process. Here’s a summary of the most important data you get from the `streamText`\n\nfunction:\n\n| Span / Event Name | What It Measures | Key Attributes for Debugging |\n|---|---|---|\n(Span)`ai.streamText` | The full, end-to-end duration of the entire `streamText` call from your application's perspective. | `ai.prompt` : The initial prompt you sent. `ai.response.text` : The final, complete text generated. `ai.response.finishReason` : Why the stream ended (e.g., `stop` , `length` ). |\n↳ (Span)`ai.streamText.doStream` | The specific duration of the call to the underlying LLM provider (e.g., OpenAI, Anthropic). | `ai.prompt.messages` : The exact message payload sent to the provider. `ai.response.msToFirstChunk` : Time To First Token (TTFT) in milliseconds. `ai.response.avgCompletionTokensPerSecond` : The generation speed. |\n(Event)`ai.stream.firstChunk` | An event marking the exact moment the first piece of data is received from the LLM stream. | `ai.response.msToFirstChunk` : Pinpoints your TTFT on the trace timeline. |\n(Event)`ai.stream.finish` | An event that marks when the final part of the LLM stream is received. | N/A |\n\nWith this visibility, you can pinpoint whether latency is caused by your code (a long `ai.streamText`\n\nspan) or the model itself (a long `ai.streamText.doStream`\n\nspan).\n\nFor a complete list of all captured attributes and functions, you can refer to the [official Vercel AI SDK telemetry documentation](https://ai-sdk.dev/docs/ai-sdk-core/telemetry#collected-data).\n\nVisualising Data in SigNoz with Dashboards\n\nOnce your app is instrumented with OpenTelemetry, SigNoz gives you powerful dashboards to explore the telemetry data. Built-in filters and span attributes make it easy to drill down into specific user sessions or response types. You can also set up custom dashboards and alerts to monitor key metrics like response time, token usage, and message and feedback distributions, giving you a real-time view of how your AI app is performing. Here are some interesting and useful panels we were able to create using the emitted traces:\n\n**Token Usage**\n\nThis panel shows the total number of tokens used across all LLM interactions, combining both input (prompts) and output (responses). It’s useful for tracking overall API usage and estimating costs, especially when using providers like OpenAI that charge per token.\n\n**Starter Message Distribution**\n\nThis panel shows how often each starter prompt is selected by users when beginning a conversation with the chatbot. It helps identify which topics are most relevant or interesting to users—useful for refining prompt design or tailoring content.\n\n**Feedback Distribution**\n\nThis panel shows how users are rating the chatbot's responses using thumbs up or thumbs down. A higher ratio of thumbs-up indicates helpful or relevant answers, while thumbs-down can highlight areas where the LLM needs improvement.\n\n**LLM Response Latency (≥ 1000ms)**\n\nThis panel tracks the percentage of requests where the LLM response time exceeds 1000 milliseconds. It’s useful for identifying latency outliers that could impact user experience. You can also colour code the text displayed based on different value thresholds(orange for ≥ 5%, red for ≥ 10%)\n\nWrapping it Up\n\n[Monitoring LLM](https://signoz.io/blog/opentelemetry-llm/) applications is no longer optional, especially as they become more interactive, user-facing, and business-critical. With the Vercel AI SDK, it’s easy to build powerful AI-driven experiences, but combining it with OpenTelemetry and SigNoz gives you the visibility needed to operate them reliably. From tracking token usage and latency to understanding user behaviour through feedback and prompt patterns, this [observability stack](https://signoz.io/guides/observability-stack/) helps you build faster, troubleshoot smarter, and continuously improve your AI app.", "url": "https://wpnews.pro/news/observing-vercel-ai-sdk-with-opentelemetry-signoz", "canonical_source": "https://signoz.io/blog/opentelemetry-vercel-ai-sdk", "published_at": "2026-06-16 00:00:00+00:00", "updated_at": "2026-06-17 04:54:48.017155+00:00", "lang": "en", "topics": ["ai-tools", "ai-infrastructure", "developer-tools"], "entities": ["Vercel", "SigNoz", "OpenTelemetry", "OpenAI", "Anthropic", "Hugging Face", "CNCF", "Next.js"], "alternates": {"html": "https://wpnews.pro/news/observing-vercel-ai-sdk-with-opentelemetry-signoz", "markdown": "https://wpnews.pro/news/observing-vercel-ai-sdk-with-opentelemetry-signoz.md", "text": "https://wpnews.pro/news/observing-vercel-ai-sdk-with-opentelemetry-signoz.txt", "jsonld": "https://wpnews.pro/news/observing-vercel-ai-sdk-with-opentelemetry-signoz.jsonld"}}