Skip to content

fix(mastra): record time_to_first_token for streaming model spans#2214

Open
Cedric / ViaDézo1er (viadezo1er) wants to merge 1 commit into
mainfrom
cedric/token-usage-ttft
Open

fix(mastra): record time_to_first_token for streaming model spans#2214
Cedric / ViaDézo1er (viadezo1er) wants to merge 1 commit into
mainfrom
cedric/token-usage-ttft

Conversation

@viadezo1er

Copy link
Copy Markdown
Contributor

The Mastra observability exporter now derives time_to_first_token (in
seconds) from a model span's completionStartTime attribute and its start
time — the metric Braintrust surfaces for streaming LLM calls — matching
how our other wrappers emit TTFT. The raw completionStartTime is no
longer duplicated into span metadata.

Token usage mapping (prompt/completion/total, cached, cache-creation,
and reasoning tokens) was already at parity with @mastra/braintrust and
is unchanged.

Ports the TTFT half of mastra-ai/mastra#11029 (fixes #10174, #9821,
#9853). Adds js/src/wrappers/mastra.test.ts and regenerates the
mastra-instrumentation e2e snapshots (streaming model spans now carry
time_to_first_token).

The Mastra observability exporter now derives time_to_first_token (in
seconds) from a model span's completionStartTime attribute and its start
time — the metric Braintrust surfaces for streaming LLM calls — matching
how our other wrappers emit TTFT. The raw completionStartTime is no
longer duplicated into span metadata.

Token usage mapping (prompt/completion/total, cached, cache-creation,
and reasoning tokens) was already at parity with @mastra/braintrust and
is unchanged.

Ports the TTFT half of mastra-ai/mastra#11029 (fixes #10174, #9821,
#9853). Adds js/src/wrappers/mastra.test.ts and regenerates the
mastra-instrumentation e2e snapshots (streaming model spans now carry
time_to_first_token).
@viadezo1er Cedric / ViaDézo1er (viadezo1er) marked this pull request as ready for review July 8, 2026 02:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant