Skip to content

Commit c5bbdc6

Browse files
authored
fix(core): Remove check and always respect ai.telemetry.functionId for Vercel AI gen spans (#17811)
This PR fixes a mismatch between ai.telemetry.functionId and gen_ai.function_id. Function ids were ignored unless the span name contained exactly one dot. This caused: - gen_ai.function_id to be missing or inconsistent for valid generation spans. - Mismatch between ai.telemetry.functionId and gen_ai.function_id, making trace exploration and metrics harder to interpret. We now always respect experimental_telemetry.functionId when present, where function id could be set as part of request. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Always update Vercel AI generate span names and set `gen_ai.function_id` when `experimental_telemetry.functionId` is present, removing the dot-count check. > > - **Core (Vercel AI span processing)**: > - In `packages/core/src/utils/vercel-ai/index.ts` `processGenerateSpan`: > - Remove `name.split('.')` dot-count check; always apply `experimental_telemetry.functionId`. > - When present, append function ID to the operation name and set `gen_ai.function_id`. > - Clarify comments on telemetry function ID usage. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 4b9fa48. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent b6d4bc2 commit c5bbdc6

File tree

1 file changed

+3
-2
lines changed
  • packages/core/src/utils/vercel-ai

1 file changed

+3
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,10 @@ function processGenerateSpan(span: Span, name: string, attributes: SpanAttribute
178178
span.setAttribute('ai.pipeline.name', nameWthoutAi);
179179
span.updateName(nameWthoutAi);
180180

181-
// If a Telemetry name is set and it is a pipeline span, use that as the operation name
181+
// If a telemetry name is set and the span represents a pipeline, use it as the operation name.
182+
// This name can be set at the request level by adding `experimental_telemetry.functionId`.
182183
const functionId = attributes[AI_TELEMETRY_FUNCTION_ID_ATTRIBUTE];
183-
if (functionId && typeof functionId === 'string' && name.split('.').length - 1 === 1) {
184+
if (functionId && typeof functionId === 'string') {
184185
span.updateName(`${nameWthoutAi} ${functionId}`);
185186
span.setAttribute('gen_ai.function_id', functionId);
186187
}

0 commit comments

Comments
 (0)