Skip to content

ref(core): Avoid side-effect of vercelAiEventProcessor #16925

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 14, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions packages/core/src/utils/vercel-ai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,15 @@ function onVercelAiSpanStart(span: Span): void {
processGenerateSpan(span, name, attributes);
}

const vercelAiEventProcessor = Object.assign(
(event: Event): Event => {
if (event.type === 'transaction' && event.spans) {
for (const span of event.spans) {
// this mutates spans in-place
processEndedVercelAiSpan(span);
}
function vercelAiEventProcessor(event: Event): Event {
if (event.type === 'transaction' && event.spans) {
for (const span of event.spans) {
// this mutates spans in-place
processEndedVercelAiSpan(span);
}
return event;
},
{ id: 'VercelAiEventProcessor' },
);

}
return event;
}
/**
* Post-process spans emitted by the Vercel AI SDK.
*/
Expand Down Expand Up @@ -229,5 +225,5 @@ function processGenerateSpan(span: Span, name: string, attributes: SpanAttribute
export function addVercelAiProcessors(client: Client): void {
client.on('spanStart', onVercelAiSpanStart);
// Note: We cannot do this on `spanEnd`, because the span cannot be mutated anymore at this point
client.addEventProcessor(vercelAiEventProcessor);
client.addEventProcessor(Object.assign(vercelAiEventProcessor, { id: 'VercelAiEventProcessor' }));
}
Loading