From 98f313c9ad88bf222eb1316877361a628e38e266 Mon Sep 17 00:00:00 2001
From: yahya-mouman <yahya.mouman@datadoghq.com>
Date: Mon, 20 Jan 2025 17:52:05 +0100
Subject: [PATCH 01/10] refactor apm tracing

---
 CODEOWNERS                                    |   1 +
 .../datadog-instrumentations/src/aws-sdk.js   |   4 +-
 .../src/services/bedrockruntime/index.js      |  14 ++
 .../src/services/bedrockruntime/tracing.js    |  65 ++++++++
 .../utils.js}                                 | 146 +++++++++---------
 ...bedrock.spec.js => bedrockruntime.spec.js} |   4 +-
 6 files changed, 155 insertions(+), 79 deletions(-)
 create mode 100644 packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/index.js
 create mode 100644 packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/tracing.js
 rename packages/datadog-plugin-aws-sdk/src/services/{bedrockruntime.js => bedrockruntime/utils.js} (71%)
 rename packages/datadog-plugin-aws-sdk/test/{bedrock.spec.js => bedrockruntime.spec.js} (98%)

diff --git a/CODEOWNERS b/CODEOWNERS
index 52963649952..08ef93c96ef 100644
--- a/CODEOWNERS
+++ b/CODEOWNERS
@@ -59,6 +59,7 @@
 /packages/datadog-plugin-langchain/ @DataDog/ml-observability
 /packages/datadog-instrumentations/src/openai.js @DataDog/ml-observability
 /packages/datadog-instrumentations/src/langchain.js @DataDog/ml-observability
+/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime @DataDog/ml-observability
 
 # CI
 /.github/workflows/appsec.yml @DataDog/asm-js
diff --git a/packages/datadog-instrumentations/src/aws-sdk.js b/packages/datadog-instrumentations/src/aws-sdk.js
index a82092927d7..e83f51e4d37 100644
--- a/packages/datadog-instrumentations/src/aws-sdk.js
+++ b/packages/datadog-instrumentations/src/aws-sdk.js
@@ -155,6 +155,8 @@ function getMessage (request, error, result) {
 }
 
 function getChannelSuffix (name) {
+  // some resource identifiers have spaces between ex: bedrock runtime
+  name = name.split(' ').join('')
   return [
     'cloudwatchlogs',
     'dynamodb',
@@ -168,7 +170,7 @@ function getChannelSuffix (name) {
     'sqs',
     'states',
     'stepfunctions',
-    'bedrock runtime'
+    'bedrockruntime'
   ].includes(name)
     ? name
     : 'default'
diff --git a/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/index.js b/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/index.js
new file mode 100644
index 00000000000..00686c98fec
--- /dev/null
+++ b/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/index.js
@@ -0,0 +1,14 @@
+const CompositePlugin = require('../../../../dd-trace/src/plugins/composite')
+const BedrockRuntimeTracing = require('./tracing')
+class BedrockRuntimePlugin extends CompositePlugin {
+  static get id () {
+    return 'bedrock'
+  }
+
+  static get plugins () {
+    return {
+      tracing: BedrockRuntimeTracing
+    }
+  }
+}
+module.exports = BedrockRuntimePlugin
diff --git a/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/tracing.js b/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/tracing.js
new file mode 100644
index 00000000000..0e0bff8298d
--- /dev/null
+++ b/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/tracing.js
@@ -0,0 +1,65 @@
+'use strict'
+
+const BaseAwsSdkPlugin = require('../../base')
+const { parseModelId, extractRequestParams, extractTextAndResponseReason } = require('./utils')
+
+const enabledOperations = ['invokeModel']
+
+class BedrockRuntime extends BaseAwsSdkPlugin {
+  static get id () { return 'bedrockruntime' }
+
+  isEnabled (request) {
+    const operation = request.operation
+    if (!enabledOperations.includes(operation)) {
+      return false
+    }
+
+    return super.isEnabled(request)
+  }
+
+  generateTags (params, operation, response) {
+    let tags = {}
+
+    const { modelProvider, modelName } = parseModelId(params.modelId)
+
+    const requestParams = extractRequestParams(params, modelProvider)
+    const textAndResponseReason = extractTextAndResponseReason(response, modelProvider, modelName)
+
+    tags = buildTagsFromParams(requestParams, textAndResponseReason, modelProvider, modelName, operation)
+
+    return tags
+  }
+}
+
+function buildTagsFromParams (requestParams, textAndResponseReason, modelProvider, modelName, operation) {
+  const tags = {}
+
+  // add request tags
+  tags['resource.name'] = operation
+  tags['aws.bedrock.request.model'] = modelName
+  tags['aws.bedrock.request.model_provider'] = modelProvider.toLowerCase()
+  tags['aws.bedrock.request.prompt'] = requestParams.prompt
+  tags['aws.bedrock.request.temperature'] = requestParams.temperature
+  tags['aws.bedrock.request.top_p'] = requestParams.topP
+  tags['aws.bedrock.request.top_k'] = requestParams.topK
+  tags['aws.bedrock.request.max_tokens'] = requestParams.maxTokens
+  tags['aws.bedrock.request.stop_sequences'] = requestParams.stopSequences
+  tags['aws.bedrock.request.input_type'] = requestParams.inputType
+  tags['aws.bedrock.request.truncate'] = requestParams.truncate
+  tags['aws.bedrock.request.stream'] = requestParams.stream
+  tags['aws.bedrock.request.n'] = requestParams.n
+
+  // add response tags
+  if (modelName.includes('embed')) {
+    tags['aws.bedrock.response.embedding_length'] = textAndResponseReason.message.length
+  }
+  if (textAndResponseReason.choiceId) {
+    tags['aws.bedrock.response.choices.id'] = textAndResponseReason.choiceId
+  }
+  tags['aws.bedrock.response.choices.text'] = textAndResponseReason.message
+  tags['aws.bedrock.response.choices.finish_reason'] = textAndResponseReason.finishReason
+
+  return tags
+}
+
+module.exports = BedrockRuntime
diff --git a/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime.js b/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js
similarity index 71%
rename from packages/datadog-plugin-aws-sdk/src/services/bedrockruntime.js
rename to packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js
index ef4efe76291..a11e604eecb 100644
--- a/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime.js
+++ b/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js
@@ -1,7 +1,17 @@
-'use strict'
+// This file is used to extract the request and response data from the AWS SDK clients.
 
-const BaseAwsSdkPlugin = require('../base')
-const log = require('../../../dd-trace/src/log')
+const log = require('../../../../dd-trace/src/log')
+
+const MODEL_TYPE_IDENTIFIERS = [
+  'foundation-model/',
+  'custom-model/',
+  'provisioned-model/',
+  'imported-module/',
+  'prompt/',
+  'endpoint/',
+  'inference-profile/',
+  'default-prompt-router/'
+]
 
 const PROVIDER = {
   AI21: 'AI21',
@@ -13,44 +23,6 @@ const PROVIDER = {
   MISTRAL: 'MISTRAL'
 }
 
-const enabledOperations = ['invokeModel']
-
-class BedrockRuntime extends BaseAwsSdkPlugin {
-  static get id () { return 'bedrock runtime' }
-
-  isEnabled (request) {
-    const operation = request.operation
-    if (!enabledOperations.includes(operation)) {
-      return false
-    }
-
-    return super.isEnabled(request)
-  }
-
-  generateTags (params, operation, response) {
-    let tags = {}
-    let modelName = ''
-    let modelProvider = ''
-    const modelMeta = params.modelId.split('.')
-    if (modelMeta.length === 2) {
-      [modelProvider, modelName] = modelMeta
-      modelProvider = modelProvider.toUpperCase()
-    } else {
-      [, modelProvider, modelName] = modelMeta
-      modelProvider = modelProvider.toUpperCase()
-    }
-
-    const shouldSetChoiceIds = modelProvider === PROVIDER.COHERE && !modelName.includes('embed')
-
-    const requestParams = extractRequestParams(params, modelProvider)
-    const textAndResponseReason = extractTextAndResponseReason(response, modelProvider, modelName, shouldSetChoiceIds)
-
-    tags = buildTagsFromParams(requestParams, textAndResponseReason, modelProvider, modelName, operation)
-
-    return tags
-  }
-}
-
 class Generation {
   constructor ({ message = '', finishReason = '', choiceId = '' } = {}) {
     // stringify message as it could be a single generated message as well as a list of embeddings
@@ -65,6 +37,7 @@ class RequestParams {
     prompt = '',
     temperature = undefined,
     topP = undefined,
+    topK = undefined,
     maxTokens = undefined,
     stopSequences = [],
     inputType = '',
@@ -72,11 +45,11 @@ class RequestParams {
     stream = '',
     n = undefined
   } = {}) {
-    // TODO: set a truncation limit to prompt
     // stringify prompt as it could be a single prompt as well as a list of message objects
     this.prompt = typeof prompt === 'string' ? prompt : JSON.stringify(prompt) || ''
     this.temperature = temperature !== undefined ? temperature : undefined
     this.topP = topP !== undefined ? topP : undefined
+    this.topK = topK !== undefined ? topK : undefined
     this.maxTokens = maxTokens !== undefined ? maxTokens : undefined
     this.stopSequences = stopSequences || []
     this.inputType = inputType || ''
@@ -86,11 +59,53 @@ class RequestParams {
   }
 }
 
+function parseModelId (modelId) {
+  // Best effort to extract the model provider and model name from the bedrock model ID.
+  // modelId can be a 1/2 period-separated string or a full AWS ARN, based on the following formats:
+  // 1. Base model: "{model_provider}.{model_name}"
+  // 2. Cross-region model: "{region}.{model_provider}.{model_name}"
+  // 3. Other: Prefixed by AWS ARN "arn:aws{+region?}:bedrock:{region}:{account-id}:"
+  //     a. Foundation model: ARN prefix + "foundation-model/{region?}.{model_provider}.{model_name}"
+  //     b. Custom model: ARN prefix + "custom-model/{model_provider}.{model_name}"
+  //     c. Provisioned model: ARN prefix + "provisioned-model/{model-id}"
+  //     d. Imported model: ARN prefix + "imported-module/{model-id}"
+  //     e. Prompt management: ARN prefix + "prompt/{prompt-id}"
+  //     f. Sagemaker: ARN prefix + "endpoint/{model-id}"
+  //     g. Inference profile: ARN prefix + "{application-?}inference-profile/{model-id}"
+  //     h. Default prompt router: ARN prefix + "default-prompt-router/{prompt-id}"
+  // If model provider cannot be inferred from the modelId formatting, then default to "custom"
+  modelId = modelId.toLowerCase()
+  if (!modelId.startsWith('arn:aws')) {
+    const modelMeta = modelId.split('.')
+    if (modelMeta.length < 2) {
+      return { modelProvider: 'custom', modelName: modelMeta[0] }
+    }
+    return { modelProvider: modelMeta[modelMeta.length - 2], modelName: modelMeta[modelMeta.length - 1] }
+  }
+
+  for (const identifier of MODEL_TYPE_IDENTIFIERS) {
+    if (!modelId.includes(identifier)) {
+      continue
+    }
+    modelId = modelId.split(identifier).pop()
+    if (['foundation-model/', 'custom-model/'].includes(identifier)) {
+      const modelMeta = modelId.split('.')
+      if (modelMeta.length < 2) {
+        return { modelProvider: 'custom', modelName: modelId }
+      }
+      return { modelProvider: modelMeta[modelMeta.length - 2], modelName: modelMeta[modelMeta.length - 1] }
+    }
+    return { modelProvider: 'custom', modelName: modelId }
+  }
+
+  return { modelProvider: 'custom', modelName: 'custom' }
+}
+
 function extractRequestParams (params, provider) {
   const requestBody = JSON.parse(params.body)
   const modelId = params.modelId
 
-  switch (provider) {
+  switch (provider.toUpperCase()) {
     case PROVIDER.AI21: {
       let userPrompt = requestBody.prompt
       if (modelId.includes('jamba')) {
@@ -176,11 +191,13 @@ function extractRequestParams (params, provider) {
   }
 }
 
-function extractTextAndResponseReason (response, provider, modelName, shouldSetChoiceIds) {
+function extractTextAndResponseReason (response, provider, modelName, shouldSetChoiceIds = undefined) {
   const body = JSON.parse(Buffer.from(response.body).toString('utf8'))
-
+  if (shouldSetChoiceIds === undefined) {
+    shouldSetChoiceIds = provider.toUpperCase() === PROVIDER.COHERE && !modelName.includes
+  }
   try {
-    switch (provider) {
+    switch (provider.toUpperCase()) {
       case PROVIDER.AI21: {
         if (modelName.includes('jamba')) {
           const generations = body.choices || []
@@ -262,34 +279,11 @@ function extractTextAndResponseReason (response, provider, modelName, shouldSetC
   return new Generation()
 }
 
-function buildTagsFromParams (requestParams, textAndResponseReason, modelProvider, modelName, operation) {
-  const tags = {}
-
-  // add request tags
-  tags['resource.name'] = operation
-  tags['aws.bedrock.request.model'] = modelName
-  tags['aws.bedrock.request.model_provider'] = modelProvider
-  tags['aws.bedrock.request.prompt'] = requestParams.prompt
-  tags['aws.bedrock.request.temperature'] = requestParams.temperature
-  tags['aws.bedrock.request.top_p'] = requestParams.topP
-  tags['aws.bedrock.request.max_tokens'] = requestParams.maxTokens
-  tags['aws.bedrock.request.stop_sequences'] = requestParams.stopSequences
-  tags['aws.bedrock.request.input_type'] = requestParams.inputType
-  tags['aws.bedrock.request.truncate'] = requestParams.truncate
-  tags['aws.bedrock.request.stream'] = requestParams.stream
-  tags['aws.bedrock.request.n'] = requestParams.n
-
-  // add response tags
-  if (modelName.includes('embed')) {
-    tags['aws.bedrock.response.embedding_length'] = textAndResponseReason.message.length
-  }
-  if (textAndResponseReason.choiceId) {
-    tags['aws.bedrock.response.choices.id'] = textAndResponseReason.choiceId
-  }
-  tags['aws.bedrock.response.choices.text'] = textAndResponseReason.message
-  tags['aws.bedrock.response.choices.finish_reason'] = textAndResponseReason.finishReason
-
-  return tags
+module.exports = {
+  Generation,
+  RequestParams,
+  parseModelId,
+  extractRequestParams,
+  extractTextAndResponseReason,
+  PROVIDER
 }
-
-module.exports = BedrockRuntime
diff --git a/packages/datadog-plugin-aws-sdk/test/bedrock.spec.js b/packages/datadog-plugin-aws-sdk/test/bedrockruntime.spec.js
similarity index 98%
rename from packages/datadog-plugin-aws-sdk/test/bedrock.spec.js
rename to packages/datadog-plugin-aws-sdk/test/bedrockruntime.spec.js
index 0990f25e198..4fd46b252f6 100644
--- a/packages/datadog-plugin-aws-sdk/test/bedrock.spec.js
+++ b/packages/datadog-plugin-aws-sdk/test/bedrockruntime.spec.js
@@ -16,7 +16,7 @@ const PROVIDER = {
 }
 
 describe('Plugin', () => {
-  describe('aws-sdk (bedrock)', function () {
+  describe('aws-sdk (bedrockruntime)', function () {
     setup()
 
     withVersions('aws-sdk', ['@aws-sdk/smithy-client', 'aws-sdk'], '>=3', (version, moduleName) => {
@@ -217,7 +217,7 @@ describe('Plugin', () => {
               expect(span.meta).to.include({
                 'aws.operation': 'invokeModel',
                 'aws.bedrock.request.model': model.modelId.split('.')[1],
-                'aws.bedrock.request.model_provider': model.provider,
+                'aws.bedrock.request.model_provider': model.provider.toLowerCase(),
                 'aws.bedrock.request.prompt': model.userPrompt
               })
               expect(span.metrics).to.include({

From 464d44cf0479650e6f918f885822cc3a7a41b428 Mon Sep 17 00:00:00 2001
From: yahya-mouman <103438582+yahya-mouman@users.noreply.github.com>
Date: Tue, 21 Jan 2025 15:15:29 +0100
Subject: [PATCH 02/10] Update
 packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/index.js

Co-authored-by: Sam Brenner <106700075+sabrenner@users.noreply.github.com>
---
 .../datadog-plugin-aws-sdk/src/services/bedrockruntime/index.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/index.js b/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/index.js
index 00686c98fec..74d54469285 100644
--- a/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/index.js
+++ b/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/index.js
@@ -2,7 +2,7 @@ const CompositePlugin = require('../../../../dd-trace/src/plugins/composite')
 const BedrockRuntimeTracing = require('./tracing')
 class BedrockRuntimePlugin extends CompositePlugin {
   static get id () {
-    return 'bedrock'
+    return 'bedrockruntime'
   }
 
   static get plugins () {

From b797d55aa5b2f8e62bb490acd503428054a8d997 Mon Sep 17 00:00:00 2001
From: yahya-mouman <103438582+yahya-mouman@users.noreply.github.com>
Date: Tue, 21 Jan 2025 15:15:48 +0100
Subject: [PATCH 03/10] Update
 packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/tracing.js

Co-authored-by: Sam Brenner <106700075+sabrenner@users.noreply.github.com>
---
 .../src/services/bedrockruntime/tracing.js                       | 1 -
 1 file changed, 1 deletion(-)

diff --git a/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/tracing.js b/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/tracing.js
index 0e0bff8298d..a87edc048c9 100644
--- a/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/tracing.js
+++ b/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/tracing.js
@@ -18,7 +18,6 @@ class BedrockRuntime extends BaseAwsSdkPlugin {
   }
 
   generateTags (params, operation, response) {
-    let tags = {}
 
     const { modelProvider, modelName } = parseModelId(params.modelId)
 

From 0a3fe022252cf834d98b6fe80874d1c48eb3b6da Mon Sep 17 00:00:00 2001
From: yahya-mouman <103438582+yahya-mouman@users.noreply.github.com>
Date: Tue, 21 Jan 2025 15:15:58 +0100
Subject: [PATCH 04/10] Update
 packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/tracing.js

Co-authored-by: Sam Brenner <106700075+sabrenner@users.noreply.github.com>
---
 .../src/services/bedrockruntime/tracing.js                      | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/tracing.js b/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/tracing.js
index a87edc048c9..d80d58cba3f 100644
--- a/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/tracing.js
+++ b/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/tracing.js
@@ -24,7 +24,7 @@ class BedrockRuntime extends BaseAwsSdkPlugin {
     const requestParams = extractRequestParams(params, modelProvider)
     const textAndResponseReason = extractTextAndResponseReason(response, modelProvider, modelName)
 
-    tags = buildTagsFromParams(requestParams, textAndResponseReason, modelProvider, modelName, operation)
+    const tags = buildTagsFromParams(requestParams, textAndResponseReason, modelProvider, modelName, operation)
 
     return tags
   }

From d209e07a80b9866536d75cc2dd7687477ef11d16 Mon Sep 17 00:00:00 2001
From: yahya-mouman <103438582+yahya-mouman@users.noreply.github.com>
Date: Tue, 21 Jan 2025 15:16:55 +0100
Subject: [PATCH 05/10] Update
 packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js

Co-authored-by: Sam Brenner <106700075+sabrenner@users.noreply.github.com>
---
 .../datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js b/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js
index a11e604eecb..f20c43c983d 100644
--- a/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js
+++ b/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js
@@ -1,4 +1,4 @@
-// This file is used to extract the request and response data from the AWS SDK clients.
+'use strict'
 
 const log = require('../../../../dd-trace/src/log')
 

From 01bacb041db6d7abc9ac60604e9429afc6c0a54b Mon Sep 17 00:00:00 2001
From: yahya-mouman <yahya.mouman@datadoghq.com>
Date: Tue, 21 Jan 2025 15:27:50 +0100
Subject: [PATCH 06/10] CODEOWNERS

---
 CODEOWNERS | 1 +
 1 file changed, 1 insertion(+)

diff --git a/CODEOWNERS b/CODEOWNERS
index 08ef93c96ef..1d3f2fd373b 100644
--- a/CODEOWNERS
+++ b/CODEOWNERS
@@ -60,6 +60,7 @@
 /packages/datadog-instrumentations/src/openai.js @DataDog/ml-observability
 /packages/datadog-instrumentations/src/langchain.js @DataDog/ml-observability
 /packages/datadog-plugin-aws-sdk/src/services/bedrockruntime @DataDog/ml-observability
+/packages/datadog-plugin-aws-sdk/test/bedrockruntime.spec.js @DataDog/ml-observability
 
 # CI
 /.github/workflows/appsec.yml @DataDog/asm-js

From c421371d11aa2a7fbf7fe35288c86eb9c462df9d Mon Sep 17 00:00:00 2001
From: yahya-mouman <yahya.mouman@datadoghq.com>
Date: Tue, 21 Jan 2025 16:16:37 +0100
Subject: [PATCH 07/10] remove shouldSetChoiceId override

---
 .../src/services/bedrockruntime/utils.js                      | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js b/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js
index f20c43c983d..08f264ca427 100644
--- a/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js
+++ b/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js
@@ -193,9 +193,7 @@ function extractRequestParams (params, provider) {
 
 function extractTextAndResponseReason (response, provider, modelName, shouldSetChoiceIds = undefined) {
   const body = JSON.parse(Buffer.from(response.body).toString('utf8'))
-  if (shouldSetChoiceIds === undefined) {
-    shouldSetChoiceIds = provider.toUpperCase() === PROVIDER.COHERE && !modelName.includes
-  }
+  shouldSetChoiceIds = provider.toUpperCase() === PROVIDER.COHERE && !modelName.includes('embed')
   try {
     switch (provider.toUpperCase()) {
       case PROVIDER.AI21: {

From dd3dca4ee62aebb4ff484044867a0ca56295ea4e Mon Sep 17 00:00:00 2001
From: yahya-mouman <yahya.mouman@datadoghq.com>
Date: Tue, 21 Jan 2025 16:17:34 +0100
Subject: [PATCH 08/10] remove shouldSetChoiceId override

---
 .../src/services/bedrockruntime/utils.js                      | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js b/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js
index 08f264ca427..8bcb6a6f592 100644
--- a/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js
+++ b/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js
@@ -191,9 +191,9 @@ function extractRequestParams (params, provider) {
   }
 }
 
-function extractTextAndResponseReason (response, provider, modelName, shouldSetChoiceIds = undefined) {
+function extractTextAndResponseReason (response, provider, modelName) {
   const body = JSON.parse(Buffer.from(response.body).toString('utf8'))
-  shouldSetChoiceIds = provider.toUpperCase() === PROVIDER.COHERE && !modelName.includes('embed')
+  const shouldSetChoiceIds = provider.toUpperCase() === PROVIDER.COHERE && !modelName.includes('embed')
   try {
     switch (provider.toUpperCase()) {
       case PROVIDER.AI21: {

From 098b07475fc01421580e4545d195d9a13b233407 Mon Sep 17 00:00:00 2001
From: yahya-mouman <yahya.mouman@datadoghq.com>
Date: Tue, 21 Jan 2025 18:12:25 +0100
Subject: [PATCH 09/10] lint

---
 .../src/services/bedrockruntime/tracing.js                       | 1 -
 1 file changed, 1 deletion(-)

diff --git a/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/tracing.js b/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/tracing.js
index d80d58cba3f..9d7d0fb1ac7 100644
--- a/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/tracing.js
+++ b/packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/tracing.js
@@ -18,7 +18,6 @@ class BedrockRuntime extends BaseAwsSdkPlugin {
   }
 
   generateTags (params, operation, response) {
-
     const { modelProvider, modelName } = parseModelId(params.modelId)
 
     const requestParams = extractRequestParams(params, modelProvider)

From 255f8e6603a9ea3a7734c13ceb87ef914dc8455c Mon Sep 17 00:00:00 2001
From: yahya-mouman <103438582+yahya-mouman@users.noreply.github.com>
Date: Fri, 24 Jan 2025 13:40:45 +0100
Subject: [PATCH 10/10] Update packages/datadog-instrumentations/src/aws-sdk.js

Co-authored-by: Thomas Hunter II <tlhunter@datadog.com>
---
 packages/datadog-instrumentations/src/aws-sdk.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/packages/datadog-instrumentations/src/aws-sdk.js b/packages/datadog-instrumentations/src/aws-sdk.js
index e83f51e4d37..f645eb18f7c 100644
--- a/packages/datadog-instrumentations/src/aws-sdk.js
+++ b/packages/datadog-instrumentations/src/aws-sdk.js
@@ -156,7 +156,7 @@ function getMessage (request, error, result) {
 
 function getChannelSuffix (name) {
   // some resource identifiers have spaces between ex: bedrock runtime
-  name = name.split(' ').join('')
+  name = name.replaceAll(' ', '')
   return [
     'cloudwatchlogs',
     'dynamodb',