1
- /* eslint-disable @typescript-eslint/no-dynamic-delete */
2
1
/* eslint-disable complexity */
3
2
import type { Client , IntegrationFn } from '@sentry/core' ;
4
3
import { defineIntegration , SEMANTIC_ATTRIBUTE_SENTRY_OP , spanToJSON } from '@sentry/core' ;
@@ -14,8 +13,10 @@ import {
14
13
AI_RESPONSE_TEXT_ATTRIBUTE ,
15
14
AI_RESPONSE_TOOL_CALLS_ATTRIBUTE ,
16
15
AI_TELEMETRY_FUNCTION_ID_ATTRIBUTE ,
16
+ AI_TOOL_CALL_ARGS_ATTRIBUTE ,
17
17
AI_TOOL_CALL_ID_ATTRIBUTE ,
18
18
AI_TOOL_CALL_NAME_ATTRIBUTE ,
19
+ AI_TOOL_CALL_RESULT_ATTRIBUTE ,
19
20
AI_USAGE_COMPLETION_TOKENS_ATTRIBUTE ,
20
21
AI_USAGE_PROMPT_TOKENS_ATTRIBUTE ,
21
22
GEN_AI_RESPONSE_MODEL_ATTRIBUTE ,
@@ -64,9 +65,17 @@ const _vercelAIIntegration = ((options: VercelAiOptions = {}) => {
64
65
) {
65
66
addOriginToSpan ( span , 'auto.vercelai.otel' ) ;
66
67
span . setAttribute ( SEMANTIC_ATTRIBUTE_SENTRY_OP , 'gen_ai.execute_tool' ) ;
67
- span . setAttribute ( 'gen_ai.tool.call.id' , attributes [ AI_TOOL_CALL_ID_ATTRIBUTE ] ) ;
68
- span . setAttribute ( 'gen_ai.tool.name' , attributes [ AI_TOOL_CALL_NAME_ATTRIBUTE ] ) ;
68
+ renameAttributeKey ( attributes , AI_TOOL_CALL_NAME_ATTRIBUTE , 'gen_ai.tool.name' ) ;
69
+ renameAttributeKey ( attributes , AI_TOOL_CALL_ID_ATTRIBUTE , 'gen_ai.tool.call.id' ) ;
70
+ renameAttributeKey ( attributes , AI_TOOL_CALL_ARGS_ATTRIBUTE , 'gen_ai.tool.input' ) ;
71
+ renameAttributeKey ( attributes , AI_TOOL_CALL_RESULT_ATTRIBUTE , 'gen_ai.tool.output' ) ;
69
72
span . updateName ( `execute_tool ${ attributes [ AI_TOOL_CALL_NAME_ATTRIBUTE ] } ` ) ;
73
+
74
+ // https://opentelemetry.io/docs/specs/semconv/registry/attributes/gen-ai/#gen-ai-tool-type
75
+ if ( ! attributes [ 'gen_ai.tool.type' ] ) {
76
+ span . setAttribute ( 'gen_ai.tool.type' , 'function' ) ;
77
+ }
78
+
70
79
return ;
71
80
}
72
81
@@ -93,7 +102,7 @@ const _vercelAIIntegration = ((options: VercelAiOptions = {}) => {
93
102
}
94
103
95
104
if ( attributes [ AI_PROMPT_ATTRIBUTE ] ) {
96
- span . setAttribute ( 'gen_ai.prompt' , attributes [ AI_PROMPT_ATTRIBUTE ] ) ;
105
+ renameAttributeKey ( attributes , AI_PROMPT_ATTRIBUTE , 'gen_ai.prompt' ) ;
97
106
}
98
107
if ( attributes [ AI_MODEL_ID_ATTRIBUTE ] && ! attributes [ GEN_AI_RESPONSE_MODEL_ATTRIBUTE ] ) {
99
108
span . setAttribute ( GEN_AI_RESPONSE_MODEL_ATTRIBUTE , attributes [ AI_MODEL_ID_ATTRIBUTE ] ) ;
@@ -268,6 +277,7 @@ export const vercelAIIntegration = defineIntegration(_vercelAIIntegration);
268
277
function renameAttributeKey ( attributes : Record < string , unknown > , oldKey : string , newKey : string ) : void {
269
278
if ( attributes [ oldKey ] != null ) {
270
279
attributes [ newKey ] = attributes [ oldKey ] ;
280
+ // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
271
281
delete attributes [ oldKey ] ;
272
282
}
273
283
}
0 commit comments