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 {