Skip to content

Conversation

@mxiamxia
Copy link
Member

@mxiamxia mxiamxia commented Jul 29, 2025

Issue #, if available:

Description of changes:
OTel Instrumentation throws TextDecoder error on BedrockRuntime.InvokeModelWithResponseStream API response

  • Fix "The 'list' argument must be an instance of SharedArrayBuffer, ArrayBuffer or ArrayBufferView" error in BedrockRuntimeServiceExtension.responseHook()
  • Add type checking to handle different response body types from AWS SDK middleware:
    • String: Already processed by AWS SDK (Uint8ArrayBlobAdapter)
    • Uint8Array: Raw binary from AWS (decode with TextDecoder)
    • Buffer: Node.js Buffer (convert with toString('utf8'))
    • Unexpected types: Log debug message and skip processing gracefully

Test

  1. Reproduced the issue by using latest release with InvokeModelWithResponseStream
  events: [
    {
      name: 'exception',
      attributes: {
        'exception.type': 'ERR_INVALID_ARG_TYPE',
        'exception.message': 'The "list" argument must be an instance of SharedArrayBuffer, ArrayBuffer or ArrayBufferView.',
        'exception.stacktrace': 'TypeError: The "list" argument must be an instance of SharedArrayBuffer, ArrayBuffer or ArrayBufferView.\n' +
          '    at TextDecoder.decode (node:internal/encoding:443:16)\n' +
          '    at BedrockRuntimeServiceExtension.responseHook (/Users/xiami/Documents/workspace/apm/aws-otel-js-instrumentation/sample-applications/simple-express-server/node_modules/@aws/aws-distro-opentelemetry-node-autoinstrumentation/build/src/patches/aws/services/bedrock.js:303:59)\n' +
          '    at ServicesExtensions.responseHook (/Users/xiami/Documents/workspace/apm/aws-otel-js-instrumentation/sample-applications/simple-express-server/node_modules/@opentelemetry/instrumentation-aws-sdk/build/src/services/ServicesExtensions.js:37:154)\n' +
          '    at /Users/xiami/Documents/workspace/apm/aws-otel-js-instrumentation/sample-applications/simple-express-server/node_modules/@opentelemetry/instrumentation-aws-sdk/build/src/aws-sdk.js:257:53\n' +
          '    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)'
      },
      time: [ 1753815032, 337792 ],
      droppedAttributesCount: 0
    }
  ],
  links: []
  1. Tested with the fix and the issue is gone
  name: 'BedrockRuntime.InvokeModelWithResponseStream',
  id: '1d23a4c6f2498f7f',
  kind: 2,
  timestamp: 1753815031313000,
  duration: 687392.625,
  attributes: {
    'rpc.system': 'aws-api',
    'rpc.method': 'InvokeModelWithResponseStream',
    'rpc.service': 'BedrockRuntime',
    'gen_ai.system': 'aws.bedrock',
    'gen_ai.request.model': 'anthropic.claude-3-5-sonnet-20240620-v1:0',
    'gen_ai.request.max_tokens': 1000,
    'gen_ai.request.temperature': 0.7,
    'gen_ai.request.top_p': 0.9,
    'aws.is.local.root': false,

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

  - Fix "The 'list' argument must be an instance of SharedArrayBuffer, ArrayBuffer or ArrayBufferView" error in BedrockRuntimeServiceExtension.responseHook()
  - Add type checking to handle different response body types from AWS SDK middleware:
    - String: Already processed by AWS SDK (Uint8ArrayBlobAdapter)
    - Uint8Array: Raw binary from AWS (decode with TextDecoder)
    - Buffer: Node.js Buffer (convert with toString('utf8'))
    - Unexpected types: Log debug message and skip processing gracefully
@mxiamxia mxiamxia requested a review from a team as a code owner July 29, 2025 18:54
@mxiamxia mxiamxia requested a review from jj22ee July 29, 2025 18:54
@mxiamxia mxiamxia force-pushed the bedrock-instr-fix branch 2 times, most recently from 4f599a3 to 1439ae4 Compare July 30, 2025 19:04
@mxiamxia mxiamxia force-pushed the bedrock-instr-fix branch from 1439ae4 to 543d5ee Compare July 31, 2025 05:06
@mxiamxia mxiamxia force-pushed the bedrock-instr-fix branch from 543d5ee to 9159941 Compare July 31, 2025 18:29
@mxiamxia mxiamxia merged commit 7c0cdeb into aws-observability:main Aug 1, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants