Skip to content

Commit 4b66b8f

Browse files
committed
feat(benchmark.js-plugin): add dynamic startInstruments function
1 parent 823cae5 commit 4b66b8f

File tree

1 file changed

+17
-0
lines changed
  • packages/benchmark.js-plugin/src

1 file changed

+17
-0
lines changed

packages/benchmark.js-plugin/src/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import {
44
optimizeFunction,
55
optimizeFunctionSync,
66
setupCore,
7+
SetupInstrumentsRequestBody,
8+
SetupInstrumentsResponse,
79
teardownCore,
810
tryIntrospect,
911
} from "@codspeed/core";
@@ -221,3 +223,18 @@ async function runBenchmarks({
221223
teardownCore();
222224
console.log(`[CodSpeed] Done running ${benches.length} benches.`);
223225
}
226+
227+
/**
228+
* Dynamically setup the CodSpeed instruments.
229+
*/
230+
export async function setupInstruments(
231+
body: SetupInstrumentsRequestBody
232+
): Promise<SetupInstrumentsResponse> {
233+
if (!Measurement.isInstrumented()) {
234+
console.warn("[CodSpeed] No instrumentation found, using default mongoUrl");
235+
236+
return { remoteAddr: body.mongoUrl };
237+
}
238+
239+
return await mongoMeasurement.setupInstruments(body);
240+
}

0 commit comments

Comments
 (0)