@@ -351,10 +351,11 @@ export class BedrockInstrumentation extends InstrumentationBase {
351351 if ( requestBody [ "messages" ] ) {
352352 const promptAttributes : Record < string , any > = { } ;
353353 requestBody [ "messages" ] . forEach ( ( message : any , index : number ) => {
354- promptAttributes [ `${ SpanAttributes . LLM_PROMPTS } .${ index } .role` ] = message . role ;
355- promptAttributes [ `${ SpanAttributes . LLM_PROMPTS } .${ index } .content` ] =
356- typeof message . content === "string"
357- ? message . content
354+ promptAttributes [ `${ SpanAttributes . LLM_PROMPTS } .${ index } .role` ] =
355+ message . role ;
356+ promptAttributes [ `${ SpanAttributes . LLM_PROMPTS } .${ index } .content` ] =
357+ typeof message . content === "string"
358+ ? message . content
358359 : JSON . stringify ( message . content ) ;
359360 } ) ;
360361 return { ...baseAttributes , ...promptAttributes } ;
@@ -469,7 +470,7 @@ export class BedrockInstrumentation extends InstrumentationBase {
469470
470471 // Handle new messages API format response
471472 if ( response [ "content" ] ) {
472- const content = Array . isArray ( response [ "content" ] )
473+ const content = Array . isArray ( response [ "content" ] )
473474 ? response [ "content" ] . map ( ( c : any ) => c . text || c ) . join ( "" )
474475 : response [ "content" ] ;
475476 return {
@@ -482,7 +483,8 @@ export class BedrockInstrumentation extends InstrumentationBase {
482483 if ( response [ "completion" ] ) {
483484 return {
484485 ...baseAttributes ,
485- [ `${ SpanAttributes . LLM_COMPLETIONS } .0.content` ] : response [ "completion" ] ,
486+ [ `${ SpanAttributes . LLM_COMPLETIONS } .0.content` ] :
487+ response [ "completion" ] ,
486488 } ;
487489 }
488490
@@ -491,12 +493,12 @@ export class BedrockInstrumentation extends InstrumentationBase {
491493 case "cohere" : {
492494 const baseAttributes = {
493495 [ `${ SpanAttributes . LLM_COMPLETIONS } .0.finish_reason` ] :
494- response [ "finish_reason" ] ,
496+ response [ "generations" ] ?. [ 0 ] ?. [ " finish_reason"] ,
495497 [ `${ SpanAttributes . LLM_COMPLETIONS } .0.role` ] : "assistant" ,
496498 ...( this . _shouldSendPrompts ( )
497499 ? {
498500 [ `${ SpanAttributes . LLM_COMPLETIONS } .0.content` ] :
499- response [ "text" ] ,
501+ response [ "generations" ] ?. [ 0 ] ?. [ " text"] ,
500502 }
501503 : { } ) ,
502504 } ;
@@ -506,10 +508,13 @@ export class BedrockInstrumentation extends InstrumentationBase {
506508 const billedUnits = response [ "meta" ] [ "billed_units" ] ;
507509 return {
508510 ...baseAttributes ,
509- [ SpanAttributes . LLM_USAGE_PROMPT_TOKENS ] : billedUnits [ "input_tokens" ] ,
510- [ SpanAttributes . LLM_USAGE_COMPLETION_TOKENS ] : billedUnits [ "output_tokens" ] ,
511- [ SpanAttributes . LLM_USAGE_TOTAL_TOKENS ] :
512- ( billedUnits [ "input_tokens" ] || 0 ) + ( billedUnits [ "output_tokens" ] || 0 ) ,
511+ [ SpanAttributes . LLM_USAGE_PROMPT_TOKENS ] :
512+ billedUnits [ "input_tokens" ] ,
513+ [ SpanAttributes . LLM_USAGE_COMPLETION_TOKENS ] :
514+ billedUnits [ "output_tokens" ] ,
515+ [ SpanAttributes . LLM_USAGE_TOTAL_TOKENS ] :
516+ ( billedUnits [ "input_tokens" ] || 0 ) +
517+ ( billedUnits [ "output_tokens" ] || 0 ) ,
513518 } ;
514519 }
515520
0 commit comments