Repository navigation
feat(server-utils): Record time to first chunk on streamed gen_ai spans - #26465
Draft
sentry-junior[bot] wants to merge 7 commits into
Draft
sentry-junior[bot] wants to merge 7 commits into
sentry-junior[bot] wants to merge 7 commits into
Conversation
Set `gen_ai.response.time_to_first_chunk` on streamed chat spans of the pi-ai, OpenAI, Anthropic, Google GenAI, Mistral, Workers AI, Vercel AI, and LangChain integrations, and map Mastra's `completionStartTime`. Only chunks with output count, following the OpenTelemetry GenAI definition. Co-Authored-By: Francesco Gringl-Novy <2411343+mydea@users.noreply.github.com>
Contributor
size-limit report 📦Compared: 757b442 (PR test merge using develop at abdc5dd) Against: abdc5dd (develop) · base run #66461 ✅ Baseline matches: this diff contains only this PR's changes.
|
Contributor
|
One or more gzipped bundles increased by more than 500 bytes. If this increase is intentional, add the Accept Bundlesize Increase label to this PR to rerun and accept the check. |
Contributor
Optional E2E testsSome optional checks were not successful. They do not block the merge. 2 not successful, 59 successful. See the run.
Successful checks
|
mydea
reviewed
Nov 17, 2026
… tests Assert the attribute on the streamed spans of the existing OpenAI, Anthropic, Google GenAI, Mistral, Vercel AI, and Mastra suites, and drop the unit tests for it.
…o-first-chunk # Conflicts: # dev-packages/node-integration-tests/suites/tracing/mastra/test.ts # dev-packages/node-integration-tests/suites/tracing/openai/test.ts
…hunk Drop the per-provider checks for output-carrying chunks and record the time when the first chunk of the response stream arrives, as the OTel definition says. This cuts most of the bundle size the feature added. Co-Authored-By: Francesco Gringl-Novy <2411343+mydea@users.noreply.github.com>
…o-first-chunk Co-Authored-By: Francesco Gringl-Novy <2411343+mydea@users.noreply.github.com> # Conflicts: # packages/server-utils/src/ai/mistral/streaming.ts # packages/server-utils/src/ai/workers-ai/streaming.ts
mydea
reviewed
Nov 17, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Streamed
gen_ai.chatspans now setgen_ai.response.time_to_first_chunk, in seconds from the span start. This covers the pi-ai, OpenAI (Chat Completions and Responses), Anthropic, Google GenAI, Mistral, Workers AI, Vercel AI, and LangChain integrations. The Mastra integration maps Mastra's owncompletionStartTimeto the attribute.Why
The attribute is in the OpenTelemetry GenAI conventions, in sentry-conventions, and in the Sentry AI client span docs, and sentry-python already sets it. No JS AI integration set it, so apps had to measure it themselves.
The value is the time when the first chunk of the response stream arrives, as the OTel definition says. Vercel AI's
stream-startpart and pi-ai'sstartevent do not count, because the model emits them before the response body arrives. pi-ai streams have one consumer, so the integration wraps the stream'spush, which providers call for each event, and does not read the stream.LangGraph, Flue, and pi-durable only create agent spans; Flue and pi-durable model calls go through pi-ai.
via @mydea.
--
View Session [Sentry]