Skip to content

Commit 88e3f8f

Browse files
authored
feat(node): Allow to force activate vercelAiIntegration (#16551)
By default, the instrumentation will register span processors only when the ai package is used. This is done to avoid overhead of span processing for users that do not even use this package. However, it seems that in some environments, esp. in Next.js, the instrumentation is not added correctly, thus never running this, and not converting spans correctly. For now, this PR adds an escape hatch to manually opt-in to this to still get correct spans: ```js vercelAiIntegration({ force: true }) ```
1 parent fee86b0 commit 88e3f8f

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

packages/node/src/integrations/tracing/vercelai/index.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const _vercelAIIntegration = ((options: VercelAiOptions = {}) => {
3333
instrumentation = instrumentVercelAi();
3434
},
3535
setup(client) {
36-
instrumentation?.callWhenPatched(() => {
36+
function registerProcessors(): void {
3737
client.on('spanStart', span => {
3838
const { data: attributes, description: name } = spanToJSON(span);
3939

@@ -188,7 +188,13 @@ const _vercelAIIntegration = ((options: VercelAiOptions = {}) => {
188188

189189
return event;
190190
});
191-
});
191+
}
192+
193+
if (options.force) {
194+
registerProcessors();
195+
} else {
196+
instrumentation?.callWhenPatched(registerProcessors);
197+
}
192198
},
193199
};
194200
}) satisfies IntegrationFn;

packages/node/src/integrations/tracing/vercelai/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ export interface VercelAiOptions {
5656
* or if you set `isEnabled` to `true` in your ai SDK method telemetry settings
5757
*/
5858
recordOutputs?: boolean;
59+
60+
/**
61+
* By default, the instrumentation will register span processors only when the ai package is used.
62+
* If you want to register the span processors even when the ai package usage cannot be detected, you can set `force` to `true`.
63+
*/
64+
force?: boolean;
5965
}
6066

6167
export interface VercelAiIntegration extends Integration {

0 commit comments

Comments
 (0)