Skip to content

Commit 5c3175f

Browse files
authored
ref(core): Avoid side-effect of vercelAiEventProcessor (#16925)
This is pretty small, but apparently `Object.assign()` also counts as side effect. Part of #16846
1 parent 369e5c0 commit 5c3175f

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

packages/core/src/utils/vercel-ai.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,15 @@ function onVercelAiSpanStart(span: Span): void {
5757
processGenerateSpan(span, name, attributes);
5858
}
5959

60-
const vercelAiEventProcessor = Object.assign(
61-
(event: Event): Event => {
62-
if (event.type === 'transaction' && event.spans) {
63-
for (const span of event.spans) {
64-
// this mutates spans in-place
65-
processEndedVercelAiSpan(span);
66-
}
60+
function vercelAiEventProcessor(event: Event): Event {
61+
if (event.type === 'transaction' && event.spans) {
62+
for (const span of event.spans) {
63+
// this mutates spans in-place
64+
processEndedVercelAiSpan(span);
6765
}
68-
return event;
69-
},
70-
{ id: 'VercelAiEventProcessor' },
71-
);
72-
66+
}
67+
return event;
68+
}
7369
/**
7470
* Post-process spans emitted by the Vercel AI SDK.
7571
*/
@@ -236,5 +232,5 @@ function processGenerateSpan(span: Span, name: string, attributes: SpanAttribute
236232
export function addVercelAiProcessors(client: Client): void {
237233
client.on('spanStart', onVercelAiSpanStart);
238234
// Note: We cannot do this on `spanEnd`, because the span cannot be mutated anymore at this point
239-
client.addEventProcessor(vercelAiEventProcessor);
235+
client.addEventProcessor(Object.assign(vercelAiEventProcessor, { id: 'VercelAiEventProcessor' }));
240236
}

0 commit comments

Comments
 (0)