@opentelemetry/instrumentation-aws-sdk 0.62.0 → 0.64.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -63,7 +63,7 @@ The instrumentations are collecting the following attributes:
63
63
  | Attribute Name | Type | Description | Example |
64
64
  | -------------- | ---- | ----------- | ------- |
65
65
  | `rpc.system` | string | Always equals "aws-api" | |
66
- | `rpc.method` | string | he name of the operation corresponding to the request, as returned by the AWS SDK. If the SDK does not provide a way to retrieve a name, the name of the command SHOULD be used, removing the suffix `Command` if present, resulting in a PascalCase name with no spaces. | `PutObject` |
66
+ | `rpc.method` | string | The name of the operation corresponding to the request, as returned by the AWS SDK. If the SDK does not provide a way to retrieve a name, the name of the command SHOULD be used, removing the suffix `Command` if present, resulting in a PascalCase name with no spaces. | `PutObject` |
67
67
  | `rpc.service` | string | The name of the service to which a request is made, as returned by the AWS SDK. If the SDK does not provide a away to retrieve a name, the name of the SDK's client interface for a service SHOULD be used, removing the suffix `Client` if present, resulting in a PascalCase name with no spaces. | `S3`, `DynamoDB`, `Route53` |
68
68
  | `cloud.region` | string | Region name for the request | "eu-west-1" |
69
69
 
@@ -1 +1 @@
1
- {"version":3,"file":"aws-sdk.types.js","sourceRoot":"","sources":["../../src/aws-sdk.types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/*\n * AWS SDK for JavaScript\n * Copyright 2012-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * This product includes software developed at\n * Amazon Web Services, Inc. (http://aws.amazon.com/).\n */\n\n/*\n These are slightly modified and simplified versions of the actual SQS types included\n in the official distribution:\n https://github.com/aws/aws-sdk-js/blob/master/clients/sqs.d.ts\n These are brought here to avoid having users install the `aws-sdk` whenever they\n require this instrumentation.\n*/\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface -- Our lint doesn't like it, but we prefer to keep it the way original source code has it\ninterface Blob {}\ntype Binary = Buffer | Uint8Array | Blob | string;\n\n// eslint-disable-next-line @typescript-eslint/no-namespace -- Prefer to contain the types copied over in one location\nexport namespace SNS {\n interface MessageAttributeValue {\n /**\n * Amazon SNS supports the following logical data types: String, String.Array, Number, and Binary. For more information, see Message Attribute Data Types.\n */\n DataType: string;\n /**\n * Strings are Unicode with UTF8 binary encoding. For a list of code values, see ASCII Printable Characters.\n */\n StringValue?: string;\n /**\n * Binary type attributes can store any binary data, for example, compressed data, encrypted data, or images.\n */\n BinaryValue?: Binary;\n }\n\n export type MessageAttributeMap = { [key: string]: MessageAttributeValue };\n}\n\n// eslint-disable-next-line @typescript-eslint/no-namespace -- Prefer to contain the types copied over in one location\nexport namespace SQS {\n type StringList = string[];\n type BinaryList = Binary[];\n interface MessageAttributeValue {\n /**\n * Strings are Unicode with UTF-8 binary encoding. For a list of code values, see ASCII Printable Characters.\n */\n StringValue?: string;\n /**\n * Binary type attributes can store any binary data, such as compressed data, encrypted data, or images.\n */\n BinaryValue?: Binary;\n /**\n * Not implemented. Reserved for future use.\n */\n StringListValues?: StringList;\n /**\n * Not implemented. Reserved for future use.\n */\n BinaryListValues?: BinaryList;\n /**\n * Amazon SQS supports the following logical data types: String, Number, and Binary. For the Number data type, you must use StringValue. You can also append custom labels. For more information, see Amazon SQS Message Attributes in the Amazon SQS Developer Guide.\n */\n DataType: string;\n }\n\n export type MessageBodyAttributeMap = {\n [key: string]: MessageAttributeValue;\n };\n\n type MessageSystemAttributeMap = { [key: string]: string };\n\n export interface Message {\n /**\n * A unique identifier for the message. A MessageId is considered unique across all accounts for an extended period of time.\n */\n MessageId?: string;\n /**\n * An identifier associated with the act of receiving the message. A new receipt handle is returned every time you receive a message. When deleting a message, you provide the last received receipt handle to delete the message.\n */\n ReceiptHandle?: string;\n /**\n * An MD5 digest of the non-URL-encoded message body string.\n */\n MD5OfBody?: string;\n /**\n * The message's contents (not URL-encoded).\n */\n Body?: string;\n /**\n * A map of the attributes requested in ReceiveMessage to their respective values. Supported attributes: ApproximateReceiveCount ApproximateFirstReceiveTimestamp MessageDeduplicationId MessageGroupId SenderId SentTimestamp SequenceNumber ApproximateFirstReceiveTimestamp and SentTimestamp are each returned as an integer representing the epoch time in milliseconds.\n */\n Attributes?: MessageSystemAttributeMap;\n /**\n * An MD5 digest of the non-URL-encoded message attribute string. You can use this attribute to verify that Amazon SQS received the message correctly. Amazon SQS URL-decodes the message before creating the MD5 digest. For information about MD5, see RFC1321.\n */\n MD5OfMessageAttributes?: string;\n /**\n * Each message attribute consists of a Name, Type, and Value. For more information, see Amazon SQS message attributes in the Amazon SQS Developer Guide.\n */\n MessageAttributes?: MessageBodyAttributeMap;\n }\n}\n"]}
1
+ {"version":3,"file":"aws-sdk.types.js","sourceRoot":"","sources":["../../src/aws-sdk.types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/*\n * AWS SDK for JavaScript\n * Copyright 2012-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n *\n * This product includes software developed at\n * Amazon Web Services, Inc. (http://aws.amazon.com/).\n */\n\n/*\n These are slightly modified and simplified versions of the actual SQS types included\n in the official distribution:\n https://github.com/aws/aws-sdk-js/blob/master/clients/sqs.d.ts\n These are brought here to avoid having users install the `aws-sdk` whenever they\n require this instrumentation.\n*/\n\ninterface Blob {}\ntype Binary = Buffer | Uint8Array | Blob | string;\n\n// eslint-disable-next-line @typescript-eslint/no-namespace -- Prefer to contain the types copied over in one location\nexport namespace SNS {\n interface MessageAttributeValue {\n /**\n * Amazon SNS supports the following logical data types: String, String.Array, Number, and Binary. For more information, see Message Attribute Data Types.\n */\n DataType: string;\n /**\n * Strings are Unicode with UTF8 binary encoding. For a list of code values, see ASCII Printable Characters.\n */\n StringValue?: string;\n /**\n * Binary type attributes can store any binary data, for example, compressed data, encrypted data, or images.\n */\n BinaryValue?: Binary;\n }\n\n export type MessageAttributeMap = { [key: string]: MessageAttributeValue };\n}\n\n// eslint-disable-next-line @typescript-eslint/no-namespace -- Prefer to contain the types copied over in one location\nexport namespace SQS {\n type StringList = string[];\n type BinaryList = Binary[];\n interface MessageAttributeValue {\n /**\n * Strings are Unicode with UTF-8 binary encoding. For a list of code values, see ASCII Printable Characters.\n */\n StringValue?: string;\n /**\n * Binary type attributes can store any binary data, such as compressed data, encrypted data, or images.\n */\n BinaryValue?: Binary;\n /**\n * Not implemented. Reserved for future use.\n */\n StringListValues?: StringList;\n /**\n * Not implemented. Reserved for future use.\n */\n BinaryListValues?: BinaryList;\n /**\n * Amazon SQS supports the following logical data types: String, Number, and Binary. For the Number data type, you must use StringValue. You can also append custom labels. For more information, see Amazon SQS Message Attributes in the Amazon SQS Developer Guide.\n */\n DataType: string;\n }\n\n export type MessageBodyAttributeMap = {\n [key: string]: MessageAttributeValue;\n };\n\n type MessageSystemAttributeMap = { [key: string]: string };\n\n export interface Message {\n /**\n * A unique identifier for the message. A MessageId is considered unique across all accounts for an extended period of time.\n */\n MessageId?: string;\n /**\n * An identifier associated with the act of receiving the message. A new receipt handle is returned every time you receive a message. When deleting a message, you provide the last received receipt handle to delete the message.\n */\n ReceiptHandle?: string;\n /**\n * An MD5 digest of the non-URL-encoded message body string.\n */\n MD5OfBody?: string;\n /**\n * The message's contents (not URL-encoded).\n */\n Body?: string;\n /**\n * A map of the attributes requested in ReceiveMessage to their respective values. Supported attributes: ApproximateReceiveCount ApproximateFirstReceiveTimestamp MessageDeduplicationId MessageGroupId SenderId SentTimestamp SequenceNumber ApproximateFirstReceiveTimestamp and SentTimestamp are each returned as an integer representing the epoch time in milliseconds.\n */\n Attributes?: MessageSystemAttributeMap;\n /**\n * An MD5 digest of the non-URL-encoded message attribute string. You can use this attribute to verify that Amazon SQS received the message correctly. Amazon SQS URL-decodes the message before creating the MD5 digest. For information about MD5, see RFC1321.\n */\n MD5OfMessageAttributes?: string;\n /**\n * Each message attribute consists of a Name, Type, and Value. For more information, see Amazon SQS message attributes in the Amazon SQS Developer Guide.\n */\n MessageAttributes?: MessageBodyAttributeMap;\n }\n}\n"]}
@@ -4,6 +4,7 @@ import { AwsSdkInstrumentationConfig, NormalizedRequest, NormalizedResponse } fr
4
4
  export declare class BedrockRuntimeServiceExtension implements ServiceExtension {
5
5
  private tokenUsage;
6
6
  private operationDuration;
7
+ private _diag;
7
8
  updateMetricInstruments(meter: Meter): void;
8
9
  requestPreSpanHook(request: NormalizedRequest, config: AwsSdkInstrumentationConfig, diag: DiagLogger): RequestMetadata;
9
10
  private requestPreSpanHookConverse;
@@ -15,5 +16,14 @@ export declare class BedrockRuntimeServiceExtension implements ServiceExtension
15
16
  private static setStopReason;
16
17
  private setUsage;
17
18
  private responseHookInvokeModel;
19
+ private responseHookInvokeModelWithResponseStream;
20
+ private parseChunk;
21
+ private static recordNovaAttributes;
22
+ private static recordClaudeAttributes;
23
+ private static recordTitanAttributes;
24
+ private static recordLlamaAttributes;
25
+ private static recordMistralAttributes;
26
+ private static recordCohereAttributes;
27
+ private static recordCohereRAttributes;
18
28
  }
19
29
  //# sourceMappingURL=bedrock-runtime.d.ts.map
@@ -22,6 +22,7 @@ const core_1 = require("@opentelemetry/core");
22
22
  class BedrockRuntimeServiceExtension {
23
23
  tokenUsage;
24
24
  operationDuration;
25
+ _diag = api_1.diag;
25
26
  updateMetricInstruments(meter) {
26
27
  // https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-metrics/#metric-gen_aiclienttokenusage
27
28
  this.tokenUsage = meter.createHistogram(semconv_1.METRIC_GEN_AI_CLIENT_TOKEN_USAGE, {
@@ -54,7 +55,9 @@ class BedrockRuntimeServiceExtension {
54
55
  case 'ConverseStream':
55
56
  return this.requestPreSpanHookConverse(request, config, diag, true);
56
57
  case 'InvokeModel':
57
- return this.requestPreSpanHookInvokeModel(request, config, diag);
58
+ return this.requestPreSpanHookInvokeModel(request, config, diag, false);
59
+ case 'InvokeModelWithResponseStream':
60
+ return this.requestPreSpanHookInvokeModel(request, config, diag, true);
58
61
  }
59
62
  return {
60
63
  isIncoming: false,
@@ -96,7 +99,7 @@ class BedrockRuntimeServiceExtension {
96
99
  spanAttributes,
97
100
  };
98
101
  }
99
- requestPreSpanHookInvokeModel(request, config, diag) {
102
+ requestPreSpanHookInvokeModel(request, config, diag, isStream) {
100
103
  let spanName;
101
104
  const spanAttributes = {
102
105
  [semconv_1.ATTR_GEN_AI_SYSTEM]: semconv_1.GEN_AI_SYSTEM_VALUE_AWS_BEDROCK,
@@ -247,6 +250,7 @@ class BedrockRuntimeServiceExtension {
247
250
  return {
248
251
  spanName,
249
252
  isIncoming: false,
253
+ isStream,
250
254
  spanAttributes,
251
255
  };
252
256
  }
@@ -261,6 +265,8 @@ class BedrockRuntimeServiceExtension {
261
265
  return this.responseHookConverseStream(response, span, tracer, config, startTime);
262
266
  case 'InvokeModel':
263
267
  return this.responseHookInvokeModel(response, span, tracer, config);
268
+ case 'InvokeModelWithResponseStream':
269
+ return this.responseHookInvokeModelWithResponseStream(response, span, tracer, config);
264
270
  }
265
271
  }
266
272
  responseHookConverse(response, span, tracer, config, startTime) {
@@ -423,6 +429,159 @@ class BedrockRuntimeServiceExtension {
423
429
  }
424
430
  }
425
431
  }
432
+ async responseHookInvokeModelWithResponseStream(response, span, tracer, config) {
433
+ const stream = response.data?.body;
434
+ const modelId = response.request.commandInput?.modelId;
435
+ if (!stream || !modelId)
436
+ return;
437
+ // Replace the original response body with our instrumented stream.
438
+ // - Defers span.end() until the entire stream is consumed
439
+ // This ensures downstream consumers still receive the full stream correctly,
440
+ // while OpenTelemetry can record span attributes from streamed data.
441
+ response.data.body = async function* () {
442
+ try {
443
+ for await (const chunk of stream) {
444
+ const parsedChunk = this.parseChunk(chunk?.chunk?.bytes);
445
+ if (!parsedChunk) {
446
+ // pass through
447
+ }
448
+ else if (modelId.includes('amazon.titan')) {
449
+ BedrockRuntimeServiceExtension.recordTitanAttributes(parsedChunk, span);
450
+ }
451
+ else if (modelId.includes('anthropic.claude')) {
452
+ BedrockRuntimeServiceExtension.recordClaudeAttributes(parsedChunk, span);
453
+ }
454
+ else if (modelId.includes('amazon.nova')) {
455
+ BedrockRuntimeServiceExtension.recordNovaAttributes(parsedChunk, span);
456
+ }
457
+ else if (modelId.includes('meta.llama')) {
458
+ BedrockRuntimeServiceExtension.recordLlamaAttributes(parsedChunk, span);
459
+ }
460
+ else if (modelId.includes('cohere.command-r')) {
461
+ BedrockRuntimeServiceExtension.recordCohereRAttributes(parsedChunk, span);
462
+ }
463
+ else if (modelId.includes('cohere.command')) {
464
+ BedrockRuntimeServiceExtension.recordCohereAttributes(parsedChunk, span);
465
+ }
466
+ else if (modelId.includes('mistral')) {
467
+ BedrockRuntimeServiceExtension.recordMistralAttributes(parsedChunk, span);
468
+ }
469
+ yield chunk;
470
+ }
471
+ }
472
+ finally {
473
+ span.end();
474
+ }
475
+ }.bind(this)();
476
+ return response.data;
477
+ }
478
+ parseChunk(bytes) {
479
+ if (!bytes || !(bytes instanceof Uint8Array))
480
+ return null;
481
+ try {
482
+ const str = Buffer.from(bytes).toString('utf-8');
483
+ return JSON.parse(str);
484
+ }
485
+ catch (err) {
486
+ this._diag.warn('Failed to parse streamed chunk', err);
487
+ return null;
488
+ }
489
+ }
490
+ static recordNovaAttributes(parsedChunk, span) {
491
+ if (parsedChunk.metadata?.usage !== undefined) {
492
+ if (parsedChunk.metadata?.usage.inputTokens !== undefined) {
493
+ span.setAttribute(semconv_1.ATTR_GEN_AI_USAGE_INPUT_TOKENS, parsedChunk.metadata.usage.inputTokens);
494
+ }
495
+ if (parsedChunk.metadata?.usage.outputTokens !== undefined) {
496
+ span.setAttribute(semconv_1.ATTR_GEN_AI_USAGE_OUTPUT_TOKENS, parsedChunk.metadata.usage.outputTokens);
497
+ }
498
+ }
499
+ if (parsedChunk.messageStop?.stopReason !== undefined) {
500
+ span.setAttribute(semconv_1.ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [
501
+ parsedChunk.messageStop.stopReason,
502
+ ]);
503
+ }
504
+ }
505
+ static recordClaudeAttributes(parsedChunk, span) {
506
+ if (parsedChunk.message?.usage?.input_tokens !== undefined) {
507
+ span.setAttribute(semconv_1.ATTR_GEN_AI_USAGE_INPUT_TOKENS, parsedChunk.message.usage.input_tokens);
508
+ }
509
+ if (parsedChunk.message?.usage?.output_tokens !== undefined) {
510
+ span.setAttribute(semconv_1.ATTR_GEN_AI_USAGE_OUTPUT_TOKENS, parsedChunk.message.usage.output_tokens);
511
+ }
512
+ if (parsedChunk.delta?.stop_reason !== undefined) {
513
+ span.setAttribute(semconv_1.ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [
514
+ parsedChunk.delta.stop_reason,
515
+ ]);
516
+ }
517
+ }
518
+ static recordTitanAttributes(parsedChunk, span) {
519
+ if (parsedChunk.inputTextTokenCount !== undefined) {
520
+ span.setAttribute(semconv_1.ATTR_GEN_AI_USAGE_INPUT_TOKENS, parsedChunk.inputTextTokenCount);
521
+ }
522
+ if (parsedChunk.totalOutputTextTokenCount !== undefined) {
523
+ span.setAttribute(semconv_1.ATTR_GEN_AI_USAGE_OUTPUT_TOKENS, parsedChunk.totalOutputTextTokenCount);
524
+ }
525
+ if (parsedChunk.completionReason !== undefined) {
526
+ span.setAttribute(semconv_1.ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [
527
+ parsedChunk.completionReason,
528
+ ]);
529
+ }
530
+ }
531
+ static recordLlamaAttributes(parsedChunk, span) {
532
+ if (parsedChunk.prompt_token_count !== undefined) {
533
+ span.setAttribute(semconv_1.ATTR_GEN_AI_USAGE_INPUT_TOKENS, parsedChunk.prompt_token_count);
534
+ }
535
+ if (parsedChunk.generation_token_count !== undefined) {
536
+ span.setAttribute(semconv_1.ATTR_GEN_AI_USAGE_OUTPUT_TOKENS, parsedChunk.generation_token_count);
537
+ }
538
+ if (parsedChunk.stop_reason !== undefined) {
539
+ span.setAttribute(semconv_1.ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [
540
+ parsedChunk.stop_reason,
541
+ ]);
542
+ }
543
+ }
544
+ static recordMistralAttributes(parsedChunk, span) {
545
+ if (parsedChunk.outputs?.[0]?.text !== undefined) {
546
+ span.setAttribute(semconv_1.ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,
547
+ // NOTE: We approximate the token count since this value is not directly available in the body
548
+ // According to Bedrock docs they use (total_chars / 6) to approximate token count for pricing.
549
+ // https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-prepare.html
550
+ Math.ceil(parsedChunk.outputs[0].text.length / 6));
551
+ }
552
+ if (parsedChunk.outputs?.[0]?.stop_reason !== undefined) {
553
+ span.setAttribute(semconv_1.ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [
554
+ parsedChunk.outputs[0].stop_reason,
555
+ ]);
556
+ }
557
+ }
558
+ static recordCohereAttributes(parsedChunk, span) {
559
+ if (parsedChunk.generations?.[0]?.text !== undefined) {
560
+ span.setAttribute(semconv_1.ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,
561
+ // NOTE: We approximate the token count since this value is not directly available in the body
562
+ // According to Bedrock docs they use (total_chars / 6) to approximate token count for pricing.
563
+ // https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-prepare.html
564
+ Math.ceil(parsedChunk.generations[0].text.length / 6));
565
+ }
566
+ if (parsedChunk.generations?.[0]?.finish_reason !== undefined) {
567
+ span.setAttribute(semconv_1.ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [
568
+ parsedChunk.generations[0].finish_reason,
569
+ ]);
570
+ }
571
+ }
572
+ static recordCohereRAttributes(parsedChunk, span) {
573
+ if (parsedChunk.text !== undefined) {
574
+ // NOTE: We approximate the token count since this value is not directly available in the body
575
+ // According to Bedrock docs they use (total_chars / 6) to approximate token count for pricing.
576
+ // https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-prepare.html
577
+ span.setAttribute(semconv_1.ATTR_GEN_AI_USAGE_OUTPUT_TOKENS, Math.ceil(parsedChunk.text.length / 6));
578
+ }
579
+ if (parsedChunk.finish_reason !== undefined) {
580
+ span.setAttribute(semconv_1.ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [
581
+ parsedChunk.finish_reason,
582
+ ]);
583
+ }
584
+ }
426
585
  }
427
586
  exports.BedrockRuntimeServiceExtension = BedrockRuntimeServiceExtension;
428
587
  //# sourceMappingURL=bedrock-runtime.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bedrock-runtime.js","sourceRoot":"","sources":["../../../src/services/bedrock-runtime.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,4CAS4B;AAE5B,wCAkBoB;AAUpB,8CAI6B;AAE7B,MAAa,8BAA8B;IACjC,UAAU,CAAa;IACvB,iBAAiB,CAAa;IAEtC,uBAAuB,CAAC,KAAY;QAClC,mGAAmG;QACnG,IAAI,CAAC,UAAU,GAAG,KAAK,CAAC,eAAe,CAAC,0CAAgC,EAAE;YACxE,IAAI,EAAE,SAAS;YACf,WAAW,EAAE,iDAAiD;YAC9D,SAAS,EAAE,eAAS,CAAC,GAAG;YACxB,MAAM,EAAE;gBACN,wBAAwB,EAAE;oBACxB,CAAC,EAAE,CA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AC,CAAC,CACvD,CAAC;iBACH;gBACD,IAAI,YAAY,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,aAAa,KAAK,SAAS,EAAE;oBAC9D,IAAI,CAAC,YAAY,CAAC,6CAAmC,EAAE;wBACrD,YAAY,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,aAAa;qBAC1C,CAAC,CAAC;iBACJ;aACF;iBAAM,IAAI,cAAc,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;gBAC7C,IAAI,YAAY,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,KAAK,SAAS,EAAE;oBACjD,IAAI,CAAC,YAAY,CACf,yCAA+B;oBAC/B,8FAA8F;oBAC9F,+FAA+F;oBAC/F,wFAAwF;oBACxF,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CACnD,CAAC;iBACH;gBACD,IAAI,YAAY,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,WAAW,KAAK,SAAS,EAAE;oBACxD,IAAI,CAAC,YAAY,CAAC,6CAAmC,EAAE;wBACrD,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,WAAW;qBACpC,CAAC,CAAC;iBACJ;aACF;SACF;IACH,CAAC;CACF;AA3gBD,wEA2gBC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n Attributes,\n DiagLogger,\n Histogram,\n HrTime,\n Meter,\n Span,\n Tracer,\n ValueType,\n} from '@opentelemetry/api';\nimport { RequestMetadata, ServiceExtension } from './ServiceExtension';\nimport {\n ATTR_GEN_AI_SYSTEM,\n ATTR_GEN_AI_OPERATION_NAME,\n ATTR_GEN_AI_REQUEST_MODEL,\n ATTR_GEN_AI_REQUEST_MAX_TOKENS,\n ATTR_GEN_AI_REQUEST_TEMPERATURE,\n ATTR_GEN_AI_REQUEST_TOP_P,\n ATTR_GEN_AI_REQUEST_STOP_SEQUENCES,\n ATTR_GEN_AI_TOKEN_TYPE,\n ATTR_GEN_AI_USAGE_INPUT_TOKENS,\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n ATTR_GEN_AI_RESPONSE_FINISH_REASONS,\n GEN_AI_OPERATION_NAME_VALUE_CHAT,\n GEN_AI_SYSTEM_VALUE_AWS_BEDROCK,\n GEN_AI_TOKEN_TYPE_VALUE_INPUT,\n GEN_AI_TOKEN_TYPE_VALUE_OUTPUT,\n METRIC_GEN_AI_CLIENT_OPERATION_DURATION,\n METRIC_GEN_AI_CLIENT_TOKEN_USAGE,\n} from '../semconv';\nimport {\n AwsSdkInstrumentationConfig,\n NormalizedRequest,\n NormalizedResponse,\n} from '../types';\nimport type {\n ConverseStreamOutput,\n TokenUsage,\n} from '@aws-sdk/client-bedrock-runtime';\nimport {\n hrTime,\n hrTimeDuration,\n hrTimeToMilliseconds,\n} from '@opentelemetry/core';\n\nexport class BedrockRuntimeServiceExtension implements ServiceExtension {\n private tokenUsage!: Histogram;\n private operationDuration!: Histogram;\n\n updateMetricInstruments(meter: Meter) {\n // https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-metrics/#metric-gen_aiclienttokenusage\n this.tokenUsage = meter.createHistogram(METRIC_GEN_AI_CLIENT_TOKEN_USAGE, {\n unit: '{token}',\n description: 'Measures number of input and output tokens used',\n valueType: ValueType.INT,\n advice: {\n explicitBucketBoundaries: [\n 1, 4, 16, 64, 256, 1024, 4096, 16384, 65536, 262144, 1048576, 4194304,\n 16777216, 67108864,\n ],\n },\n });\n\n // https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-metrics/#metric-gen_aiclientoperationduration\n this.operationDuration = meter.createHistogram(\n METRIC_GEN_AI_CLIENT_OPERATION_DURATION,\n {\n unit: 's',\n description: 'GenAI operation duration',\n advice: {\n explicitBucketBoundaries: [\n 0.01, 0.02, 0.04, 0.08, 0.16, 0.32, 0.64, 1.28, 2.56, 5.12, 10.24,\n 20.48, 40.96, 81.92,\n ],\n },\n }\n );\n }\n\n requestPreSpanHook(\n request: NormalizedRequest,\n config: AwsSdkInstrumentationConfig,\n diag: DiagLogger\n ): RequestMetadata {\n switch (request.commandName) {\n case 'Converse':\n return this.requestPreSpanHookConverse(request, config, diag, false);\n case 'ConverseStream':\n return this.requestPreSpanHookConverse(request, config, diag, true);\n case 'InvokeModel':\n return this.requestPreSpanHookInvokeModel(request, config, diag);\n }\n\n return {\n isIncoming: false,\n };\n }\n\n private requestPreSpanHookConverse(\n request: NormalizedRequest,\n config: AwsSdkInstrumentationConfig,\n diag: DiagLogger,\n isStream: boolean\n ): RequestMetadata {\n let spanName = GEN_AI_OPERATION_NAME_VALUE_CHAT;\n const spanAttributes: Attributes = {\n [ATTR_GEN_AI_SYSTEM]: GEN_AI_SYSTEM_VALUE_AWS_BEDROCK,\n [ATTR_GEN_AI_OPERATION_NAME]: GEN_AI_OPERATION_NAME_VALUE_CHAT,\n };\n\n const modelId = request.commandInput.modelId;\n if (modelId) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MODEL] = modelId;\n if (spanName) {\n spanName += ` ${modelId}`;\n }\n }\n\n const inferenceConfig = request.commandInput.inferenceConfig;\n if (inferenceConfig) {\n const { maxTokens, temperature, topP, stopSequences } = inferenceConfig;\n if (maxTokens !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] = maxTokens;\n }\n if (temperature !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TEMPERATURE] = temperature;\n }\n if (topP !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TOP_P] = topP;\n }\n if (stopSequences !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_STOP_SEQUENCES] = stopSequences;\n }\n }\n\n return {\n spanName,\n isIncoming: false,\n isStream,\n spanAttributes,\n };\n }\n\n private requestPreSpanHookInvokeModel(\n request: NormalizedRequest,\n config: AwsSdkInstrumentationConfig,\n diag: DiagLogger\n ): RequestMetadata {\n let spanName: string | undefined;\n const spanAttributes: Attributes = {\n [ATTR_GEN_AI_SYSTEM]: GEN_AI_SYSTEM_VALUE_AWS_BEDROCK,\n // add operation name for InvokeModel API\n };\n\n const modelId = request.commandInput?.modelId;\n if (modelId) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MODEL] = modelId;\n }\n\n if (request.commandInput?.body) {\n const requestBody = JSON.parse(request.commandInput.body);\n if (modelId.includes('amazon.titan')) {\n if (requestBody.textGenerationConfig?.temperature !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TEMPERATURE] =\n requestBody.textGenerationConfig.temperature;\n }\n if (requestBody.textGenerationConfig?.topP !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TOP_P] =\n requestBody.textGenerationConfig.topP;\n }\n if (requestBody.textGenerationConfig?.maxTokenCount !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] =\n requestBody.textGenerationConfig.maxTokenCount;\n }\n if (requestBody.textGenerationConfig?.stopSequences !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_STOP_SEQUENCES] =\n requestBody.textGenerationConfig.stopSequences;\n }\n } else if (modelId.includes('amazon.nova')) {\n if (requestBody.inferenceConfig?.temperature !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TEMPERATURE] =\n requestBody.inferenceConfig.temperature;\n }\n if (requestBody.inferenceConfig?.top_p !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TOP_P] =\n requestBody.inferenceConfig.top_p;\n }\n if (requestBody.inferenceConfig?.max_new_tokens !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] =\n requestBody.inferenceConfig.max_new_tokens;\n }\n if (requestBody.inferenceConfig?.stopSequences !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_STOP_SEQUENCES] =\n requestBody.inferenceConfig.stopSequences;\n }\n } else if (modelId.includes('anthropic.claude')) {\n if (requestBody.max_tokens !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] =\n requestBody.max_tokens;\n }\n if (requestBody.temperature !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TEMPERATURE] =\n requestBody.temperature;\n }\n if (requestBody.top_p !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TOP_P] = requestBody.top_p;\n }\n if (requestBody.stop_sequences !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_STOP_SEQUENCES] =\n requestBody.stop_sequences;\n }\n } else if (modelId.includes('meta.llama')) {\n if (requestBody.max_gen_len !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] =\n requestBody.max_gen_len;\n }\n if (requestBody.temperature !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TEMPERATURE] =\n requestBody.temperature;\n }\n if (requestBody.top_p !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TOP_P] = requestBody.top_p;\n }\n // request for meta llama models does not contain stop_sequences field\n } else if (modelId.includes('cohere.command-r')) {\n if (requestBody.max_tokens !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] =\n requestBody.max_tokens;\n }\n if (requestBody.temperature !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TEMPERATURE] =\n requestBody.temperature;\n }\n if (requestBody.p !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TOP_P] = requestBody.p;\n }\n if (requestBody.message !== undefined) {\n // NOTE: We approximate the token count since this value is not directly available in the body\n // According to Bedrock docs they use (total_chars / 6) to approximate token count for pricing.\n // https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-prepare.html\n spanAttributes[ATTR_GEN_AI_USAGE_INPUT_TOKENS] = Math.ceil(\n requestBody.message.length / 6\n );\n }\n if (requestBody.stop_sequences !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_STOP_SEQUENCES] =\n requestBody.stop_sequences;\n }\n } else if (modelId.includes('cohere.command')) {\n if (requestBody.max_tokens !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] =\n requestBody.max_tokens;\n }\n if (requestBody.temperature !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TEMPERATURE] =\n requestBody.temperature;\n }\n if (requestBody.p !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TOP_P] = requestBody.p;\n }\n if (requestBody.prompt !== undefined) {\n // NOTE: We approximate the token count since this value is not directly available in the body\n // According to Bedrock docs they use (total_chars / 6) to approximate token count for pricing.\n // https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-prepare.html\n spanAttributes[ATTR_GEN_AI_USAGE_INPUT_TOKENS] = Math.ceil(\n requestBody.prompt.length / 6\n );\n }\n if (requestBody.stop_sequences !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_STOP_SEQUENCES] =\n requestBody.stop_sequences;\n }\n } else if (modelId.includes('mistral')) {\n if (requestBody.prompt !== undefined) {\n // NOTE: We approximate the token count since this value is not directly available in the body\n // According to Bedrock docs they use (total_chars / 6) to approximate token count for pricing.\n // https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-prepare.html\n spanAttributes[ATTR_GEN_AI_USAGE_INPUT_TOKENS] = Math.ceil(\n requestBody.prompt.length / 6\n );\n }\n if (requestBody.max_tokens !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] =\n requestBody.max_tokens;\n }\n if (requestBody.temperature !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TEMPERATURE] =\n requestBody.temperature;\n }\n if (requestBody.top_p !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TOP_P] = requestBody.top_p;\n }\n if (requestBody.stop !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_STOP_SEQUENCES] = requestBody.stop;\n }\n }\n }\n\n return {\n spanName,\n isIncoming: false,\n spanAttributes,\n };\n }\n\n responseHook(\n response: NormalizedResponse,\n span: Span,\n tracer: Tracer,\n config: AwsSdkInstrumentationConfig,\n startTime: HrTime\n ) {\n if (!span.isRecording()) {\n return;\n }\n\n switch (response.request.commandName) {\n case 'Converse':\n return this.responseHookConverse(\n response,\n span,\n tracer,\n config,\n startTime\n );\n case 'ConverseStream':\n return this.responseHookConverseStream(\n response,\n span,\n tracer,\n config,\n startTime\n );\n case 'InvokeModel':\n return this.responseHookInvokeModel(response, span, tracer, config);\n }\n }\n\n private responseHookConverse(\n response: NormalizedResponse,\n span: Span,\n tracer: Tracer,\n config: AwsSdkInstrumentationConfig,\n startTime: HrTime\n ) {\n const { stopReason, usage } = response.data;\n\n BedrockRuntimeServiceExtension.setStopReason(span, stopReason);\n this.setUsage(response, span, usage, startTime);\n }\n\n private responseHookConverseStream(\n response: NormalizedResponse,\n span: Span,\n tracer: Tracer,\n config: AwsSdkInstrumentationConfig,\n startTime: HrTime\n ) {\n return {\n ...response.data,\n // Wrap and replace the response stream to allow processing events to telemetry\n // before yielding to the user.\n stream: this.wrapConverseStreamResponse(\n response,\n response.data.stream,\n span,\n startTime\n ),\n };\n }\n\n private async *wrapConverseStreamResponse(\n response: NormalizedResponse,\n stream: AsyncIterable<ConverseStreamOutput>,\n span: Span,\n startTime: HrTime\n ) {\n try {\n let usage: TokenUsage | undefined;\n for await (const item of stream) {\n BedrockRuntimeServiceExtension.setStopReason(\n span,\n item.messageStop?.stopReason\n );\n usage = item.metadata?.usage;\n yield item;\n }\n this.setUsage(response, span, usage, startTime);\n } finally {\n span.end();\n }\n }\n\n private static setStopReason(span: Span, stopReason: string | undefined) {\n if (stopReason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [stopReason]);\n }\n }\n\n private setUsage(\n response: NormalizedResponse,\n span: Span,\n usage: TokenUsage | undefined,\n startTime: HrTime\n ) {\n const sharedMetricAttrs: Attributes = {\n [ATTR_GEN_AI_SYSTEM]: GEN_AI_SYSTEM_VALUE_AWS_BEDROCK,\n [ATTR_GEN_AI_OPERATION_NAME]: GEN_AI_OPERATION_NAME_VALUE_CHAT,\n [ATTR_GEN_AI_REQUEST_MODEL]: response.request.commandInput.modelId,\n };\n\n const durationSecs =\n hrTimeToMilliseconds(hrTimeDuration(startTime, hrTime())) / 1000;\n this.operationDuration.record(durationSecs, sharedMetricAttrs);\n\n if (usage) {\n const { inputTokens, outputTokens } = usage;\n if (inputTokens !== undefined) {\n span.setAttribute(ATTR_GEN_AI_USAGE_INPUT_TOKENS, inputTokens);\n\n this.tokenUsage.record(inputTokens, {\n ...sharedMetricAttrs,\n [ATTR_GEN_AI_TOKEN_TYPE]: GEN_AI_TOKEN_TYPE_VALUE_INPUT,\n });\n }\n if (outputTokens !== undefined) {\n span.setAttribute(ATTR_GEN_AI_USAGE_OUTPUT_TOKENS, outputTokens);\n\n this.tokenUsage.record(outputTokens, {\n ...sharedMetricAttrs,\n [ATTR_GEN_AI_TOKEN_TYPE]: GEN_AI_TOKEN_TYPE_VALUE_OUTPUT,\n });\n }\n }\n }\n\n private responseHookInvokeModel(\n response: NormalizedResponse,\n span: Span,\n tracer: Tracer,\n config: AwsSdkInstrumentationConfig\n ) {\n const currentModelId = response.request.commandInput?.modelId;\n if (response.data?.body) {\n const decodedResponseBody = new TextDecoder().decode(response.data.body);\n const responseBody = JSON.parse(decodedResponseBody);\n if (currentModelId.includes('amazon.titan')) {\n if (responseBody.inputTextTokenCount !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_INPUT_TOKENS,\n responseBody.inputTextTokenCount\n );\n }\n if (responseBody.results?.[0]?.tokenCount !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n responseBody.results[0].tokenCount\n );\n }\n if (responseBody.results?.[0]?.completionReason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [\n responseBody.results[0].completionReason,\n ]);\n }\n } else if (currentModelId.includes('amazon.nova')) {\n if (responseBody.usage !== undefined) {\n if (responseBody.usage.inputTokens !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_INPUT_TOKENS,\n responseBody.usage.inputTokens\n );\n }\n if (responseBody.usage.outputTokens !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n responseBody.usage.outputTokens\n );\n }\n }\n if (responseBody.stopReason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [\n responseBody.stopReason,\n ]);\n }\n } else if (currentModelId.includes('anthropic.claude')) {\n if (responseBody.usage?.input_tokens !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_INPUT_TOKENS,\n responseBody.usage.input_tokens\n );\n }\n if (responseBody.usage?.output_tokens !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n responseBody.usage.output_tokens\n );\n }\n if (responseBody.stop_reason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [\n responseBody.stop_reason,\n ]);\n }\n } else if (currentModelId.includes('meta.llama')) {\n if (responseBody.prompt_token_count !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_INPUT_TOKENS,\n responseBody.prompt_token_count\n );\n }\n if (responseBody.generation_token_count !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n responseBody.generation_token_count\n );\n }\n if (responseBody.stop_reason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [\n responseBody.stop_reason,\n ]);\n }\n } else if (currentModelId.includes('cohere.command-r')) {\n if (responseBody.text !== undefined) {\n // NOTE: We approximate the token count since this value is not directly available in the body\n // According to Bedrock docs they use (total_chars / 6) to approximate token count for pricing.\n // https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-prepare.html\n span.setAttribute(\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n Math.ceil(responseBody.text.length / 6)\n );\n }\n if (responseBody.finish_reason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [\n responseBody.finish_reason,\n ]);\n }\n } else if (currentModelId.includes('cohere.command')) {\n if (responseBody.generations?.[0]?.text !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n // NOTE: We approximate the token count since this value is not directly available in the body\n // According to Bedrock docs they use (total_chars / 6) to approximate token count for pricing.\n // https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-prepare.html\n Math.ceil(responseBody.generations[0].text.length / 6)\n );\n }\n if (responseBody.generations?.[0]?.finish_reason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [\n responseBody.generations[0].finish_reason,\n ]);\n }\n } else if (currentModelId.includes('mistral')) {\n if (responseBody.outputs?.[0]?.text !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n // NOTE: We approximate the token count since this value is not directly available in the body\n // According to Bedrock docs they use (total_chars / 6) to approximate token count for pricing.\n // https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-prepare.html\n Math.ceil(responseBody.outputs[0].text.length / 6)\n );\n }\n if (responseBody.outputs?.[0]?.stop_reason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [\n responseBody.outputs[0].stop_reason,\n ]);\n }\n }\n }\n }\n}\n"]}
1
+ {"version":3,"file":"bedrock-runtime.js","sourceRoot":"","sources":["../../../src/services/bedrock-runtime.ts"],"names":[],"mappings":";;;AAA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ourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport {\n Attributes,\n DiagLogger,\n diag,\n Histogram,\n HrTime,\n Meter,\n Span,\n Tracer,\n ValueType,\n} from '@opentelemetry/api';\nimport { RequestMetadata, ServiceExtension } from './ServiceExtension';\nimport {\n ATTR_GEN_AI_SYSTEM,\n ATTR_GEN_AI_OPERATION_NAME,\n ATTR_GEN_AI_REQUEST_MODEL,\n ATTR_GEN_AI_REQUEST_MAX_TOKENS,\n ATTR_GEN_AI_REQUEST_TEMPERATURE,\n ATTR_GEN_AI_REQUEST_TOP_P,\n ATTR_GEN_AI_REQUEST_STOP_SEQUENCES,\n ATTR_GEN_AI_TOKEN_TYPE,\n ATTR_GEN_AI_USAGE_INPUT_TOKENS,\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n ATTR_GEN_AI_RESPONSE_FINISH_REASONS,\n GEN_AI_OPERATION_NAME_VALUE_CHAT,\n GEN_AI_SYSTEM_VALUE_AWS_BEDROCK,\n GEN_AI_TOKEN_TYPE_VALUE_INPUT,\n GEN_AI_TOKEN_TYPE_VALUE_OUTPUT,\n METRIC_GEN_AI_CLIENT_OPERATION_DURATION,\n METRIC_GEN_AI_CLIENT_TOKEN_USAGE,\n} from '../semconv';\nimport {\n AwsSdkInstrumentationConfig,\n NormalizedRequest,\n NormalizedResponse,\n} from '../types';\nimport type {\n ConverseStreamOutput,\n TokenUsage,\n} from '@aws-sdk/client-bedrock-runtime';\nimport {\n hrTime,\n hrTimeDuration,\n hrTimeToMilliseconds,\n} from '@opentelemetry/core';\n\nexport class BedrockRuntimeServiceExtension implements ServiceExtension {\n private tokenUsage!: Histogram;\n private operationDuration!: Histogram;\n private _diag: DiagLogger = diag;\n\n updateMetricInstruments(meter: Meter) {\n // https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-metrics/#metric-gen_aiclienttokenusage\n this.tokenUsage = meter.createHistogram(METRIC_GEN_AI_CLIENT_TOKEN_USAGE, {\n unit: '{token}',\n description: 'Measures number of input and output tokens used',\n valueType: ValueType.INT,\n advice: {\n explicitBucketBoundaries: [\n 1, 4, 16, 64, 256, 1024, 4096, 16384, 65536, 262144, 1048576, 4194304,\n 16777216, 67108864,\n ],\n },\n });\n\n // https://opentelemetry.io/docs/specs/semconv/gen-ai/gen-ai-metrics/#metric-gen_aiclientoperationduration\n this.operationDuration = meter.createHistogram(\n METRIC_GEN_AI_CLIENT_OPERATION_DURATION,\n {\n unit: 's',\n description: 'GenAI operation duration',\n advice: {\n explicitBucketBoundaries: [\n 0.01, 0.02, 0.04, 0.08, 0.16, 0.32, 0.64, 1.28, 2.56, 5.12, 10.24,\n 20.48, 40.96, 81.92,\n ],\n },\n }\n );\n }\n\n requestPreSpanHook(\n request: NormalizedRequest,\n config: AwsSdkInstrumentationConfig,\n diag: DiagLogger\n ): RequestMetadata {\n switch (request.commandName) {\n case 'Converse':\n return this.requestPreSpanHookConverse(request, config, diag, false);\n case 'ConverseStream':\n return this.requestPreSpanHookConverse(request, config, diag, true);\n case 'InvokeModel':\n return this.requestPreSpanHookInvokeModel(request, config, diag, false);\n case 'InvokeModelWithResponseStream':\n return this.requestPreSpanHookInvokeModel(request, config, diag, true);\n }\n\n return {\n isIncoming: false,\n };\n }\n\n private requestPreSpanHookConverse(\n request: NormalizedRequest,\n config: AwsSdkInstrumentationConfig,\n diag: DiagLogger,\n isStream: boolean\n ): RequestMetadata {\n let spanName = GEN_AI_OPERATION_NAME_VALUE_CHAT;\n const spanAttributes: Attributes = {\n [ATTR_GEN_AI_SYSTEM]: GEN_AI_SYSTEM_VALUE_AWS_BEDROCK,\n [ATTR_GEN_AI_OPERATION_NAME]: GEN_AI_OPERATION_NAME_VALUE_CHAT,\n };\n\n const modelId = request.commandInput.modelId;\n if (modelId) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MODEL] = modelId;\n if (spanName) {\n spanName += ` ${modelId}`;\n }\n }\n\n const inferenceConfig = request.commandInput.inferenceConfig;\n if (inferenceConfig) {\n const { maxTokens, temperature, topP, stopSequences } = inferenceConfig;\n if (maxTokens !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] = maxTokens;\n }\n if (temperature !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TEMPERATURE] = temperature;\n }\n if (topP !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TOP_P] = topP;\n }\n if (stopSequences !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_STOP_SEQUENCES] = stopSequences;\n }\n }\n\n return {\n spanName,\n isIncoming: false,\n isStream,\n spanAttributes,\n };\n }\n\n private requestPreSpanHookInvokeModel(\n request: NormalizedRequest,\n config: AwsSdkInstrumentationConfig,\n diag: DiagLogger,\n isStream: boolean\n ): RequestMetadata {\n let spanName: string | undefined;\n const spanAttributes: Attributes = {\n [ATTR_GEN_AI_SYSTEM]: GEN_AI_SYSTEM_VALUE_AWS_BEDROCK,\n // add operation name for InvokeModel API\n };\n\n const modelId = request.commandInput?.modelId;\n if (modelId) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MODEL] = modelId;\n }\n\n if (request.commandInput?.body) {\n const requestBody = JSON.parse(request.commandInput.body);\n if (modelId.includes('amazon.titan')) {\n if (requestBody.textGenerationConfig?.temperature !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TEMPERATURE] =\n requestBody.textGenerationConfig.temperature;\n }\n if (requestBody.textGenerationConfig?.topP !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TOP_P] =\n requestBody.textGenerationConfig.topP;\n }\n if (requestBody.textGenerationConfig?.maxTokenCount !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] =\n requestBody.textGenerationConfig.maxTokenCount;\n }\n if (requestBody.textGenerationConfig?.stopSequences !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_STOP_SEQUENCES] =\n requestBody.textGenerationConfig.stopSequences;\n }\n } else if (modelId.includes('amazon.nova')) {\n if (requestBody.inferenceConfig?.temperature !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TEMPERATURE] =\n requestBody.inferenceConfig.temperature;\n }\n if (requestBody.inferenceConfig?.top_p !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TOP_P] =\n requestBody.inferenceConfig.top_p;\n }\n if (requestBody.inferenceConfig?.max_new_tokens !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] =\n requestBody.inferenceConfig.max_new_tokens;\n }\n if (requestBody.inferenceConfig?.stopSequences !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_STOP_SEQUENCES] =\n requestBody.inferenceConfig.stopSequences;\n }\n } else if (modelId.includes('anthropic.claude')) {\n if (requestBody.max_tokens !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] =\n requestBody.max_tokens;\n }\n if (requestBody.temperature !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TEMPERATURE] =\n requestBody.temperature;\n }\n if (requestBody.top_p !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TOP_P] = requestBody.top_p;\n }\n if (requestBody.stop_sequences !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_STOP_SEQUENCES] =\n requestBody.stop_sequences;\n }\n } else if (modelId.includes('meta.llama')) {\n if (requestBody.max_gen_len !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] =\n requestBody.max_gen_len;\n }\n if (requestBody.temperature !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TEMPERATURE] =\n requestBody.temperature;\n }\n if (requestBody.top_p !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TOP_P] = requestBody.top_p;\n }\n // request for meta llama models does not contain stop_sequences field\n } else if (modelId.includes('cohere.command-r')) {\n if (requestBody.max_tokens !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] =\n requestBody.max_tokens;\n }\n if (requestBody.temperature !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TEMPERATURE] =\n requestBody.temperature;\n }\n if (requestBody.p !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TOP_P] = requestBody.p;\n }\n if (requestBody.message !== undefined) {\n // NOTE: We approximate the token count since this value is not directly available in the body\n // According to Bedrock docs they use (total_chars / 6) to approximate token count for pricing.\n // https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-prepare.html\n spanAttributes[ATTR_GEN_AI_USAGE_INPUT_TOKENS] = Math.ceil(\n requestBody.message.length / 6\n );\n }\n if (requestBody.stop_sequences !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_STOP_SEQUENCES] =\n requestBody.stop_sequences;\n }\n } else if (modelId.includes('cohere.command')) {\n if (requestBody.max_tokens !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] =\n requestBody.max_tokens;\n }\n if (requestBody.temperature !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TEMPERATURE] =\n requestBody.temperature;\n }\n if (requestBody.p !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TOP_P] = requestBody.p;\n }\n if (requestBody.prompt !== undefined) {\n // NOTE: We approximate the token count since this value is not directly available in the body\n // According to Bedrock docs they use (total_chars / 6) to approximate token count for pricing.\n // https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-prepare.html\n spanAttributes[ATTR_GEN_AI_USAGE_INPUT_TOKENS] = Math.ceil(\n requestBody.prompt.length / 6\n );\n }\n if (requestBody.stop_sequences !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_STOP_SEQUENCES] =\n requestBody.stop_sequences;\n }\n } else if (modelId.includes('mistral')) {\n if (requestBody.prompt !== undefined) {\n // NOTE: We approximate the token count since this value is not directly available in the body\n // According to Bedrock docs they use (total_chars / 6) to approximate token count for pricing.\n // https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-prepare.html\n spanAttributes[ATTR_GEN_AI_USAGE_INPUT_TOKENS] = Math.ceil(\n requestBody.prompt.length / 6\n );\n }\n if (requestBody.max_tokens !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_MAX_TOKENS] =\n requestBody.max_tokens;\n }\n if (requestBody.temperature !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TEMPERATURE] =\n requestBody.temperature;\n }\n if (requestBody.top_p !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_TOP_P] = requestBody.top_p;\n }\n if (requestBody.stop !== undefined) {\n spanAttributes[ATTR_GEN_AI_REQUEST_STOP_SEQUENCES] = requestBody.stop;\n }\n }\n }\n\n return {\n spanName,\n isIncoming: false,\n isStream,\n spanAttributes,\n };\n }\n\n responseHook(\n response: NormalizedResponse,\n span: Span,\n tracer: Tracer,\n config: AwsSdkInstrumentationConfig,\n startTime: HrTime\n ) {\n if (!span.isRecording()) {\n return;\n }\n\n switch (response.request.commandName) {\n case 'Converse':\n return this.responseHookConverse(\n response,\n span,\n tracer,\n config,\n startTime\n );\n case 'ConverseStream':\n return this.responseHookConverseStream(\n response,\n span,\n tracer,\n config,\n startTime\n );\n case 'InvokeModel':\n return this.responseHookInvokeModel(response, span, tracer, config);\n case 'InvokeModelWithResponseStream':\n return this.responseHookInvokeModelWithResponseStream(\n response,\n span,\n tracer,\n config\n );\n }\n }\n\n private responseHookConverse(\n response: NormalizedResponse,\n span: Span,\n tracer: Tracer,\n config: AwsSdkInstrumentationConfig,\n startTime: HrTime\n ) {\n const { stopReason, usage } = response.data;\n\n BedrockRuntimeServiceExtension.setStopReason(span, stopReason);\n this.setUsage(response, span, usage, startTime);\n }\n\n private responseHookConverseStream(\n response: NormalizedResponse,\n span: Span,\n tracer: Tracer,\n config: AwsSdkInstrumentationConfig,\n startTime: HrTime\n ) {\n return {\n ...response.data,\n // Wrap and replace the response stream to allow processing events to telemetry\n // before yielding to the user.\n stream: this.wrapConverseStreamResponse(\n response,\n response.data.stream,\n span,\n startTime\n ),\n };\n }\n\n private async *wrapConverseStreamResponse(\n response: NormalizedResponse,\n stream: AsyncIterable<ConverseStreamOutput>,\n span: Span,\n startTime: HrTime\n ) {\n try {\n let usage: TokenUsage | undefined;\n for await (const item of stream) {\n BedrockRuntimeServiceExtension.setStopReason(\n span,\n item.messageStop?.stopReason\n );\n usage = item.metadata?.usage;\n yield item;\n }\n this.setUsage(response, span, usage, startTime);\n } finally {\n span.end();\n }\n }\n\n private static setStopReason(span: Span, stopReason: string | undefined) {\n if (stopReason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [stopReason]);\n }\n }\n\n private setUsage(\n response: NormalizedResponse,\n span: Span,\n usage: TokenUsage | undefined,\n startTime: HrTime\n ) {\n const sharedMetricAttrs: Attributes = {\n [ATTR_GEN_AI_SYSTEM]: GEN_AI_SYSTEM_VALUE_AWS_BEDROCK,\n [ATTR_GEN_AI_OPERATION_NAME]: GEN_AI_OPERATION_NAME_VALUE_CHAT,\n [ATTR_GEN_AI_REQUEST_MODEL]: response.request.commandInput.modelId,\n };\n\n const durationSecs =\n hrTimeToMilliseconds(hrTimeDuration(startTime, hrTime())) / 1000;\n this.operationDuration.record(durationSecs, sharedMetricAttrs);\n\n if (usage) {\n const { inputTokens, outputTokens } = usage;\n if (inputTokens !== undefined) {\n span.setAttribute(ATTR_GEN_AI_USAGE_INPUT_TOKENS, inputTokens);\n\n this.tokenUsage.record(inputTokens, {\n ...sharedMetricAttrs,\n [ATTR_GEN_AI_TOKEN_TYPE]: GEN_AI_TOKEN_TYPE_VALUE_INPUT,\n });\n }\n if (outputTokens !== undefined) {\n span.setAttribute(ATTR_GEN_AI_USAGE_OUTPUT_TOKENS, outputTokens);\n\n this.tokenUsage.record(outputTokens, {\n ...sharedMetricAttrs,\n [ATTR_GEN_AI_TOKEN_TYPE]: GEN_AI_TOKEN_TYPE_VALUE_OUTPUT,\n });\n }\n }\n }\n\n private responseHookInvokeModel(\n response: NormalizedResponse,\n span: Span,\n tracer: Tracer,\n config: AwsSdkInstrumentationConfig\n ) {\n const currentModelId = response.request.commandInput?.modelId;\n if (response.data?.body) {\n const decodedResponseBody = new TextDecoder().decode(response.data.body);\n const responseBody = JSON.parse(decodedResponseBody);\n if (currentModelId.includes('amazon.titan')) {\n if (responseBody.inputTextTokenCount !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_INPUT_TOKENS,\n responseBody.inputTextTokenCount\n );\n }\n if (responseBody.results?.[0]?.tokenCount !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n responseBody.results[0].tokenCount\n );\n }\n if (responseBody.results?.[0]?.completionReason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [\n responseBody.results[0].completionReason,\n ]);\n }\n } else if (currentModelId.includes('amazon.nova')) {\n if (responseBody.usage !== undefined) {\n if (responseBody.usage.inputTokens !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_INPUT_TOKENS,\n responseBody.usage.inputTokens\n );\n }\n if (responseBody.usage.outputTokens !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n responseBody.usage.outputTokens\n );\n }\n }\n if (responseBody.stopReason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [\n responseBody.stopReason,\n ]);\n }\n } else if (currentModelId.includes('anthropic.claude')) {\n if (responseBody.usage?.input_tokens !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_INPUT_TOKENS,\n responseBody.usage.input_tokens\n );\n }\n if (responseBody.usage?.output_tokens !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n responseBody.usage.output_tokens\n );\n }\n if (responseBody.stop_reason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [\n responseBody.stop_reason,\n ]);\n }\n } else if (currentModelId.includes('meta.llama')) {\n if (responseBody.prompt_token_count !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_INPUT_TOKENS,\n responseBody.prompt_token_count\n );\n }\n if (responseBody.generation_token_count !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n responseBody.generation_token_count\n );\n }\n if (responseBody.stop_reason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [\n responseBody.stop_reason,\n ]);\n }\n } else if (currentModelId.includes('cohere.command-r')) {\n if (responseBody.text !== undefined) {\n // NOTE: We approximate the token count since this value is not directly available in the body\n // According to Bedrock docs they use (total_chars / 6) to approximate token count for pricing.\n // https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-prepare.html\n span.setAttribute(\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n Math.ceil(responseBody.text.length / 6)\n );\n }\n if (responseBody.finish_reason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [\n responseBody.finish_reason,\n ]);\n }\n } else if (currentModelId.includes('cohere.command')) {\n if (responseBody.generations?.[0]?.text !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n // NOTE: We approximate the token count since this value is not directly available in the body\n // According to Bedrock docs they use (total_chars / 6) to approximate token count for pricing.\n // https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-prepare.html\n Math.ceil(responseBody.generations[0].text.length / 6)\n );\n }\n if (responseBody.generations?.[0]?.finish_reason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [\n responseBody.generations[0].finish_reason,\n ]);\n }\n } else if (currentModelId.includes('mistral')) {\n if (responseBody.outputs?.[0]?.text !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n // NOTE: We approximate the token count since this value is not directly available in the body\n // According to Bedrock docs they use (total_chars / 6) to approximate token count for pricing.\n // https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-prepare.html\n Math.ceil(responseBody.outputs[0].text.length / 6)\n );\n }\n if (responseBody.outputs?.[0]?.stop_reason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [\n responseBody.outputs[0].stop_reason,\n ]);\n }\n }\n }\n }\n\n private async responseHookInvokeModelWithResponseStream(\n response: NormalizedResponse,\n span: Span,\n tracer: Tracer,\n config: AwsSdkInstrumentationConfig\n ): Promise<any> {\n const stream = response.data?.body;\n const modelId = response.request.commandInput?.modelId;\n if (!stream || !modelId) return;\n\n // Replace the original response body with our instrumented stream.\n // - Defers span.end() until the entire stream is consumed\n // This ensures downstream consumers still receive the full stream correctly,\n // while OpenTelemetry can record span attributes from streamed data.\n response.data.body = async function* (\n this: BedrockRuntimeServiceExtension\n ) {\n try {\n for await (const chunk of stream) {\n const parsedChunk = this.parseChunk(chunk?.chunk?.bytes);\n\n if (!parsedChunk) {\n // pass through\n } else if (modelId.includes('amazon.titan')) {\n BedrockRuntimeServiceExtension.recordTitanAttributes(\n parsedChunk,\n span\n );\n } else if (modelId.includes('anthropic.claude')) {\n BedrockRuntimeServiceExtension.recordClaudeAttributes(\n parsedChunk,\n span\n );\n } else if (modelId.includes('amazon.nova')) {\n BedrockRuntimeServiceExtension.recordNovaAttributes(\n parsedChunk,\n span\n );\n } else if (modelId.includes('meta.llama')) {\n BedrockRuntimeServiceExtension.recordLlamaAttributes(\n parsedChunk,\n span\n );\n } else if (modelId.includes('cohere.command-r')) {\n BedrockRuntimeServiceExtension.recordCohereRAttributes(\n parsedChunk,\n span\n );\n } else if (modelId.includes('cohere.command')) {\n BedrockRuntimeServiceExtension.recordCohereAttributes(\n parsedChunk,\n span\n );\n } else if (modelId.includes('mistral')) {\n BedrockRuntimeServiceExtension.recordMistralAttributes(\n parsedChunk,\n span\n );\n }\n yield chunk;\n }\n } finally {\n span.end();\n }\n }.bind(this)();\n return response.data;\n }\n\n private parseChunk(bytes?: Uint8Array): any {\n if (!bytes || !(bytes instanceof Uint8Array)) return null;\n try {\n const str = Buffer.from(bytes).toString('utf-8');\n return JSON.parse(str);\n } catch (err) {\n this._diag.warn('Failed to parse streamed chunk', err);\n return null;\n }\n }\n\n private static recordNovaAttributes(parsedChunk: any, span: Span) {\n if (parsedChunk.metadata?.usage !== undefined) {\n if (parsedChunk.metadata?.usage.inputTokens !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_INPUT_TOKENS,\n parsedChunk.metadata.usage.inputTokens\n );\n }\n if (parsedChunk.metadata?.usage.outputTokens !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n parsedChunk.metadata.usage.outputTokens\n );\n }\n }\n if (parsedChunk.messageStop?.stopReason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [\n parsedChunk.messageStop.stopReason,\n ]);\n }\n }\n\n private static recordClaudeAttributes(parsedChunk: any, span: Span) {\n if (parsedChunk.message?.usage?.input_tokens !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_INPUT_TOKENS,\n parsedChunk.message.usage.input_tokens\n );\n }\n if (parsedChunk.message?.usage?.output_tokens !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n parsedChunk.message.usage.output_tokens\n );\n }\n if (parsedChunk.delta?.stop_reason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [\n parsedChunk.delta.stop_reason,\n ]);\n }\n }\n\n private static recordTitanAttributes(parsedChunk: any, span: Span) {\n if (parsedChunk.inputTextTokenCount !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_INPUT_TOKENS,\n parsedChunk.inputTextTokenCount\n );\n }\n if (parsedChunk.totalOutputTextTokenCount !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n parsedChunk.totalOutputTextTokenCount\n );\n }\n if (parsedChunk.completionReason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [\n parsedChunk.completionReason,\n ]);\n }\n }\n private static recordLlamaAttributes(parsedChunk: any, span: Span) {\n if (parsedChunk.prompt_token_count !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_INPUT_TOKENS,\n parsedChunk.prompt_token_count\n );\n }\n if (parsedChunk.generation_token_count !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n parsedChunk.generation_token_count\n );\n }\n if (parsedChunk.stop_reason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [\n parsedChunk.stop_reason,\n ]);\n }\n }\n\n private static recordMistralAttributes(parsedChunk: any, span: Span) {\n if (parsedChunk.outputs?.[0]?.text !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n // NOTE: We approximate the token count since this value is not directly available in the body\n // According to Bedrock docs they use (total_chars / 6) to approximate token count for pricing.\n // https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-prepare.html\n Math.ceil(parsedChunk.outputs[0].text.length / 6)\n );\n }\n if (parsedChunk.outputs?.[0]?.stop_reason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [\n parsedChunk.outputs[0].stop_reason,\n ]);\n }\n }\n\n private static recordCohereAttributes(parsedChunk: any, span: Span) {\n if (parsedChunk.generations?.[0]?.text !== undefined) {\n span.setAttribute(\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n // NOTE: We approximate the token count since this value is not directly available in the body\n // According to Bedrock docs they use (total_chars / 6) to approximate token count for pricing.\n // https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-prepare.html\n Math.ceil(parsedChunk.generations[0].text.length / 6)\n );\n }\n if (parsedChunk.generations?.[0]?.finish_reason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [\n parsedChunk.generations[0].finish_reason,\n ]);\n }\n }\n\n private static recordCohereRAttributes(parsedChunk: any, span: Span) {\n if (parsedChunk.text !== undefined) {\n // NOTE: We approximate the token count since this value is not directly available in the body\n // According to Bedrock docs they use (total_chars / 6) to approximate token count for pricing.\n // https://docs.aws.amazon.com/bedrock/latest/userguide/model-customization-prepare.html\n span.setAttribute(\n ATTR_GEN_AI_USAGE_OUTPUT_TOKENS,\n Math.ceil(parsedChunk.text.length / 6)\n );\n }\n if (parsedChunk.finish_reason !== undefined) {\n span.setAttribute(ATTR_GEN_AI_RESPONSE_FINISH_REASONS, [\n parsedChunk.finish_reason,\n ]);\n }\n }\n}\n"]}
@@ -1,3 +1,3 @@
1
- export declare const PACKAGE_VERSION = "0.62.0";
1
+ export declare const PACKAGE_VERSION = "0.64.0";
2
2
  export declare const PACKAGE_NAME = "@opentelemetry/instrumentation-aws-sdk";
3
3
  //# sourceMappingURL=version.d.ts.map
@@ -17,6 +17,6 @@
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.PACKAGE_NAME = exports.PACKAGE_VERSION = void 0;
19
19
  // this is autogenerated file, see scripts/version-update.js
20
- exports.PACKAGE_VERSION = '0.62.0';
20
+ exports.PACKAGE_VERSION = '0.64.0';
21
21
  exports.PACKAGE_NAME = '@opentelemetry/instrumentation-aws-sdk';
22
22
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,eAAe,GAAG,QAAQ,CAAC;AAC3B,QAAA,YAAY,GAAG,wCAAwC,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const PACKAGE_VERSION = '0.62.0';\nexport const PACKAGE_NAME = '@opentelemetry/instrumentation-aws-sdk';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,eAAe,GAAG,QAAQ,CAAC;AAC3B,QAAA,YAAY,GAAG,wCAAwC,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const PACKAGE_VERSION = '0.64.0';\nexport const PACKAGE_NAME = '@opentelemetry/instrumentation-aws-sdk';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentelemetry/instrumentation-aws-sdk",
3
- "version": "0.62.0",
3
+ "version": "0.64.0",
4
4
  "description": "OpenTelemetry instrumentation for `aws-sdk` and `@aws-sdk/client-*` clients for various AWS services",
5
5
  "keywords": [
6
6
  "aws",
@@ -34,8 +34,6 @@
34
34
  "clean": "rimraf build/*",
35
35
  "compile:with-dependencies": "nx run-many -t compile -p @opentelemetry/instrumentation-aws-sdk",
36
36
  "compile": "tsc -p .",
37
- "lint": "eslint . --ext=ts,js,mjs",
38
- "lint:fix": "eslint . --ext=ts,js,mjs --fix",
39
37
  "lint:readme": "node ../../scripts/lint-readme.js",
40
38
  "prepublishOnly": "npm run compile",
41
39
  "tdd": "npm run test -- --watch-extensions ts --watch",
@@ -49,7 +47,7 @@
49
47
  },
50
48
  "dependencies": {
51
49
  "@opentelemetry/core": "^2.0.0",
52
- "@opentelemetry/instrumentation": "^0.206.0",
50
+ "@opentelemetry/instrumentation": "^0.208.0",
53
51
  "@opentelemetry/semantic-conventions": "^1.34.0"
54
52
  },
55
53
  "devDependencies": {
@@ -64,13 +62,12 @@
64
62
  "@aws-sdk/client-sqs": "^3.85.0",
65
63
  "@aws-sdk/types": "^3.370.0",
66
64
  "@opentelemetry/api": "^1.3.0",
67
- "@opentelemetry/contrib-test-utils": "^0.53.0",
65
+ "@opentelemetry/contrib-test-utils": "^0.55.0",
68
66
  "@opentelemetry/sdk-trace-base": "^2.0.0",
69
67
  "@smithy/node-http-handler": "4.1.1",
70
68
  "@types/mocha": "10.0.10",
71
69
  "@types/node": "18.18.14",
72
70
  "@types/sinon": "17.0.4",
73
- "eslint": "8.7.0",
74
71
  "expect": "29.2.0",
75
72
  "nock": "13.3.3",
76
73
  "nyc": "17.1.0",
@@ -82,5 +79,5 @@
82
79
  "engines": {
83
80
  "node": "^18.19.0 || >=20.6.0"
84
81
  },
85
- "gitHead": "333e026413f082f90859bb778abf7519fbffa940"
82
+ "gitHead": "94e5b7da4500459e38e8d4dfda93542f22159600"
86
83
  }