Repository navigation
Description
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/node
SDK Version
11.22.0
Framework Version
Node.js v26.13.1, openai 7.66.0
Link to Sentry event
No response
Reproduction Example/SDK Setup
import * as Sentry from '@sentry/node';
import OpenAI from 'openai';
Sentry.init({
dsn: 'https://examplePublicKey@o0.ingest.sentry.io/0',
tracesSampleRate: 1.0,
transport: () => ({
send: async () => ({}),
flush: async () => true,
}),
beforeSendSpan(span) {
console.log(span.name, span.attributes?.['gen_ai.response.time_to_first_chunk']);
return span;
},
});
const client = Sentry.instrumentOpenAiClient(
new OpenAI({ apiKey: 'test', baseURL: 'http://127.0.0.1:4123/v1' }),
);
const stream = await client.chat.completions.create({
model: 'gpt-4o-mini',
stream: true,
messages: [{ role: 'user', content: 'hi' }],
});
for await (const _chunk of stream) {
// consume stream
}Steps to Reproduce
Point baseURL at a local OpenAI Chat Completions SSE server for three cases:
- Metadata-only stream: send
{ choices: [{ delta: { role: 'assistant', content: '' } }] }at +30 ms,finish_reason: 'stop'at +130 ms, andusageat +180 ms (0 output tokens). - Delayed first content: send the role-only chunk at +30 ms, then
{ delta: { content: 'Hello' } }at +280 ms and' world'at +400 ms. - Tool-call-only stream: send the role-only chunk at +30 ms, then
delta.tool_callsat +220 ms and +340 ms (content: null).
Expected Result
In getsentry/sentry-conventions v0.34.0 (gen_ai__response__time_to_first_chunk.json, PR #795):
A chunk is a decoded provider stream event carrying new, non-empty output: text, refusals, reasoning (including opaque payloads), audio, images, or tool-call names or arguments. Empty start events or events carrying only usage, roles, IDs, signatures, keep-alives, progress/status updates, or end markers are not chunks. Chunk boundaries follow provider events, not TCP reads, HTTP frames, or extra SDK callbacks.
[...]
Set this attribute when the first chunk is received and do not set it if no chunk is received.
- Case 1 (metadata-only):
gen_ai.response.time_to_first_chunkis omitted. - Case 2 (delayed content):
gen_ai.response.time_to_first_chunkis ~0.28 s. - Case 3 (tool-call-only):
gen_ai.response.time_to_first_chunkis ~0.22 s.
Actual Result
On @sentry/node 11.22.0 (same behavior back to 11.15.0, introduced in #26465):
- Case 1 (metadata-only):
gen_ai.response.time_to_first_chunkis set to0.0451s even with 0 output tokens. - Case 2 (delayed content):
gen_ai.response.time_to_first_chunkis0.0342s (~8x too low, recorded on the +30 ms role chunk). - Case 3 (tool-call-only):
gen_ai.response.time_to_first_chunkis0.0342s (~6.5x too low, recorded on the +30 ms role chunk).
Additional Context
The same early recordTimeToFirstChunk(span) call shows up across other streaming wrappers in packages/server-utils/src/:
ai/openai/streaming.ts(line 250): fires on every first event infor await, including empty role/usage chunks and Responses APIresponse.created/response.in_progressevents.ai/anthropic-ai/streaming.ts(line 211): fires beforehandleMessageMetadata, somessage_startandpingrecord TTFC before any output content block orcontent_block_delta.integrations/vercel-ai/util.ts(lines 120-121): only skipsstream-start, still recording onresponse-metadata,text-start,reasoning-start,tool-input-start, andfinish.ai/pi-ai/chat.ts(lines 135-136): only skipsstart.ai/google-genai/streaming.ts(line 116),ai/mistral/streaming.ts(line 257), andai/workers-ai/streaming.ts(line 238, which fires on raw byte reads before SSE event decoding).
For reference, ai/tanstack-ai/index.ts (lines 204-205) already gates recordTimeToFirstChunk on OUTPUT_CHUNK_TYPES.
If you want this fixed, I can open a PR against develop to only call recordTimeToFirstChunk on real output chunks, with unit tests for these providers.
Priority
React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it.
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsNo status
Activity
linear-code commentedon Dec 1, 2026
JS-4198
andreiborza commentedon Dec 2, 2026
Hi @adityareddy-dev, thanks for filing. We'll fix it.
github-actions commentedon Dec 2, 2026
A PR closing this issue has just been released 🚀
This issue was referenced by PR #27052, which was included in the 11.23.0 release.
fix(server-utils): Record time to first chunk on the first output chu…