diff --git a/dev-packages/node-integration-tests/suites/tracing/vercelai/v6/scenario-tool-loop-agent.mjs b/dev-packages/node-integration-tests/suites/tracing/vercelai/v6/scenario-tool-loop-agent.mjs index fe485ce29a90..6967ec2efe94 100644 --- a/dev-packages/node-integration-tests/suites/tracing/vercelai/v6/scenario-tool-loop-agent.mjs +++ b/dev-packages/node-integration-tests/suites/tracing/vercelai/v6/scenario-tool-loop-agent.mjs @@ -8,7 +8,7 @@ async function run() { let callCount = 0; const agent = new ToolLoopAgent({ - experimental_telemetry: { isEnabled: true }, + experimental_telemetry: { isEnabled: true, functionId: 'weather_agent' }, model: new MockLanguageModelV3({ doGenerate: async () => { if (callCount++ === 0) { diff --git a/dev-packages/node-integration-tests/suites/tracing/vercelai/v6/test.ts b/dev-packages/node-integration-tests/suites/tracing/vercelai/v6/test.ts index 2c07366423cf..1b030804f8d2 100644 --- a/dev-packages/node-integration-tests/suites/tracing/vercelai/v6/test.ts +++ b/dev-packages/node-integration-tests/suites/tracing/vercelai/v6/test.ts @@ -619,6 +619,7 @@ describe('Vercel AI integration (V6)', () => { [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.vercelai.otel', [GEN_AI_REQUEST_MODEL_ATTRIBUTE]: 'mock-model-id', }), + description: 'invoke_agent weather_agent', op: 'gen_ai.invoke_agent', origin: 'auto.vercelai.otel', status: 'ok', @@ -633,6 +634,7 @@ describe('Vercel AI integration (V6)', () => { [GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE]: 20, [GEN_AI_RESPONSE_FINISH_REASONS_ATTRIBUTE]: ['tool-calls'], }), + description: 'generate_content mock-model-id', op: 'gen_ai.generate_content', origin: 'auto.vercelai.otel', status: 'ok', @@ -662,6 +664,7 @@ describe('Vercel AI integration (V6)', () => { [GEN_AI_USAGE_OUTPUT_TOKENS_ATTRIBUTE]: 25, [GEN_AI_RESPONSE_FINISH_REASONS_ATTRIBUTE]: ['stop'], }), + description: 'generate_content mock-model-id', op: 'gen_ai.generate_content', origin: 'auto.vercelai.otel', status: 'ok', diff --git a/packages/core/src/tracing/vercel-ai/index.ts b/packages/core/src/tracing/vercel-ai/index.ts index 569233cf8321..95bf550e5ff2 100644 --- a/packages/core/src/tracing/vercel-ai/index.ts +++ b/packages/core/src/tracing/vercel-ai/index.ts @@ -322,7 +322,13 @@ function processEndedVercelAiSpan(span: SpanJSON): void { // Rename AI SDK attributes to standardized gen_ai attributes // Map operation.name to OpenTelemetry semantic convention values if (attributes[OPERATION_NAME_ATTRIBUTE]) { - const operationName = mapVercelAiOperationName(attributes[OPERATION_NAME_ATTRIBUTE] as string); + // V6+ sets ai.operationId to the bare operation (e.g. "ai.streamText") while + // operation.name appends functionId (e.g. "ai.streamText myAgent"). + // When ai.operationId is present, use it for correct mapping. + const rawOperationName = attributes[AI_OPERATION_ID_ATTRIBUTE] + ? (attributes[AI_OPERATION_ID_ATTRIBUTE] as string) + : (attributes[OPERATION_NAME_ATTRIBUTE] as string); + const operationName = mapVercelAiOperationName(rawOperationName); attributes[GEN_AI_OPERATION_NAME_ATTRIBUTE] = operationName; // eslint-disable-next-line @typescript-eslint/no-dynamic-delete delete attributes[OPERATION_NAME_ATTRIBUTE];