@@ -69,11 +69,9 @@ export async function generateTextPatchAnthropic (
6969 try {
7070 const resp = await originalMethod . apply ( this , args )
7171 const responses = JSON . stringify ( resp ?. responseMessages )
72- span . addEvent ( Event . GEN_AI_PROMPT , {
73- 'gen_ai.prompt' : JSON . stringify ( [
74- { role : 'user' , content : args [ 0 ] ?. prompt }
75- ] )
76- } )
72+ // set content to either prompt or messages
73+ const content = args [ 0 ] ?. prompt ?? JSON . stringify ( args [ 0 ] ?. messages )
74+ span . addEvent ( Event . GEN_AI_PROMPT , { 'gen_ai.prompt' : content } )
7775 span . addEvent ( Event . GEN_AI_COMPLETION , { 'gen_ai.completion' : responses } )
7876 const responseAttributes : Partial < LLMSpanAttributes > = {
7977 'url.full' : url ,
@@ -146,7 +144,8 @@ export async function streamTextPatchAnthropic (
146144 return await context . with ( trace . setSpan ( context . active ( ) , span ) , async ( ) => {
147145 try {
148146 const resp : any = await originalMethod . apply ( this , args )
149- addSpanEvent ( span , Event . GEN_AI_PROMPT , { 'gen_ai.prompt' : JSON . stringify ( args [ 0 ] ?. prompt ) } )
147+ const content = args [ 0 ] ?. prompt ?? JSON . stringify ( args [ 0 ] ?. messages )
148+ addSpanEvent ( span , Event . GEN_AI_PROMPT , { 'gen_ai.prompt' : content } )
150149 const responseAttributes : Partial < LLMSpanAttributes > = {
151150 'url.full' : url ,
152151 'url.path' : APIS . anthropic . MESSAGES_CREATE . ENDPOINT
@@ -231,11 +230,8 @@ export async function generateObjectPatchAnthropic (
231230 try {
232231 const resp = await originalMethod . apply ( this , args )
233232 const responses = JSON . stringify ( resp ?. object )
234- span . addEvent ( Event . GEN_AI_PROMPT , {
235- 'gen_ai.prompt' : JSON . stringify ( [
236- { role : 'user' , content : args [ 0 ] ?. prompt }
237- ] )
238- } )
233+ const content = args [ 0 ] ?. prompt ?? JSON . stringify ( args [ 0 ] ?. messages )
234+ span . addEvent ( Event . GEN_AI_PROMPT , { 'gen_ai.prompt' : content } )
239235 span . addEvent ( Event . GEN_AI_COMPLETION , { 'gen_ai.completion' : responses } )
240236 const responseAttributes : Partial < LLMSpanAttributes > = {
241237 'url.full' : url ,
@@ -308,7 +304,8 @@ export async function streamObjectPatchAnthropic (
308304 return await context . with ( trace . setSpan ( context . active ( ) , span ) , async ( ) => {
309305 try {
310306 const resp : any = await originalMethod . apply ( this , args )
311- addSpanEvent ( span , Event . GEN_AI_PROMPT , { 'gen_ai.prompt' : JSON . stringify ( args [ 0 ] ?. prompt ) } )
307+ const content = args [ 0 ] ?. prompt ?? JSON . stringify ( args [ 0 ] ?. messages )
308+ addSpanEvent ( span , Event . GEN_AI_PROMPT , { 'gen_ai.prompt' : content } )
312309 const responseAttributes : Partial < LLMSpanAttributes > = {
313310 'url.full' : url ,
314311 'url.path' : APIS . anthropic . MESSAGES_CREATE . ENDPOINT
0 commit comments