Skip to content

Commit

Permalink
fix: @aws-sdk/client-s3 instrumentation was broken with 3.363.0 release
Browse files Browse the repository at this point in the history
In aws/aws-sdk-js-v3#4873 aws-sdk v3 moved
@aws-sdk/smithy-client to @smithy/smithy-client. This will now
instrument either package name.

Fixes: #3454
  • Loading branch information
trentm committed Jun 29, 2023
1 parent 37345ca commit 73c9687
Show file tree
Hide file tree
Showing 4 changed files with 11,928 additions and 11,795 deletions.
4 changes: 2 additions & 2 deletions lib/instrumentation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const nodeHasInstrumentableFetch = typeof (global.fetch) === 'function'

var MODULES = [
'@apollo/server',
'@aws-sdk/smithy-client', // Instrument the base client which all AWS-SDK v3 clients extends
['@aws-sdk/smithy-client', '@smithy/smithy-client'], // Instrument the base client which all AWS-SDK v3 clients extends.
['@elastic/elasticsearch', '@elastic/elasticsearch-canary'],
'@opentelemetry/api',
'@opentelemetry/sdk-metrics',
Expand Down Expand Up @@ -430,7 +430,7 @@ Instrumentation.prototype._patchModule = function (modExports, name, version, en
continue
}

modExports = patch(modExports, this._agent, { version, enabled, isImportMod })
modExports = patch(modExports, this._agent, { name, version, enabled, isImportMod })
}
}
return modExports
Expand Down
11 changes: 8 additions & 3 deletions lib/instrumentation/modules/@aws-sdk/smithy-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

'use strict'

const semver = require('semver')
const shimmer = require('../../shimmer')
const elasticAPMMiddlewares = Symbol('elasticAPMMiddlewares')
Expand Down Expand Up @@ -57,11 +58,15 @@ const clientsConfig = {
}
}

module.exports = function (mod, agent, { version, enabled }) {
module.exports = function (mod, agent, { name, version, enabled }) {
if (!enabled) return mod

// We have to do this check since npm view reveals RC versions below 3
if (!semver.satisfies(version, '>=3 <4')) {
// As of `@aws-sdk/*@3.363.0` the underlying smithy-client is under the
// `@smithy/` npm org and is 1.x.
if (name === '@smithy/smithy-client' && !semver.satisfies(version, '>=1 <2')) {
agent.logger.debug('cannot instrument @aws-sdk/client-*: @smithy/smithy-client version %s not supported', version)
return mod
} else if (name === '@aws-sdk/smithy-client' && !semver.satisfies(version, '>=3 <4')) {
agent.logger.debug('cannot instrument @aws-sdk/client-*: @aws-sdk/smithy-client version %s not supported', version)
return mod
}
Expand Down
Loading

0 comments on commit 73c9687

Please sign in to comment.