@@ -63,6 +63,23 @@ export interface BenchOptions {
6363 executablePath ?: string ;
6464}
6565
66+ let integrationInitialized = false ;
67+
68+ /**
69+ * Register the integration and environment with the instrumentation. This is
70+ * process-global, so it only needs to run once regardless of how many
71+ * benchmarks are defined.
72+ */
73+ function ensureIntegrationSetup ( ) : void {
74+ if ( integrationInitialized ) return ;
75+ integrationInitialized = true ;
76+
77+ InstrumentHooks . setIntegration ( "node-custom" , __VERSION__ ) ;
78+ InstrumentHooks . setEnvironment ( "nodejs" , "version" , process . versions . node ) ;
79+ InstrumentHooks . setEnvironment ( "nodejs" , "v8" , process . versions . v8 ) ;
80+ InstrumentHooks . writeEnvironment ( process . pid ) ;
81+ }
82+
6683function resolveRounds ( optionRounds : number | undefined ) : number {
6784 const envValue = process . env . CODSPEED_ROUNDS ;
6885 const raw = envValue ?? optionRounds ;
@@ -177,10 +194,7 @@ export async function bench(
177194 const rounds = resolveRounds ( options . rounds ) ;
178195 const uri = `${ getCallingFile ( 0 ) } ::${ name } ` ;
179196
180- InstrumentHooks . setIntegration ( "node-custom" , __VERSION__ ) ;
181- InstrumentHooks . setEnvironment ( "nodejs" , "version" , process . versions . node ) ;
182- InstrumentHooks . setEnvironment ( "nodejs" , "v8" , process . versions . v8 ) ;
183- InstrumentHooks . writeEnvironment ( process . pid ) ;
197+ ensureIntegrationSetup ( ) ;
184198
185199 InstrumentHooks . setExecutedBenchmark ( process . pid , uri ) ;
186200 InstrumentHooks . startBenchmark ( ) ;
0 commit comments