@@ -73,6 +73,10 @@ export class BedrockRuntimeServiceExtension implements ServiceExtension {
7373
7474 public constructor ( private readonly _options : GenAiOptions = { } ) { }
7575
76+ private _recordingOptions ( ) : Required < GenAiOptions > {
77+ return resolveAIRecordingOptions ( this . _options ) ;
78+ }
79+
7680 public requestPreSpanHook ( request : NormalizedRequest ) : RequestMetadata {
7781 if ( isInsidePiAiSpan ( ) ) {
7882 this . _piAiRequests . add ( request ) ;
@@ -154,7 +158,7 @@ export class BedrockRuntimeServiceExtension implements ServiceExtension {
154158 }
155159 }
156160
157- if ( resolveAIRecordingOptions ( this . _options ) . recordInputs ) {
161+ if ( this . _recordingOptions ( ) . recordInputs ) {
158162 Object . assign ( spanAttributes , getConverseInputAttributes ( request . commandInput ) ) ;
159163 }
160164
@@ -283,7 +287,7 @@ export class BedrockRuntimeServiceExtension implements ServiceExtension {
283287 }
284288 }
285289
286- if ( resolveAIRecordingOptions ( this . _options ) . recordInputs ) {
290+ if ( this . _recordingOptions ( ) . recordInputs ) {
287291 Object . assign ( spanAttributes , getInvokeModelInputAttributes ( modelId , requestBody ) ) ;
288292 }
289293 }
@@ -300,7 +304,7 @@ export class BedrockRuntimeServiceExtension implements ServiceExtension {
300304 const { stopReason, usage, output } = response . data ;
301305
302306 setStopReason ( span , stopReason ) ;
303- if ( resolveAIRecordingOptions ( this . _options ) . recordOutputs ) {
307+ if ( this . _recordingOptions ( ) . recordOutputs ) {
304308 setOutputMessages ( span , contentBlocksToParts ( output ?. message ?. content ) ) ;
305309 }
306310 span . setAttributes (
@@ -328,7 +332,7 @@ export class BedrockRuntimeServiceExtension implements ServiceExtension {
328332 response . data . stream as AsyncIterable < ConverseStreamOutput > ,
329333 span ,
330334 response . request . abortSignal ,
331- resolveAIRecordingOptions ( this . _options ) . recordOutputs ,
335+ this . _recordingOptions ( ) . recordOutputs ,
332336 processConverseStreamEvent ,
333337 ) ;
334338 }
@@ -396,7 +400,7 @@ export class BedrockRuntimeServiceExtension implements ServiceExtension {
396400 span . setAttribute ( GEN_AI_USAGE_OUTPUT_TOKENS , Math . ceil ( responseBody . outputs [ 0 ] . text . length / 6 ) ) ;
397401 }
398402 }
399- if ( resolveAIRecordingOptions ( this . _options ) . recordOutputs ) {
403+ if ( this . _recordingOptions ( ) . recordOutputs ) {
400404 setOutputMessages ( span , getInvokeModelOutputParts ( responseBody ) ) ;
401405 }
402406 }
@@ -420,7 +424,7 @@ export class BedrockRuntimeServiceExtension implements ServiceExtension {
420424 stream as AsyncIterable < { chunk ?: { bytes ?: Uint8Array } } > ,
421425 span ,
422426 response . request . abortSignal ,
423- resolveAIRecordingOptions ( this . _options ) . recordOutputs ,
427+ this . _recordingOptions ( ) . recordOutputs ,
424428 ( item , state ) => {
425429 if ( processChunk ) {
426430 const parsedChunk = parseChunk ( item ?. chunk ?. bytes ) ;
0 commit comments