Skip to content

Commit b855902

Browse files
committed
@smithy/smithy-client send subscriber with AWS Bedrock Middleware integration
1 parent 915b320 commit b855902

File tree

9 files changed

+592
-421
lines changed

9 files changed

+592
-421
lines changed

lib/instrumentation/aws-sdk/v3/bedrock.js

Lines changed: 0 additions & 409 deletions
This file was deleted.

lib/instrumentation/aws-sdk/v3/smithy-client.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ const { snsMiddlewareConfig } = require('./sns')
1010
const { sqsMiddlewareConfig } = require('./sqs')
1111
const { dynamoMiddlewareConfig } = require('./dynamodb')
1212
const { lambdaMiddlewareConfig } = require('./lambda')
13-
const { bedrockMiddlewareConfig } = require('./bedrock')
1413
const MIDDLEWARE = Symbol('nrMiddleware')
1514

1615
const middlewareByClient = {
1716
Client: middlewareConfig,
18-
BedrockRuntime: [...middlewareConfig, bedrockMiddlewareConfig],
1917
Lambda: [...middlewareConfig, lambdaMiddlewareConfig],
2018
SNS: [...middlewareConfig, snsMiddlewareConfig],
2119
SQS: [...middlewareConfig, sqsMiddlewareConfig],
@@ -31,13 +29,23 @@ module.exports = function instrumentSmithyClient(shim, smithyClientExport) {
3129
}
3230
}
3331

32+
// Clients handled by subscriber-based instrumentation in
33+
// lib/subscribers/smithy-client/send.js. Skip them here to avoid
34+
// double middleware registration during the migration.
35+
const subscriberHandledClients = new Set(['BedrockRuntime'])
36+
3437
function wrapSend(shim, send) {
3538
return function wrappedSend() {
3639
// most clients we want to instrument aside from smithy-client
3740
// extend themselves to provide different names(i.e. - SNS and SNSClient)
3841
// we want to handle these the same by registering the sns middleware
3942
const client = this.constructor.name.replace(/Client$/, '')
4043
shim.logger.trace('Sending with client %s', client)
44+
45+
if (subscriberHandledClients.has(client)) {
46+
return send.apply(this, arguments)
47+
}
48+
4149
const config = this.config
4250
const middlewares = middlewareByClient[client] || middlewareByClient.Client
4351

lib/subscriber-configs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const subscribers = {
3333
...require('./subscribers/q/config'),
3434
...require('./subscribers/redis/config'),
3535
...require('./subscribers/redis-client/config'),
36+
...require('./subscribers/smithy-client/config'),
3637
...require('./subscribers/undici/config'),
3738
...require('./subscribers/winston/config')
3839
}

0 commit comments

Comments
 (0)