@@ -31,6 +31,7 @@ delete process.env.DD_INJECT_FORCE
3131function testInjectionScenarios ( arg , filename , esmWorks = false ) {
3232 if ( ! currentVersionIsSupported ) return
3333 const doTest = ( file , ...args ) => testFile ( file , ...args )
34+
3435 context ( 'preferring app-dir dd-trace' , ( ) => {
3536 context ( 'when dd-trace is not in the app dir' , ( ) => {
3637 const NODE_OPTIONS = `--no-warnings --${ arg } ${ path . join ( __dirname , '..' , filename ) } `
@@ -39,34 +40,45 @@ function testInjectionScenarios (arg, filename, esmWorks = false) {
3940 if ( currentVersionIsSupported ) {
4041 context ( 'without DD_INJECTION_ENABLED' , ( ) => {
4142 it ( 'should initialize the tracer' , ( ) => doTest ( 'init/trace.js' , 'true\n' , [ ] , 'manual' ) )
43+
4244 it ( 'should initialize instrumentation' , ( ) => doTest ( 'init/instrument.js' , 'true\n' , [ ] , 'manual' ) )
45+
4346 it ( `should ${ esmWorks ? '' : 'not ' } initialize ESM instrumentation` , ( ) =>
4447 doTest ( 'init/instrument.mjs' , `${ esmWorks } \n` , [ ] , 'manual' ) )
4548 } )
4649 }
50+
4751 context ( 'with DD_INJECTION_ENABLED' , ( ) => {
4852 useEnv ( { DD_INJECTION_ENABLED } )
4953
5054 it ( 'should not initialize the tracer' , ( ) => doTest ( 'init/trace.js' , 'false\n' , [ ] ) )
55+
5156 it ( 'should not initialize instrumentation' , ( ) => doTest ( 'init/instrument.js' , 'false\n' , [ ] ) )
57+
5258 it ( 'should not initialize ESM instrumentation' , ( ) => doTest ( 'init/instrument.mjs' , 'false\n' , [ ] ) )
5359 } )
5460 } )
61+
5562 context ( 'when dd-trace in the app dir' , ( ) => {
5663 const NODE_OPTIONS = `--no-warnings --${ arg } dd-trace/${ filename } `
5764 useEnv ( { NODE_OPTIONS } )
5865
5966 context ( 'without DD_INJECTION_ENABLED' , ( ) => {
6067 it ( 'should initialize the tracer' , ( ) => doTest ( 'init/trace.js' , 'true\n' , [ ] , 'manual' ) )
68+
6169 it ( 'should initialize instrumentation' , ( ) => doTest ( 'init/instrument.js' , 'true\n' , [ ] , 'manual' ) )
70+
6271 it ( `should ${ esmWorks ? '' : 'not ' } initialize ESM instrumentation` , ( ) =>
6372 doTest ( 'init/instrument.mjs' , `${ esmWorks } \n` , [ ] , 'manual' ) )
6473 } )
74+
6575 context ( 'with DD_INJECTION_ENABLED' , ( ) => {
6676 useEnv ( { DD_INJECTION_ENABLED , DD_TRACE_DEBUG } )
6777
6878 it ( 'should initialize the tracer' , ( ) => doTest ( 'init/trace.js' , 'true\n' , telemetryGood , 'ssi' ) )
79+
6980 it ( 'should initialize instrumentation' , ( ) => doTest ( 'init/instrument.js' , 'true\n' , telemetryGood , 'ssi' ) )
81+
7082 it ( `should ${ esmWorks ? '' : 'not ' } initialize ESM instrumentation` , ( ) =>
7183 doTest ( 'init/instrument.mjs' , `${ esmWorks } \n` , telemetryGood , 'ssi' ) )
7284 } )
@@ -91,15 +103,17 @@ function testRuntimeVersionChecks (arg, filename) {
91103 context ( 'when node version is less than engines field' , ( ) => {
92104 useEnv ( { NODE_OPTIONS } )
93105
94- it ( 'should not initialize the tracer' , ( ) =>
95- doTest ( 'false\n' , [ ] ) )
106+ it ( 'should not initialize the tracer' , ( ) => doTest ( 'false\n' , [ ] ) )
107+
96108 context ( 'with DD_INJECTION_ENABLED' , ( ) => {
97109 useEnv ( { DD_INJECTION_ENABLED } )
98110
99111 context ( 'without debug' , ( ) => {
100112 it ( 'should not initialize the tracer' , ( ) => doTest ( 'false\n' , telemetryAbort ) )
113+
101114 it ( 'should initialize the tracer, if DD_INJECT_FORCE' , ( ) => doTestForced ( 'true\n' , telemetryForced ) )
102115 } )
116+
103117 context ( 'with debug' , ( ) => {
104118 useEnv ( { DD_TRACE_DEBUG } )
105119
@@ -109,6 +123,7 @@ Found incompatible runtime Node.js ${process.versions.node}, Supported runtimes:
109123>=18.
110124false
111125` , telemetryAbort ) )
126+
112127 it ( 'should initialize the tracer, if DD_INJECT_FORCE' , ( ) =>
113128 doTestForced ( `Aborting application instrumentation due to incompatible_runtime.
114129Found incompatible runtime Node.js ${ process . versions . node } , Supported runtimes: Node.js \
@@ -125,19 +140,23 @@ true
125140 useEnv ( { NODE_OPTIONS } )
126141
127142 it ( 'should initialize the tracer, if no DD_INJECTION_ENABLED' , ( ) => doTest ( 'true\n' , [ ] , 'manual' ) )
143+
128144 context ( 'with DD_INJECTION_ENABLED' , ( ) => {
129145 useEnv ( { DD_INJECTION_ENABLED } )
130146
131147 context ( 'without debug' , ( ) => {
132148 it ( 'should initialize the tracer' , ( ) => doTest ( 'true\n' , telemetryGood , 'ssi' ) )
149+
133150 it ( 'should initialize the tracer, if DD_INJECT_FORCE' , ( ) =>
134151 doTestForced ( 'true\n' , telemetryGood , 'ssi' ) )
135152 } )
153+
136154 context ( 'with debug' , ( ) => {
137155 useEnv ( { DD_TRACE_DEBUG } )
138156
139157 it ( 'should initialize the tracer' , ( ) =>
140158 doTest ( 'Application instrumentation bootstrapping complete\ntrue\n' , telemetryGood , 'ssi' ) )
159+
141160 it ( 'should initialize the tracer, if DD_INJECT_FORCE' , ( ) =>
142161 doTestForced ( 'Application instrumentation bootstrapping complete\ntrue\n' , telemetryGood , 'ssi' ) )
143162 } )
@@ -183,6 +202,7 @@ if (semver.satisfies(process.versions.node, '>=14.13.1')) {
183202 process . versions . node !== '18.0.0' )
184203 testRuntimeVersionChecks ( 'loader' , 'initialize.mjs' )
185204 } )
205+
186206 if ( semver . satisfies ( process . versions . node , '>=20.6.0' ) ) {
187207 context ( 'as --import' , ( ) => {
188208 testInjectionScenarios ( 'import' , 'initialize.mjs' , true )
0 commit comments