Skip to content

Commit fe71aae

Browse files
authored
fix: @aws-sdk/client-s3 instrumentation was broken with 3.363.0 release (#3455)
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
1 parent 3000188 commit fe71aae

File tree

6 files changed

+12013
-11875
lines changed

6 files changed

+12013
-11875
lines changed

CHANGELOG.asciidoc

+3
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ See <<esm>> for full details.
7373
* Set the trace-context for an incoming HTTP/2 request. Contributed by @paulish.
7474
({issues}1830[#1830])
7575
76+
* Fix aws-sdk v3 instrumentation (currently just `@aws-sdk/client-s3`) for
77+
versions 3.363.0 and later. ({pull}3455[#3455])
78+
7679
[float]
7780
===== Chores
7881

lib/instrumentation/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const nodeHasInstrumentableFetch = typeof (global.fetch) === 'function'
3737

3838
var MODULES = [
3939
'@apollo/server',
40-
'@aws-sdk/smithy-client', // Instrument the base client which all AWS-SDK v3 clients extends
40+
['@aws-sdk/smithy-client', '@smithy/smithy-client'], // Instrument the base client which all AWS-SDK v3 clients extends.
4141
['@elastic/elasticsearch', '@elastic/elasticsearch-canary'],
4242
'@opentelemetry/api',
4343
'@opentelemetry/sdk-metrics',
@@ -430,7 +430,7 @@ Instrumentation.prototype._patchModule = function (modExports, name, version, en
430430
continue
431431
}
432432

433-
modExports = patch(modExports, this._agent, { version, enabled, isImportMod })
433+
modExports = patch(modExports, this._agent, { name, version, enabled, isImportMod })
434434
}
435435
}
436436
return modExports

lib/instrumentation/modules/@aws-sdk/smithy-client.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
'use strict'
8+
89
const semver = require('semver')
910
const shimmer = require('../../shimmer')
1011
const elasticAPMMiddlewares = Symbol('elasticAPMMiddlewares')
@@ -57,11 +58,15 @@ const clientsConfig = {
5758
}
5859
}
5960

60-
module.exports = function (mod, agent, { version, enabled }) {
61+
module.exports = function (mod, agent, { name, version, enabled }) {
6162
if (!enabled) return mod
6263

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

0 commit comments

Comments
 (0)