You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Import from "@opentelemetry/instrumentation" and bundle using esbuild with format: 'esm'
Expected Result
The build should proceed without warning and not crash during runtime.
Actual Result
When AWS CDK builds with esbuild, the following warning is emitted:
▲ [WARNING] Constructing "ImportInTheMiddle" will crash at run-time because it's an import namespace object, not a constructor [call-import-namespace]
node_modules/@opentelemetry/instrumentation/build/esm/platform/node/instrumentation.js:286:30:
286 │ var esmHook = new ImportInTheMiddle([module_2.name], { internals: false }, hookFn);
╵ ~~~~~~~~~~~~~~~~~
Consider changing "ImportInTheMiddle" to a default import instead:
node_modules/@opentelemetry/instrumentation/build/esm/platform/node/instrumentation.js:48:7:
48 │ import * as ImportInTheMiddle from 'import-in-the-middle';
│ ~~~~~~~~~~~~~~~~~~~~~~
╵ ImportInTheMiddle
1 warning
Runtime, the application crashes with
2024-05-17T10:20:37.898Z undefined INFO [Dynatrace] Failed to import runtime script(Node.js: v20.12.0, Agent: 1.287.2.20240223-044013, Script: /tmp/dtIndex.mjs):
TypeError: ImportInTheMiddle is not a constructor
at _loop_1 (file:///var/task/index.mjs:x:x)
at InstrumentationBase4.enable (file:///var/task/index.mjs:x:x)
at new InstrumentationBase4 (file:///var/task/index.mjs:x:x)
at new _AwsInstrumentation (file:///var/task/index.mjs:x:x)
at file:///var/task/index.mjs:xx
at ModuleJob.run (node:internal/modules/esm/module_job:x:x)
at async ModuleLoader.import (node:internal/modules/esm/loader:x:x)
at async _tryAwaitImport (file:///tmp/dtIndex.mjs:x:x)
at async _tryRequire (file:///tmp/dtIndex.mjs:x:x)
at async _loadUserApp (file:///tmp/dtIndex.mjs:x:x)
`import-in-the-middle` has some ESM interop issues.
From
[here](open-telemetry/opentelemetry-js#4546 (comment)):
> Specifically, namespace imports are required by the ESM spec to be
objects. IITM's top-level export is not an object, but a callable
function
This causes
[issues](open-telemetry/opentelemetry-js#4717)
with some bundlers. Obviously bundled imports will not go through
`import-in-the-middle` but using it should not inhibit bundlers as iitm
can still hook build-in modules.
This adds a `Hook` named export and changes one cjs and esm test to
use that new export.
What happened?
Steps to Reproduce
Import from "@opentelemetry/instrumentation" and bundle using esbuild with
format: 'esm'
Expected Result
The build should proceed without warning and not crash during runtime.
Actual Result
When AWS CDK builds with esbuild, the following warning is emitted:
Runtime, the application crashes with
Additional Details
OpenTelemetry Setup Code
No response
package.json
Relevant log output
No response
The text was updated successfully, but these errors were encountered: