Skip to content

Commit 853d1e9

Browse files
authored
fix: removed support for experimental loader flag (#2153)
BREAKING CHANGE: - Removed support for --experimental-loader - Removed support for esm-loader.mjs Migration Recommendations: - Replace --experimental-loader with --import - Use esm-register.mjs instead of esm-loader.mjs e.g. --import /path/to/instana/node_modules/@instana/collector/esm-register.mjs
1 parent 0b41e6e commit 853d1e9

File tree

23 files changed

+249
-89
lines changed

23 files changed

+249
-89
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -374,18 +374,11 @@ REGIONS=<region> SKIP_DOCKER_IMAGE=true BUILD_LAYER_WITH=local LAYER_NAME=experi
374374

375375
We have added the ESM support for all Node.js versions, Since version 20.6, [ESM loaders are off-thread](https://github.com/nodejs/node/pull/44710), loaded separately, a shift from previous setups where the Instana collector was loaded within the loader, leading to a disruption in existing implementation. To resolve this, we've replaced the deprecated `--experimental-loader` with `--import`, facilitating the loading of the collector in the main thread. However, note that `--import` is only compatible with Node.js v18.19 and later, necessitating the maintenance of both styles for different Node.js versions.
376376

377-
Use the following command to enable experimental ESM support:
378-
379-
- For Node.js versions greater than or equal to 18.19:
377+
Use the following command to enable ESM support:
380378

381379
```sh
382380
node --import /path/to/instana/node_modules/@instana/collector/esm-register.mjs entry-point
383381
```
384-
- For Node.js versions less than 18.19:
385-
386-
```sh
387-
node --experimental-loader /path/to/instana/node_modules/@instana/collector/esm-loader.mjs entry-point
388-
```
389382

390383
## Node.js prerelease
391384

packages/aws-fargate/esm-loader.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
'use strict';
66

77
/**
8+
* IMPORTANT: This file is deprecated, no longer supported, and will be removed in the next major release (v6).
9+
*
810
* IMPORTANT NOTE: From Node.js version 18.19 and above, the ESM loaders operate off-thread.
911
* Consequently, ESM instrumentation using '--experimental-loader' becomes deprecated.
1012
* Instead, we are using '--import' for loading instrumentation and relocated the Instana collector

packages/aws-fargate/src/preactivate.js

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,45 @@
55

66
'use strict';
77

8-
const { isNodeJsTooOld, minimumNodeJsVersion } = require('@instana/core/src/util/nodeJsVersionCheck');
8+
const { esm, nodeJsVersionCheck } = require('@instana/core/src/util');
99

10-
if (isNodeJsTooOld()) {
10+
if (nodeJsVersionCheck.isNodeJsTooOld()) {
1111
// eslint-disable-next-line no-console
1212
console.error(
13-
`The package @instana/aws-fargate requires at least Node.js ${minimumNodeJsVersion} but this process is ` +
13+
// eslint-disable-next-line max-len
14+
`The package @instana/aws-fargate requires at least Node.js ${nodeJsVersionCheck.minimumNodeJsVersion} but this process is ` +
1415
`running on Node.js ${process.version}. This Fargate container will not be monitored by Instana.` +
1516
'See https://www.ibm.com/docs/en/instana-observability/current?topic=agents-aws-fargate#versioning.'
1617
);
1718
return;
1819
}
1920

21+
// Check for unsupported ESM loader configurations and exit early
22+
if (esm.hasExperimentalLoaderFlag()) {
23+
// eslint-disable-next-line no-console
24+
console.error(
25+
"Node.js 18.19.0 and later no longer support the '--experimental-loader' flag for ESM. " +
26+
`Your current version is ${process.version}. To ensure tracing by Instana, ` +
27+
"please use the '--import' flag instead. For more information, refer to the Instana documentation: " +
28+
'https://www.ibm.com/docs/en/instana-observability/current?topic=nodejs-collector-installation.'
29+
);
30+
return;
31+
}
32+
33+
// This loader worked with '--experimental-loader' in Node.js versions below 18.19.
34+
// TODO: Remove 'esm-loader.mjs' file and this log in the next major release (v6).
35+
if (esm.hasEsmLoaderFile()) {
36+
// eslint-disable-next-line no-console
37+
console.error(
38+
"Importing 'esm-loader.mjs' is not a valid command. " +
39+
'This process will not be monitored by Instana. ' +
40+
"Use 'esm-register.mjs' with '--import' to enable tracing. For more information, " +
41+
'refer to the Instana documentation: ' +
42+
'https://www.ibm.com/docs/en/instana-observability/current?topic=nodejs-collector-installation.'
43+
);
44+
return;
45+
}
46+
2047
const { util: coreUtil } = require('@instana/core');
2148
const { environment: environmentUtil, consoleLogger: serverlessLogger } = require('@instana/serverless');
2249

packages/aws-fargate/test/Control.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const config = require('@instana/core/test/config');
1313
const AbstractServerlessControl = require('../../serverless/test/util/AbstractServerlessControl');
1414
const portfinder = require('../../collector/test/test_util/portfinder');
1515
const PATH_TO_INSTANA_FARGATE_PACKAGE = path.join(__dirname, '..');
16-
const isLatestEsmSupportedVersion = require('@instana/core').util.esm.isLatestEsmSupportedVersion;
1716
let execArg;
1817

1918
function Control(opts) {
@@ -99,9 +98,7 @@ Control.prototype.startMonitoredProcess = function startMonitoredProcess() {
9998
env.INSTANA_AGENT_KEY = this.instanaAgentKey;
10099
}
101100

102-
const loaderPath = isLatestEsmSupportedVersion(process.versions.node)
103-
? ['--import', `${path.join(__dirname, '..', 'esm-register.mjs')}`]
104-
: [`--experimental-loader=${path.join(__dirname, '..', 'esm-loader.mjs')}`];
101+
const loaderPath = ['--import', `${path.join(__dirname, '..', 'esm-register.mjs')}`];
105102

106103
if (this.opts.containerAppPath && this.opts.env && this.opts.env.ESM_TEST) {
107104
if (this.opts.containerAppPath.endsWith('.mjs')) {

packages/azure-container-services/esm-loader.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
'use strict';
66

77
/**
8+
* IMPORTANT: This file is deprecated, no longer supported, and will be removed in the next major release (v6).
9+
*
810
* IMPORTANT NOTE: From Node.js version 18.19 and above, the ESM loaders operate off-thread.
911
* Consequently, ESM instrumentation using '--experimental-loader' becomes deprecated.
1012
* Instead, we are using '--import' for loading instrumentation and relocated the Instana collector

packages/azure-container-services/src/index.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,47 @@
44

55
'use strict';
66

7-
const { isNodeJsTooOld, minimumNodeJsVersion } = require('@instana/core/src/util/nodeJsVersionCheck');
7+
const { esm, nodeJsVersionCheck } = require('@instana/core/src/util');
88

99
// As of now, Azure App Service supports Node.js versions 16-lts,18-lts and 20-lts. However, for existing services,
1010
// older Node.js versions might still be supported. You can find more information about configuring Node.js on Azure
1111
// App Service at: https://learn.microsoft.com/en-us/azure/app-service/configure-language-nodejs?pivots=platform-linux
1212

13-
if (isNodeJsTooOld()) {
13+
if (nodeJsVersionCheck.isNodeJsTooOld()) {
1414
// eslint-disable-next-line no-console
1515
console.error(
16-
`The package @instana/azure-container-services requires at least Node.js ${minimumNodeJsVersion} but this` +
16+
// eslint-disable-next-line max-len
17+
`The package @instana/azure-container-services requires at least Node.js ${nodeJsVersionCheck.minimumNodeJsVersion} but this` +
1718
`process is running on Node.js ${process.version}. This azure container service will not be monitored by Instana.`
1819
);
1920
return;
2021
}
2122

23+
if (esm.hasExperimentalLoaderFlag()) {
24+
// eslint-disable-next-line no-console
25+
console.error(
26+
"Node.js 18.19.0 and later no longer support the '--experimental-loader' flag for ESM. " +
27+
`Your current version is ${process.version}. To ensure tracing by Instana, ` +
28+
"please use the '--import' flag instead. For more information, refer to the Instana documentation: " +
29+
'https://www.ibm.com/docs/en/instana-observability/current?topic=nodejs-collector-installation.'
30+
);
31+
return;
32+
}
33+
34+
// This loader worked with '--experimental-loader' in Node.js versions below 18.19.
35+
// TODO: Remove 'esm-loader.mjs' file and this log in the next major release (v6).
36+
if (esm.hasEsmLoaderFile()) {
37+
// eslint-disable-next-line no-console
38+
console.error(
39+
"Importing 'esm-loader.mjs' is not supported and will be removed in next major release. " +
40+
'This process will not be monitored by Instana. ' +
41+
"Use 'esm-register.mjs' with '--import' to enable tracing. For more information, " +
42+
'refer to the Instana documentation: ' +
43+
'https://www.ibm.com/docs/en/instana-observability/current?topic=nodejs-collector-installation.'
44+
);
45+
return;
46+
}
47+
2248
const { util: coreUtil } = require('@instana/core');
2349
const { environment: environmentUtil, consoleLogger: log } = require('@instana/serverless');
2450

packages/azure-container-services/test/Control.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const fetch = require('node-fetch-v2');
1010
const portfinder = require('@instana/collector/test/test_util/portfinder');
1111
const config = require('@instana/core/test/config');
1212
const AbstractServerlessControl = require('../../serverless/test/util/AbstractServerlessControl');
13-
const isLatestEsmSupportedVersion = require('@instana/core').util.esm.isLatestEsmSupportedVersion;
1413

1514
const PATH_TO_INSTANA_AZURE_PACKAGE = path.join(__dirname, '..');
1615
let execArg;
@@ -59,9 +58,7 @@ class Control extends AbstractServerlessControl {
5958
env.INSTANA_AGENT_KEY = this.instanaAgentKey;
6059
}
6160

62-
const loaderPath = isLatestEsmSupportedVersion(process.versions.node)
63-
? ['--import', `${path.join(__dirname, '..', 'esm-register.mjs')}`]
64-
: [`--experimental-loader=${path.join(__dirname, '..', 'esm-loader.mjs')}`];
61+
const loaderPath = ['--import', `${path.join(__dirname, '..', 'esm-register.mjs')}`];
6562

6663
if (this.opts.containerAppPath && this.opts.env && this.opts.env.ESM_TEST) {
6764
execArg = this.opts.containerAppPath.endsWith('.mjs') ? loaderPath : ['--require', PATH_TO_INSTANA_AZURE_PACKAGE];

packages/collector/esm-loader.mjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
'use strict';
66

77
/**
8+
* IMPORTANT: This file is deprecated, no longer supported, and will be removed in the next major release (v6).
9+
*
810
* IMPORTANT NOTE: From Node.js version 18.19 and above, the ESM loaders operate off-thread.
911
* Consequently, ESM instrumentation using '--experimental-loader' becomes deprecated.
1012
* Instead, we are using '--import' for loading instrumentation and relocated the Instana collector

packages/collector/src/index.js

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
'use strict';
77

8-
const { isNodeJsTooOld, minimumNodeJsVersion } = require('@instana/core/src/util/nodeJsVersionCheck');
8+
const { esm, nodeJsVersionCheck } = require('@instana/core/src/util');
99
const { isProcessAvailable } = require('@instana/core/src/util/moduleAvailable');
1010

1111
if (!isProcessAvailable()) {
@@ -20,10 +20,11 @@ if (!isProcessAvailable()) {
2020
return;
2121
}
2222

23-
if (isNodeJsTooOld()) {
23+
if (nodeJsVersionCheck.isNodeJsTooOld()) {
2424
// eslint-disable-next-line no-console
2525
console.error(
26-
`The package @instana/collector requires at least Node.js ${minimumNodeJsVersion} but this process is ` +
26+
// eslint-disable-next-line max-len
27+
`The package @instana/collector requires at least Node.js ${nodeJsVersionCheck.minimumNodeJsVersion} but this process is ` +
2728
`running on Node.js ${process.version}. This process will not be monitored by Instana.`
2829
);
2930

@@ -34,6 +35,36 @@ if (isNodeJsTooOld()) {
3435
return;
3536
}
3637

38+
// v18.19 and above usage of --experimental-loader flag no longer supported
39+
// TODO: Remove error log in the next major release(v6)
40+
if (esm.hasExperimentalLoaderFlag()) {
41+
// eslint-disable-next-line no-console
42+
console.error(
43+
"Node.js 18.19.0 and later no longer support the '--experimental-loader' flag for ESM. " +
44+
`Your current version is ${process.version}. To ensure tracing by Instana, ` +
45+
"please use the '--import' flag instead. For more information, refer to the Instana documentation: " +
46+
'https://www.ibm.com/docs/en/instana-observability/current?topic=nodejs-collector-installation.'
47+
);
48+
module.exports.default = function noOp() {};
49+
// @ts-ignore TS1108
50+
return;
51+
}
52+
53+
// This loader worked with '--experimental-loader' in Node.js versions below 18.19.
54+
// TODO: Remove 'esm-loader.mjs' file and this log in the next major release (v6).
55+
if (esm.hasEsmLoaderFile()) {
56+
// eslint-disable-next-line no-console
57+
console.error(
58+
"Importing 'esm-loader.mjs' is not supported and will be removed in next major release. " +
59+
'This process will not be monitored by Instana. ' +
60+
"Use 'esm-register.mjs' with '--import' to enable tracing. For more information, " +
61+
'refer to the Instana documentation: ' +
62+
'https://www.ibm.com/docs/en/instana-observability/current?topic=nodejs-collector-installation.'
63+
);
64+
module.exports.default = function noOp() {};
65+
// @ts-ignore TS1108
66+
return;
67+
}
3768
let isMainThread = true;
3869
try {
3970
isMainThread = require('worker_threads').isMainThread;

packages/collector/test/test_util/ProcessControls.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ const globalAgent = require('../globalAgent');
2020
const portFinder = require('./portfinder');
2121
const sslDir = path.join(__dirname, '..', 'apps', 'ssl');
2222
const cert = fs.readFileSync(path.join(sslDir, 'cert'));
23-
const isLatestEsmSupportedVersion = require('@instana/core').util.esm.isLatestEsmSupportedVersion;
2423

2524
class ProcessControls {
2625
/**
@@ -57,10 +56,7 @@ class ProcessControls {
5756
}
5857

5958
if (process.env.RUN_ESM && !opts.execArgv) {
60-
const resolveEsmLoader = () =>
61-
isLatestEsmSupportedVersion(process.versions.node)
62-
? [`--import=${path.join(__dirname, '..', '..', 'esm-register.mjs')}`]
63-
: [`--experimental-loader=${path.join(__dirname, '..', '..', 'esm-loader.mjs')}`];
59+
const esmLoader = [`--import=${path.join(__dirname, '..', '..', 'esm-register.mjs')}`];
6460

6561
try {
6662
// Custom appPath is provided, use that. here we check the exact file name for esm app
@@ -72,13 +68,13 @@ class ProcessControls {
7268
const esmApp = testUtils.checkESMApp({ appPath: updatedPath });
7369

7470
if (esmApp) {
75-
opts.execArgv = resolveEsmLoader();
71+
opts.execArgv = esmLoader;
7672
opts.appPath = updatedPath;
7773
}
7874
} else if (opts?.dirname) {
7975
const esmApp = testUtils.checkESMApp({ appPath: path.join(opts.dirname, 'app.mjs') });
8076
if (esmApp) {
81-
opts.execArgv = resolveEsmLoader();
77+
opts.execArgv = esmLoader;
8278
opts.appPath = path.join(opts.dirname, 'app.mjs');
8379
}
8480
}

0 commit comments

Comments
 (0)