diff --git a/packages/vitest-plugin/src/index.ts b/packages/vitest-plugin/src/index.ts index 403f348..1fbdd5c 100644 --- a/packages/vitest-plugin/src/index.ts +++ b/packages/vitest-plugin/src/index.ts @@ -1,4 +1,10 @@ -import { getV8Flags, Measurement } from "@codspeed/core"; +import { + getV8Flags, + Measurement, + mongoMeasurement, + SetupInstrumentsRequestBody, + SetupInstrumentsResponse, +} from "@codspeed/core"; import { join } from "path"; import { Plugin } from "vite"; import { UserConfig } from "vitest/config"; @@ -45,3 +51,18 @@ export default function codspeedPlugin(): Plugin { }, }; } + +/** + * Dynamically setup the CodSpeed instruments. + */ +export async function setupInstruments( + body: SetupInstrumentsRequestBody +): Promise { + if (!Measurement.isInstrumented()) { + console.warn("[CodSpeed] No instrumentation found, using default mongoUrl"); + + return { remoteAddr: body.mongoUrl }; + } + + return await mongoMeasurement.setupInstruments(body); +}