@@ -12,7 +12,6 @@ import {
1212 GEN_AI_OPERATION_NAME_ATTRIBUTE ,
1313 GEN_AI_REQUEST_AVAILABLE_TOOLS_ATTRIBUTE ,
1414 GEN_AI_REQUEST_MODEL_ATTRIBUTE ,
15- GEN_AI_RESPONSE_TEXT_ATTRIBUTE ,
1615 GEN_AI_SYSTEM_ATTRIBUTE ,
1716 GEN_AI_SYSTEM_INSTRUCTIONS_ATTRIBUTE ,
1817} from '../ai/gen-ai-attributes' ;
@@ -26,18 +25,8 @@ import {
2625} from '../ai/utils' ;
2726import { OPENAI_METHOD_REGISTRY } from './constants' ;
2827import { instrumentStream } from './streaming' ;
29- import type { ChatCompletionChunk , OpenAiOptions , OpenAiResponse , OpenAIStream , ResponseStreamingEvent } from './types' ;
30- import {
31- addChatCompletionAttributes ,
32- addConversationAttributes ,
33- addEmbeddingsAttributes ,
34- addResponsesApiAttributes ,
35- extractRequestParameters ,
36- isChatCompletionResponse ,
37- isConversationResponse ,
38- isEmbeddingsResponse ,
39- isResponsesApiResponse ,
40- } from './utils' ;
28+ import type { ChatCompletionChunk , OpenAiOptions , OpenAIStream , ResponseStreamingEvent } from './types' ;
29+ import { addResponseAttributes , extractRequestParameters } from './utils' ;
4130
4231/**
4332 * Extract available tools from request parameters
@@ -88,33 +77,6 @@ function extractRequestAttributes(args: unknown[], operationName: string): Recor
8877 return attributes ;
8978}
9079
91- /**
92- * Add response attributes to spans
93- * This supports Chat Completion, Responses API, Embeddings, and Conversations API responses
94- */
95- function addResponseAttributes ( span : Span , result : unknown , recordOutputs ?: boolean ) : void {
96- if ( ! result || typeof result !== 'object' ) return ;
97-
98- const response = result as OpenAiResponse ;
99-
100- if ( isChatCompletionResponse ( response ) ) {
101- addChatCompletionAttributes ( span , response , recordOutputs ) ;
102- if ( recordOutputs && response . choices ?. length ) {
103- const responseTexts = response . choices . map ( choice => choice . message ?. content || '' ) ;
104- span . setAttributes ( { [ GEN_AI_RESPONSE_TEXT_ATTRIBUTE ] : JSON . stringify ( responseTexts ) } ) ;
105- }
106- } else if ( isResponsesApiResponse ( response ) ) {
107- addResponsesApiAttributes ( span , response , recordOutputs ) ;
108- if ( recordOutputs && response . output_text ) {
109- span . setAttributes ( { [ GEN_AI_RESPONSE_TEXT_ATTRIBUTE ] : response . output_text } ) ;
110- }
111- } else if ( isEmbeddingsResponse ( response ) ) {
112- addEmbeddingsAttributes ( span , response ) ;
113- } else if ( isConversationResponse ( response ) ) {
114- addConversationAttributes ( span , response ) ;
115- }
116- }
117-
11880// Extract and record AI request inputs, if present. This is intentionally separate from response attributes.
11981function addRequestAttributes ( span : Span , params : Record < string , unknown > , operationName : string ) : void {
12082 // Store embeddings input on a separate attribute and do not truncate it
0 commit comments