Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
409 changes: 0 additions & 409 deletions lib/instrumentation/aws-sdk/v3/bedrock.js

This file was deleted.

12 changes: 10 additions & 2 deletions lib/instrumentation/aws-sdk/v3/smithy-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ const { snsMiddlewareConfig } = require('./sns')
const { sqsMiddlewareConfig } = require('./sqs')
const { dynamoMiddlewareConfig } = require('./dynamodb')
const { lambdaMiddlewareConfig } = require('./lambda')
const { bedrockMiddlewareConfig } = require('./bedrock')
const MIDDLEWARE = Symbol('nrMiddleware')

const middlewareByClient = {
Client: middlewareConfig,
BedrockRuntime: [...middlewareConfig, bedrockMiddlewareConfig],
Lambda: [...middlewareConfig, lambdaMiddlewareConfig],
SNS: [...middlewareConfig, snsMiddlewareConfig],
SQS: [...middlewareConfig, sqsMiddlewareConfig],
Expand All @@ -31,13 +29,23 @@ module.exports = function instrumentSmithyClient(shim, smithyClientExport) {
}
}

// Clients handled by subscriber-based instrumentation in
// lib/subscribers/smithy-client/send.js. Skip them here to avoid
// double middleware registration during the migration.
const subscriberHandledClients = new Set(['BedrockRuntime'])

function wrapSend(shim, send) {
return function wrappedSend() {
// most clients we want to instrument aside from smithy-client
// extend themselves to provide different names(i.e. - SNS and SNSClient)
// we want to handle these the same by registering the sns middleware
const client = this.constructor.name.replace(/Client$/, '')
shim.logger.trace('Sending with client %s', client)

if (subscriberHandledClients.has(client)) {
return send.apply(this, arguments)
}

const config = this.config
const middlewares = middlewareByClient[client] || middlewareByClient.Client

Expand Down
1 change: 1 addition & 0 deletions lib/subscriber-configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// 'package-name': [ { path: 'subscriberPath', instrumentations: [] }, ... ]
const subscribers = {
...require('./subscribers/amqplib/config'),
...require('./subscribers/aws-sdk/config'),
...require('./subscribers/bluebird/config'),
...require('./subscribers/bunyan/config'),
...require('./subscribers/cassandra-driver/config'),
Expand Down
55 changes: 55 additions & 0 deletions lib/subscribers/aws-sdk/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2026 New Relic Corporation. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

const sendConfig = {
path: './aws-sdk/send.js',
instrumentations: [
// CJS
{
channelName: 'nr_send',
module: { name: '@smithy/smithy-client', versionRange: '>=4.0.0', filePath: 'dist-cjs/index.js' },
functionQuery: {
className: 'Client',
methodName: 'send',
kind: 'Sync'
}
},
{
channelName: 'nr_send',
module: { name: '@smithy/smithy-client', versionRange: '>=1.0.0 <4.0.0', filePath: 'dist-cjs/index.js' },
functionQuery: {
className: '_Client',
methodName: 'send',
kind: 'Sync'
}
},
// ESM
{
channelName: 'nr_send',
module: { name: '@smithy/smithy-client', versionRange: '>=4.0.0', filePath: 'dist-es/index.js' },
functionQuery: {
className: 'Client',
methodName: 'send',
kind: 'Sync'
}
},
{
channelName: 'nr_send',
module: { name: '@smithy/smithy-client', versionRange: '>=1.0.0 <4.0.0', filePath: 'dist-es/index.js' },
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is @aws-sdk/smithy-client no longer valid? We were instrumenting that before

Copy link
Copy Markdown
Contributor Author

@amychisholm03 amychisholm03 Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like I said in my PR description, @aws-sdk/smithy-client is like a 3-liner package that just exports @smithy/smithy-client, so we only need to subscribe to the later.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it do so across all versions of these libraries that we support?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For npm run versioned aws-sdk-v3 it appears so.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll test more versions with AGENT_PATH="$(pwd)" ./node_modules/.bin/versioned-tests --patch --print pretty -i 100 --all --strict test/versioned/aws-sdk-v3

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to our tests:

{"name": "@aws-sdk/smithy-client", "minSupported": "3.47.0", "minAgentVersion": "8.7.1"},

The minimum version of @aws-sdk/smithy-client we support is 3.47.0. That version's manifest does not reference @smithy/smithy-client:

https://npmx.dev/package-code/@aws-sdk/smithy-client/v/3.47.0/package.json#L21-L25

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least for @aws-sdk/client-bedrock-runtime >=3.474.0, it does not have @aws-sdk/smithy-client as a dependency, only @smithy/smithy-client. Now with other @aws-sdk/* packages, there may be older versions that used @aws-sdk/smithy-client and adding the subscriber config for that could be addressed in that future PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you saying that the subscriber implementation only works with @aws-sdk/* >= v3.474.0?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the smithy client subscriber should instrument Client.send (or _Client.send depending on version) for @smithy/smithy-client: >=1, but it is only being tested currently with the AWS Bedrock middleware which is @aws-sdk/client-bedrock-runtime versions >=3.474.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I can't see any direct dependents of 3.47 that we are concerned with. So maybe this isn't a problem.

functionQuery: {
className: '_Client',
methodName: 'send',
kind: 'Sync'
}
}
]
}

module.exports = {
'@smithy/smithy-client':
[
sendConfig
]
}
Loading
Loading