{
  "id": 20892881,
  "title": "How I Traced a Missing Vercel AI SDK Duration Histogram",
  "url": "https://urgent.news/2026/11/20/how-i-traced-a-missing-vercel-ai-sdk-duration-histogram",
  "topic": "ai",
  "section": "AI",
  "published": "2026-11-20T10:15:02.000Z",
  "source": {
    "name": "HackerNoon",
    "slug": "hackernoon",
    "url": "https://hackernoon.com/how-i-traced-a-missing-vercel-ai-sdk-duration-histogram?source=rss"
  },
  "original_language": null,
  "account": "To trace the duration of the Vercel AI SDK, the reporter first confirmed the model call duration using OpenTelemetry spans. They added a custom counter in the metrics export, but couldn't locate the inference duration histogram. They filed an issue (#24229) regarding the reproduction. The histogram was shipped in @ai-sdk/otel 1.0.160 through PR #24354.\n\nTo further investigate, the reporter ran 25 calls on each version (7.0.157 and 7.0.160) with varying generation delays (short, medium, long) and a stream. They used a local mock model to simulate delays, flushed the in-memory export after each call, and compared the results.\n\nA span attribute doesn't create a metric, but a TracerProvider sends spans to a span exporter, while a MeterProvider, reader, and metric exporter are needed for the histogram. The reporter registered new OpenTelemetry() before setting the global meter provider, which worked with the shipped code. They kept the experiment local by pinning AI and @ai-sdk/otel to specific versions and using the same OpenTelemetry, metrics, trace SDKs, and Node version.\n\nThe reporter created a control counter using the InMemoryMetricExporter and PeriodicExportingMetricReader. They incremented the counter after each call and flushed after every attempt. The issue reproduction included tracing setup and the mock model. To compare results, both AI SDK packages were pinned together. The older version (1.0.157) exported no inference histogram, while the newer version (1.0.160) exported a histogram with 25 observations.\n\nAfter each call, the reporter subtracted the previous cumulative sum for the same attribute set, checking that its count had increased by one. This gave them a duration in seconds for each call. They converted the medians to milliseconds for a comparison table.\n\nThe reporter noticed that the three generation groups aligned closely with their timer delays. The stream and error measurements were separate. They disabled retries and kept CPU and network settings constant. The mock model's stream was set to wait 40 ms, emit text, wait another 160 ms, and finish, resulting in a 202.3 ms median for the full invocation.\n\nFor future reproductions, the reporter suggested saving the GenAI semantic convention revision alongside package versions and including failed mock attempts. They wanted to see latency measurements for failed calls. The PR and its tests covered cancellations and failed stream attempts during retries. The reporter exercised a thrown error and checked the recorded durations for each call.",
  "summary": "I ran 25 mock calls per version to see how the Vercel AI SDK records generation, streaming and failures in its OpenTelemetry inference histogram.",
  "summary_source": "publisher",
  "key_points": [],
  "editors_take": null,
  "opinion": false,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "outlets_capped": false,
    "also_reported_by": []
  },
  "machine_translated": false,
  "ai_generated": true,
  "disclaimer": "Accounts, briefs, key points, the editor’s take and translations are written by software from other outlets’ reporting and may contain errors. A summary whose summary_source is \"publisher\" is the outlet’s own feed text. Always check the linked original."
}