From 240b4f5779b41846bad099698d766f7ab3270f33 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Wed, 11 Jun 2025 16:10:10 +0200 Subject: [PATCH] feat(node): Allow to force activate `vercelAiIntegration` 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 }) ``` --- .../node/src/integrations/tracing/vercelai/index.ts | 10 ++++++++-- .../node/src/integrations/tracing/vercelai/types.ts | 6 ++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/node/src/integrations/tracing/vercelai/index.ts b/packages/node/src/integrations/tracing/vercelai/index.ts index 2c5faf04acef..d2f73e02adc3 100644 --- a/packages/node/src/integrations/tracing/vercelai/index.ts +++ b/packages/node/src/integrations/tracing/vercelai/index.ts @@ -33,7 +33,7 @@ const _vercelAIIntegration = ((options: VercelAiOptions = {}) => { instrumentation = instrumentVercelAi(); }, setup(client) { - instrumentation?.callWhenPatched(() => { + function registerProcessors(): void { client.on('spanStart', span => { const { data: attributes, description: name } = spanToJSON(span); @@ -188,7 +188,13 @@ const _vercelAIIntegration = ((options: VercelAiOptions = {}) => { return event; }); - }); + } + + if (options.force) { + registerProcessors(); + } else { + instrumentation?.callWhenPatched(registerProcessors); + } }, }; }) satisfies IntegrationFn; diff --git a/packages/node/src/integrations/tracing/vercelai/types.ts b/packages/node/src/integrations/tracing/vercelai/types.ts index 50434b70604f..35cfeb33a112 100644 --- a/packages/node/src/integrations/tracing/vercelai/types.ts +++ b/packages/node/src/integrations/tracing/vercelai/types.ts @@ -56,6 +56,12 @@ export interface VercelAiOptions { * or if you set `isEnabled` to `true` in your ai SDK method telemetry settings */ recordOutputs?: boolean; + + /** + * By default, the instrumentation will register span processors only when the ai package is used. + * If you want to register the span processors even when the ai package usage cannot be detected, you can set `force` to `true`. + */ + force?: boolean; } export interface VercelAiIntegration extends Integration {