Closed
Description
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:
▲ [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)
Additional Details
OpenTelemetry Setup Code
No response
package.json
"dependencies": {
"@opentelemetry/api": "^1.8.0",
"@opentelemetry/exporter-metrics-otlp-proto": "^0.51.1",
"@opentelemetry/exporter-trace-otlp-proto": "^0.51.1",
"@opentelemetry/instrumentation": "^0.51.1",
"@opentelemetry/instrumentation-aws-sdk": "^0.41.0",
"@opentelemetry/instrumentation-pg": "^0.41.0",
"@opentelemetry/instrumentation-pino": "^0.39.0",
"@opentelemetry/resources": "^1.24.1",
"@opentelemetry/sdk-trace-base": "^1.24.1",
"@opentelemetry/sdk-trace-node": "^1.24.1",
"@opentelemetry/semantic-conventions": "^1.24.1"
}
Relevant log output
No response