@@ -11,7 +11,8 @@ const { MEASURED } = require('../../../ext/tags')
1111const {
1212 convertBuffersToObjects,
1313 constructCompletionResponseFromStreamedChunks,
14- constructChatCompletionResponseFromStreamedChunks
14+ constructChatCompletionResponseFromStreamedChunks,
15+ constructResponseResponseFromStreamedChunks
1516} = require ( './stream-helpers' )
1617
1718const { DD_MAJOR } = require ( '../../../version' )
@@ -59,6 +60,8 @@ class OpenAiTracingPlugin extends TracingPlugin {
5960 response = constructCompletionResponseFromStreamedChunks ( chunks , n )
6061 } else if ( methodName === 'createChatCompletion' ) {
6162 response = constructChatCompletionResponseFromStreamedChunks ( chunks , n )
63+ } else if ( methodName === 'createResponse' ) {
64+ response = constructResponseResponseFromStreamedChunks ( chunks )
6265 }
6366
6467 ctx . result = { data : response }
@@ -134,6 +137,10 @@ class OpenAiTracingPlugin extends TracingPlugin {
134137 case 'createEdit' :
135138 createEditRequestExtraction ( tags , payload , openaiStore )
136139 break
140+
141+ case 'createResponse' :
142+ createResponseRequestExtraction ( tags , payload , openaiStore )
143+ break
137144 }
138145
139146 span . addTags ( tags )
@@ -313,6 +320,10 @@ function normalizeMethodName (methodName) {
313320 case 'embeddings.create' :
314321 return 'createEmbedding'
315322
323+ // responses
324+ case 'responses.create' :
325+ return 'createResponse'
326+
316327 // files
317328 case 'files.create' :
318329 return 'createFile'
@@ -376,6 +387,16 @@ function createEditRequestExtraction (tags, payload, openaiStore) {
376387 openaiStore . instruction = instruction
377388}
378389
390+ function createResponseRequestExtraction ( tags , payload , openaiStore ) {
391+ // Extract model information
392+ if ( payload . model ) {
393+ tags [ 'openai.request.model' ] = payload . model
394+ }
395+
396+ // Store the full payload for response extraction
397+ openaiStore . responseData = payload
398+ }
399+
379400function retrieveModelRequestExtraction ( tags , payload ) {
380401 tags [ 'openai.request.id' ] = payload . id
381402}
@@ -410,6 +431,10 @@ function responseDataExtractionByMethod (methodName, tags, body, openaiStore) {
410431 commonCreateResponseExtraction ( tags , body , openaiStore , methodName )
411432 break
412433
434+ case 'createResponse' :
435+ createResponseResponseExtraction ( tags , body , openaiStore )
436+ break
437+
413438 case 'listFiles' :
414439 case 'listFineTunes' :
415440 case 'listFineTuneEvents' :
@@ -513,6 +538,26 @@ function commonCreateResponseExtraction (tags, body, openaiStore, methodName) {
513538 openaiStore . choices = body . choices
514539}
515540
541+ function createResponseResponseExtraction ( tags , body , openaiStore ) {
542+ // Extract response ID if available
543+ if ( body . id ) {
544+ tags [ 'openai.response.id' ] = body . id
545+ }
546+
547+ // Extract status if available
548+ if ( body . status ) {
549+ tags [ 'openai.response.status' ] = body . status
550+ }
551+
552+ // Extract model from response if available
553+ if ( body . model ) {
554+ tags [ 'openai.response.model' ] = body . model
555+ }
556+
557+ // Store the full response for potential future use
558+ openaiStore . response = body
559+ }
560+
516561// The server almost always responds with JSON
517562function coerceResponseBody ( body , methodName ) {
518563 switch ( methodName ) {
0 commit comments