-
Notifications
You must be signed in to change notification settings - Fork 312
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(chore)APM: Refactor Bedrock Integration (#5137)
* refactor apm tracing * Update packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/index.js Co-authored-by: Sam Brenner <[email protected]> * Update packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/tracing.js Co-authored-by: Sam Brenner <[email protected]> * Update packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/tracing.js Co-authored-by: Sam Brenner <[email protected]> * Update packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/utils.js Co-authored-by: Sam Brenner <[email protected]> * CODEOWNERS * remove shouldSetChoiceId override * remove shouldSetChoiceId override * lint * Update packages/datadog-instrumentations/src/aws-sdk.js Co-authored-by: Thomas Hunter II <[email protected]> --------- Co-authored-by: Sam Brenner <[email protected]> Co-authored-by: Thomas Hunter II <[email protected]>
- Loading branch information
1 parent
30efc06
commit f41f5f7
Showing
6 changed files
with
151 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const CompositePlugin = require('../../../../dd-trace/src/plugins/composite') | ||
const BedrockRuntimeTracing = require('./tracing') | ||
class BedrockRuntimePlugin extends CompositePlugin { | ||
static get id () { | ||
return 'bedrockruntime' | ||
} | ||
|
||
static get plugins () { | ||
return { | ||
tracing: BedrockRuntimeTracing | ||
} | ||
} | ||
} | ||
module.exports = BedrockRuntimePlugin |
63 changes: 63 additions & 0 deletions
63
packages/datadog-plugin-aws-sdk/src/services/bedrockruntime/tracing.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
'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) { | ||
const { modelProvider, modelName } = parseModelId(params.modelId) | ||
|
||
const requestParams = extractRequestParams(params, modelProvider) | ||
const textAndResponseReason = extractTextAndResponseReason(response, modelProvider, modelName) | ||
|
||
const 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters