Skip to content

Commit 84fca87

Browse files
committed
fix: removed support for experimental loader flag
1 parent 66f40a8 commit 84fca87

File tree

18 files changed

+126
-73
lines changed

18 files changed

+126
-73
lines changed

CONTRIBUTING.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -376,16 +376,9 @@ We have added the ESM support for all Node.js versions, Since version 20.6, [ESM
376376

377377
Use the following command to enable experimental ESM support:
378378

379-
- For Node.js versions greater than or equal to 18.19:
380-
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/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/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: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
'use strict';
77

88
const { isNodeJsTooOld, minimumNodeJsVersion } = require('@instana/core/src/util/nodeJsVersionCheck');
9+
const { hasEsmLoaderFile, hasExperimentalLoaderFlag } = require('@instana/core/src/util/esm');
910
const { isProcessAvailable } = require('@instana/core/src/util/moduleAvailable');
1011

1112
if (!isProcessAvailable()) {
@@ -34,6 +35,38 @@ 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 (hasExperimentalLoaderFlag()) {
41+
// eslint-disable-next-line no-console
42+
console.error(
43+
'Node.js introduced breaking changes in versions 18.19.0 and above, leading to the discontinuation of support ' +
44+
`for the --experimental-loader flag by Instana. The current Node.js version is ${process.version} and` +
45+
'this process will not be monitored by Instana. ' +
46+
"To ensure tracing by Instana, please use the '--import' flag instead. For more information, " +
47+
'refer to the Instana documentation: ' +
48+
'https://www.ibm.com/docs/en/instana-observability/current?topic=nodejs-collector-installation.'
49+
);
50+
module.exports.default = function noOp() {};
51+
// @ts-ignore TS1108
52+
return;
53+
}
54+
55+
// This loader worked with '--experimental-loader' in Node.js versions below 18.19.
56+
// TODO: Remove 'esm-loader.mjs' file and this log in the next major release (v6).
57+
if (hasEsmLoaderFile()) {
58+
// eslint-disable-next-line no-console
59+
console.error(
60+
"Detected use of 'esm-loader.mjs'. This file is no longer supported and will be removed in next major release. " +
61+
'This process will not be monitored by Instana. ' +
62+
"To ensure tracing by Instana, please use the 'esm-register.mjs' file instead. For more information, " +
63+
'refer to the Instana documentation: ' +
64+
'https://www.ibm.com/docs/en/instana-observability/current?topic=nodejs-collector-installation.'
65+
);
66+
module.exports.default = function noOp() {};
67+
// @ts-ignore TS1108
68+
return;
69+
}
3770
let isMainThread = true;
3871
try {
3972
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
}

packages/collector/test/tracing/misc/typescript/ts_esm/ts_esm_test.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,13 @@ const path = require('path');
99
const { execSync } = require('child_process');
1010
const config = require('../../../../../../core/test/config');
1111
const testUtils = require('../../../../../../core/test/test_util');
12-
const isLatestEsmSupportedVersion = require('../../../../../../core').util.esm.isLatestEsmSupportedVersion;
1312
const supportedVersion = require('../../../../../../core').tracing.supportedVersion;
1413
const ProcessControls = require('../../../../test_util/ProcessControls');
1514
const globalAgent = require('../../../../globalAgent');
1615

1716
const mochaSuiteFn = supportedVersion(process.versions.node) ? describe : describe.skip;
1817

19-
const loaderPath = isLatestEsmSupportedVersion(process.versions.node)
20-
? ['--import', path.join(__dirname, 'node_modules', '@instana', 'collector', 'esm-register.mjs')]
21-
: ['--experimental-loader', path.join(__dirname, 'node_modules', '@instana', 'collector', 'esm-loader.mjs')];
18+
const loaderPath = ['--import', path.join(__dirname, 'node_modules', '@instana', 'collector', 'esm-register.mjs')];
2219

2320
mochaSuiteFn('Typescript TS->ESM', function () {
2421
this.timeout(config.getTestTimeout() * 5);

packages/collector/test/tracing/sdk/multiple_installations/esm/test.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const config = require('@instana/core/test/config');
1515
const testUtils = require('@instana/core/test/test_util');
1616
const ProcessControls = require('../../../../test_util/ProcessControls');
1717
const globalAgent = require('../../../../globalAgent');
18-
const isLatestEsmSupportedVersion = require('@instana/core').util.esm.isLatestEsmSupportedVersion;
1918
const mochaSuiteFn = supportedVersion(process.versions.node) ? describe : describe.skip;
2019

2120
mochaSuiteFn('[ESM] tracing/sdk/multiple_installations', function () {
@@ -40,9 +39,7 @@ mochaSuiteFn('[ESM] tracing/sdk/multiple_installations', function () {
4039
let controls;
4140

4241
before(async () => {
43-
const nodeOptions = isLatestEsmSupportedVersion(process.versions.node)
44-
? '--import ./load-instana.mjs'
45-
: '--experimental-loader ./load-instana.mjs';
42+
const nodeOptions = '--import ./load-instana.mjs';
4643
controls = new ProcessControls({
4744
useGlobalAgent: true,
4845
cwd: path.join(__dirname, 'src'),

0 commit comments

Comments
 (0)