Skip to content

feat(ai): add an event emitter to core functions#12749

Merged
aayush-kapoor merged 18 commits intomainfrom
aayush/event-emitter
Feb 25, 2026
Merged

feat(ai): add an event emitter to core functions#12749
aayush-kapoor merged 18 commits intomainfrom
aayush/event-emitter

Conversation

@aayush-kapoor
Copy link
Copy Markdown
Collaborator

@aayush-kapoor aayush-kapoor commented Feb 20, 2026

Background

as a part of the ongoing change to refactor telemetry, the idea is to create an event emitter (that basically emits all the information that is present at that step of the flow) so that listeners (such as OTel) can tap into the information and create spans accordingly

Summary

  • add an event emitter + listeners array
  • simple example to verify events and listeners work

Manual Verification

  • verified by running examples/ai-functions/src/events/listen-to-events.ts

Checklist

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

Future Work

  • will need to decouple otel from core functions

@tigent tigent bot added ai/core core functions like generateText, streamText, etc. Provider utils, and provider spec. ai/telemetry feature New feature or request labels Feb 20, 2026
Comment on lines +9 to +12
export async function notify<EVENT>(options: {
event: EVENT;
callbacks?: Listener<EVENT> | Array<Listener<EVENT>>;
}): Promise<void> {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

Comment on lines 1279 to +1308
@@ -1298,10 +1303,9 @@ class DefaultStreamTextResult<TOOLS extends ToolSet, OUTPUT extends Output>
include,
...callbackTelemetryProps,
experimental_context,
});
} catch (_ignored) {
// Errors in callbacks should not break the generation flow.
}
},
callbacks: onStart,
});
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great and allows us to extend as well in the future

@aayush-kapoor aayush-kapoor enabled auto-merge (squash) February 25, 2026 15:30
@aayush-kapoor aayush-kapoor merged commit b7fba77 into main Feb 25, 2026
19 checks passed
@aayush-kapoor aayush-kapoor deleted the aayush/event-emitter branch February 25, 2026 15:34
@gr2m gr2m removed the ai/telemetry label Mar 6, 2026
@aayush-kapoor aayush-kapoor linked an issue Apr 9, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/core core functions like generateText, streamText, etc. Provider utils, and provider spec. feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

create a listener / emitter system for passing event data

3 participants