Skip to content

Commit 9069a82

Browse files
committed
fix(instr-aws-sdk): @smithy/[email protected] change broke aws-sdk-v3 instrumentation
As of smithy-lang/smithy-typescript#1146 (details at smithy-lang/smithy-typescript#1113) the CommonJS export for many (all?) `@smithy/*` packages is now an esbuild bundle -- all in `dist-cjs/index.js`. That means that subfile patching like this no longer works: ```js const v3SmithyMiddlewareStackFile = new InstrumentationNodeModuleFile( '@smithy/middleware-stack/dist-cjs/MiddlewareStack.js', ['>=1.0.1'], this.patchV3ConstructStack.bind(this), this.unpatchV3ConstructStack.bind(this) ); ``` In our case this breaks as of `@smithy/[email protected]` released 2024-01-17T22:26:42.432Z. This is considered a non-breaking change, so the dependency ranges for earlier released versions of `@smithy/smithy-client` will pick this up. A fix is to change the `@smithy/middleware-stack` patching to be on the top-level module exports. Because the `constructStack` field is only available as a getter we cannot use shimmer (InstrumentationBase._wrap). Instead this returns a new `moduleExports` object with a new getter that shims the call.
1 parent fce7d3b commit 9069a82

File tree

1 file changed

+14
-9
lines changed
  • plugins/node/opentelemetry-instrumentation-aws-sdk/src

1 file changed

+14
-9
lines changed

plugins/node/opentelemetry-instrumentation-aws-sdk/src/aws-sdk.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,23 @@ export class AwsInstrumentation extends InstrumentationBase<any> {
113113
]);
114114

115115
// patch for @smithy/middleware-stack for aws-sdk packages v3.363.0+
116-
const v3SmithyMiddlewareStackFile = new InstrumentationNodeModuleFile(
117-
'@smithy/middleware-stack/dist-cjs/MiddlewareStack.js',
118-
['>=1.0.1'],
119-
this.patchV3ConstructStack.bind(this),
120-
this.unpatchV3ConstructStack.bind(this)
121-
);
116+
const self = this;
122117
const v3SmithyMiddlewareStack = new InstrumentationNodeModuleDefinition(
123118
'@smithy/middleware-stack',
124119
['>=2.0.0'],
125-
undefined,
126-
undefined,
127-
[v3SmithyMiddlewareStackFile]
120+
(moduleExports, moduleVersion) => {
121+
// XXX need full propwrap, i.e. any possible props other that `constructStack`
122+
const newExports = {
123+
get constructStack() {
124+
return self._getV3ConstructStackPatch(
125+
moduleVersion,
126+
(moduleExports as any).constructStack
127+
);
128+
},
129+
};
130+
return newExports;
131+
},
132+
undefined // XXX Is no longer being able to unpatch an issue?
128133
);
129134

130135
const v3SmithyClient = new InstrumentationNodeModuleDefinition<typeof AWS>(

0 commit comments

Comments
 (0)