11/* eslint-disable max-lines */
22import type { Client } from '../../client' ;
3+ import { getClient } from '../../currentScopes' ;
34import { SEMANTIC_ATTRIBUTE_SENTRY_OP , SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '../../semanticAttributes' ;
45import type { Event } from '../../types-hoist/event' ;
56import type { Span , SpanAttributes , SpanAttributeValue , SpanJSON } from '../../types-hoist/span' ;
@@ -94,7 +95,7 @@ function mapVercelAiOperationName(operationName: string): string {
9495 * Post-process spans emitted by the Vercel AI SDK.
9596 * This is supposed to be used in `client.on('spanStart', ...)
9697 */
97- function onVercelAiSpanStart ( span : Span , client : Client ) : void {
98+ function onVercelAiSpanStart ( span : Span ) : void {
9899 const { data : attributes , description : name } = spanToJSON ( span ) ;
99100
100101 if ( ! name ) {
@@ -114,7 +115,10 @@ function onVercelAiSpanStart(span: Span, client: Client): void {
114115 return ;
115116 }
116117
117- const integration = client . getIntegrationByName ( 'VercelAI' ) as { options ?: { enableTruncation ?: boolean } } | undefined ;
118+ const client = getClient ( ) ;
119+ const integration = client ?. getIntegrationByName ( 'VercelAI' ) as
120+ | { options ?: { enableTruncation ?: boolean } }
121+ | undefined ;
118122 const enableTruncation = integration ?. options ?. enableTruncation ?? true ;
119123
120124 processGenerateSpan ( span , name , attributes , enableTruncation ) ;
@@ -448,7 +452,7 @@ function processGenerateSpan(span: Span, name: string, attributes: SpanAttribute
448452 * Add event processors to the given client to process Vercel AI spans.
449453 */
450454export function addVercelAiProcessors ( client : Client ) : void {
451- client . on ( 'spanStart' , span => onVercelAiSpanStart ( span , client ) ) ;
455+ client . on ( 'spanStart' , onVercelAiSpanStart ) ;
452456 // Note: We cannot do this on `spanEnd`, because the span cannot be mutated anymore at this point
453457 client . addEventProcessor ( Object . assign ( vercelAiEventProcessor , { id : 'VercelAiEventProcessor' } ) ) ;
454458}
0 commit comments