Skip to content

Commit 6750b12

Browse files
committed
feat(node): Update vercel ai integration attributes
1 parent 86d8994 commit 6750b12

File tree

2 files changed

+15
-7
lines changed
  • dev-packages/node-integration-tests/suites/tracing/vercelai
  • packages/core/src/utils

2 files changed

+15
-7
lines changed

dev-packages/node-integration-tests/suites/tracing/vercelai/test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,11 @@ describe('Vercel AI integration', () => {
182182
expect.objectContaining({
183183
data: {
184184
'ai.operationId': 'ai.toolCall',
185-
'ai.toolCall.id': 'call-1',
186-
'ai.toolCall.name': 'getWeather',
187185
'gen_ai.tool.call.id': 'call-1',
186+
'gen_ai.tool.input': expect.any(String),
188187
'gen_ai.tool.name': 'getWeather',
188+
'gen_ai.tool.output': expect.any(String),
189+
'gen_ai.tool.type': 'function',
189190
'operation.name': 'ai.toolCall',
190191
'sentry.op': 'gen_ai.execute_tool',
191192
'sentry.origin': 'auto.vercelai.otel',
@@ -390,11 +391,10 @@ describe('Vercel AI integration', () => {
390391
data: {
391392
'ai.operationId': 'ai.toolCall',
392393
'ai.toolCall.args': expect.any(String),
393-
'ai.toolCall.id': 'call-1',
394-
'ai.toolCall.name': 'getWeather',
395394
'ai.toolCall.result': expect.any(String),
396395
'gen_ai.tool.call.id': 'call-1',
397396
'gen_ai.tool.name': 'getWeather',
397+
'gen_ai.tool.type': 'function',
398398
'operation.name': 'ai.toolCall',
399399
'sentry.op': 'gen_ai.execute_tool',
400400
'sentry.origin': 'auto.vercelai.otel',

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ import {
1212
AI_RESPONSE_TEXT_ATTRIBUTE,
1313
AI_RESPONSE_TOOL_CALLS_ATTRIBUTE,
1414
AI_TELEMETRY_FUNCTION_ID_ATTRIBUTE,
15+
AI_TOOL_CALL_ARGS_ATTRIBUTE,
1516
AI_TOOL_CALL_ID_ATTRIBUTE,
1617
AI_TOOL_CALL_NAME_ATTRIBUTE,
18+
AI_TOOL_CALL_RESULT_ATTRIBUTE,
1719
AI_USAGE_COMPLETION_TOKENS_ATTRIBUTE,
1820
AI_USAGE_PROMPT_TOKENS_ATTRIBUTE,
1921
GEN_AI_RESPONSE_MODEL_ATTRIBUTE,
@@ -111,8 +113,14 @@ function renameAttributeKey(attributes: Record<string, unknown>, oldKey: string,
111113
function processToolCallSpan(span: Span, attributes: SpanAttributes): void {
112114
addOriginToSpan(span, 'auto.vercelai.otel');
113115
span.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_OP, 'gen_ai.execute_tool');
114-
span.setAttribute('gen_ai.tool.call.id', attributes[AI_TOOL_CALL_ID_ATTRIBUTE]);
115-
span.setAttribute('gen_ai.tool.name', attributes[AI_TOOL_CALL_NAME_ATTRIBUTE]);
116+
renameAttributeKey(attributes, AI_TOOL_CALL_NAME_ATTRIBUTE, 'gen_ai.tool.name');
117+
renameAttributeKey(attributes, AI_TOOL_CALL_ID_ATTRIBUTE, 'gen_ai.tool.call.id');
118+
renameAttributeKey(attributes, AI_TOOL_CALL_ARGS_ATTRIBUTE, 'gen_ai.tool.input');
119+
renameAttributeKey(attributes, AI_TOOL_CALL_RESULT_ATTRIBUTE, 'gen_ai.tool.output');
120+
// https://opentelemetry.io/docs/specs/semconv/registry/attributes/gen-ai/#gen-ai-tool-type
121+
if (!attributes['gen_ai.tool.type']) {
122+
span.setAttribute('gen_ai.tool.type', 'function');
123+
}
116124
span.updateName(`execute_tool ${attributes[AI_TOOL_CALL_NAME_ATTRIBUTE]}`);
117125
}
118126

@@ -127,7 +135,7 @@ function processGenerateSpan(span: Span, name: string, attributes: SpanAttribute
127135
const functionId = attributes[AI_TELEMETRY_FUNCTION_ID_ATTRIBUTE];
128136
if (functionId && typeof functionId === 'string' && name.split('.').length - 1 === 1) {
129137
span.updateName(`${nameWthoutAi} ${functionId}`);
130-
span.setAttribute('ai.pipeline.name', functionId);
138+
span.setAttribute('gen_ai.function_id', functionId);
131139
}
132140

133141
if (attributes[AI_PROMPT_ATTRIBUTE]) {

0 commit comments

Comments
 (0)