Skip to content

Commit

Permalink
feat(tinybench-plugin): add dynamic startInstruments function
Browse files Browse the repository at this point in the history
  • Loading branch information
adriencaccia committed Jan 12, 2024
1 parent e0fa17e commit 676473d
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/tinybench-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
mongoMeasurement,
optimizeFunction,
setupCore,
StartInstrumentsRequestBody,
StartInstrumentsResponse,
teardownCore,
tryIntrospect,
} from "@codspeed/core";
Expand Down Expand Up @@ -101,3 +103,18 @@ function getCallingFile(): string {
}
return path.relative(gitDir, callingFile);
}

/**
* Dynamically starts the CodSpeed instruments.
*/
export async function startInstruments(
body: StartInstrumentsRequestBody
): Promise<StartInstrumentsResponse> {
if (!Measurement.isInstrumented()) {
console.warn("[CodSpeed] No instrumentation found, using default mongoUrl");

return { remoteAddr: body.mongoUrl };
}

return await mongoMeasurement.startInstruments(body);
}

0 comments on commit 676473d

Please sign in to comment.