feat(ai): add telemetry interface and registry#12881
Merged
aayush-kapoor merged 8 commits intomainfrom Mar 3, 2026
Merged
Conversation
aayush-kapoor
commented
Feb 26, 2026
Collaborator
Author
There was a problem hiding this comment.
the dx for the providers using this will be
import type { TelemetryHandler } from 'ai';
import { bindTelemetryHandler } from 'ai';
class DevToolsTelemetryHandler implements TelemetryHandler {
private runId: string | undefined;
private stepCounter = 0;
private stepTimers = new Map<number, number>();
async onStart(event) {
...
}
async onStepStart(event) {
...
}
async onToolCallStart(event) {
// Log tool invocation to devtools UI
}
async onToolCallFinish(event) {
// Log tool result (or error) with duration
}
async onStepFinish(event) {
...
}
async onFinish(event) {
// Final summary: total usage, all steps, etc.
}
}
// the public API - what end users import and pass to `handlers`
export function devToolsHandler(): TelemetryHandler {
return bindTelemetryHandler(new DevToolsTelemetryHandler());
}
lgrammel
reviewed
Feb 27, 2026
lgrammel
approved these changes
Feb 27, 2026
lgrammel
reviewed
Mar 2, 2026
| TOOLS extends ToolSet = ToolSet, | ||
| OUTPUT extends Output = Output, | ||
| > { | ||
| onStart?(event: OnStartEvent<TOOLS, OUTPUT>): PromiseLike<void> | void; |
Collaborator
There was a problem hiding this comment.
wonder if we can use / extract types such as OnStartListener - maybe in follow up prs
lgrammel
reviewed
Mar 2, 2026
lgrammel
reviewed
Mar 2, 2026
lgrammel
reviewed
Mar 2, 2026
Collaborator
|
the global listener would need to be called from generateText and streamText |
aayush-kapoor
commented
Mar 2, 2026
aayush-kapoor
commented
Mar 2, 2026
aayush-kapoor
commented
Mar 2, 2026
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.
Background
we needed an interface that could be implemented by telemetry providers for capturing all the data that will be propagated via the callbacks
Summary
TelemetryHandler: interface to create custom telemetry integrationsexpand-handlers.ts: file turns handlers: [handlerA, handlerB, handlerC] into a single object with one callback per lifecycle event, where each callback fans out to every handler that needs info about that eventhandlersto thetelemetry-settingsfor handlers that receive lifecycle events during generationFuture Work
make the
integrationsoption work behind the scenes, ie without a need for it to be in experimental_telemetryChecklist
pnpm changesetin the project root)