Skip to content

Commit 2e27f79

Browse files
committed
Name awsIntegration options type and share recording option lookup
1 parent 19528f9 commit 2e27f79

2 files changed

Lines changed: 13 additions & 7 deletions

File tree

‎packages/server-utils/src/integrations/aws-sdk/index.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ function setMetadataAttributes(span: Span, metadata: Record<string, any> | undef
6565
}
6666

6767
// `recordInputs` and `recordOutputs` apply to Bedrock Runtime calls, the only AWS calls that carry prompts and responses.
68-
const _awsIntegration = ((options?: GenAiOptions) => {
68+
export type AwsIntegrationOptions = GenAiOptions;
69+
70+
const _awsIntegration = ((options?: AwsIntegrationOptions) => {
6971
const servicesExtensions = new ServicesExtensions(options);
7072

7173
return {

‎packages/server-utils/src/integrations/aws-sdk/services/bedrock-runtime.ts‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)