Skip to content

Commit

Permalink
fix(instr-aws-sdk): @smithy/[email protected] change broke aws-s…
Browse files Browse the repository at this point in the history
…dk-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.
  • Loading branch information
trentm committed Jan 25, 2024
1 parent fce7d3b commit 9069a82
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions plugins/node/opentelemetry-instrumentation-aws-sdk/src/aws-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,18 +113,23 @@ export class AwsInstrumentation extends InstrumentationBase<any> {
]);

// patch for @smithy/middleware-stack for aws-sdk packages v3.363.0+
const v3SmithyMiddlewareStackFile = new InstrumentationNodeModuleFile(
'@smithy/middleware-stack/dist-cjs/MiddlewareStack.js',
['>=1.0.1'],
this.patchV3ConstructStack.bind(this),
this.unpatchV3ConstructStack.bind(this)
);
const self = this;
const v3SmithyMiddlewareStack = new InstrumentationNodeModuleDefinition(
'@smithy/middleware-stack',
['>=2.0.0'],
undefined,
undefined,
[v3SmithyMiddlewareStackFile]
(moduleExports, moduleVersion) => {
// XXX need full propwrap, i.e. any possible props other that `constructStack`
const newExports = {
get constructStack() {
return self._getV3ConstructStackPatch(
moduleVersion,
(moduleExports as any).constructStack
);
},
};
return newExports;
},
undefined // XXX Is no longer being able to unpatch an issue?
);

const v3SmithyClient = new InstrumentationNodeModuleDefinition<typeof AWS>(
Expand Down

0 comments on commit 9069a82

Please sign in to comment.