diff --git a/packages/tinybench-plugin/src/index.ts b/packages/tinybench-plugin/src/index.ts index adc308d..30032a9 100644 --- a/packages/tinybench-plugin/src/index.ts +++ b/packages/tinybench-plugin/src/index.ts @@ -4,6 +4,8 @@ import { mongoMeasurement, optimizeFunction, setupCore, + StartInstrumentsRequestBody, + StartInstrumentsResponse, teardownCore, tryIntrospect, } from "@codspeed/core"; @@ -101,3 +103,18 @@ function getCallingFile(): string { } return path.relative(gitDir, callingFile); } + +/** + * Dynamically starts the CodSpeed instruments. + */ +export async function startInstruments( + body: StartInstrumentsRequestBody +): Promise { + if (!Measurement.isInstrumented()) { + console.warn("[CodSpeed] No instrumentation found, using default mongoUrl"); + + return { remoteAddr: body.mongoUrl }; + } + + return await mongoMeasurement.startInstruments(body); +}