Skip to content

Commit d176053

Browse files
committed
.
1 parent b9de893 commit d176053

File tree

1 file changed

+7
-3
lines changed
  • packages/core/src/tracing/vercel-ai

1 file changed

+7
-3
lines changed

packages/core/src/tracing/vercel-ai/index.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable max-lines */
22
import type { Client } from '../../client';
3+
import { getClient } from '../../currentScopes';
34
import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '../../semanticAttributes';
45
import type { Event } from '../../types-hoist/event';
56
import 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
*/
450454
export 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

Comments
 (0)