Skip to content

Commit 676473d

Browse files
committed
feat(tinybench-plugin): add dynamic startInstruments function
1 parent e0fa17e commit 676473d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

packages/tinybench-plugin/src/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import {
44
mongoMeasurement,
55
optimizeFunction,
66
setupCore,
7+
StartInstrumentsRequestBody,
8+
StartInstrumentsResponse,
79
teardownCore,
810
tryIntrospect,
911
} from "@codspeed/core";
@@ -101,3 +103,18 @@ function getCallingFile(): string {
101103
}
102104
return path.relative(gitDir, callingFile);
103105
}
106+
107+
/**
108+
* Dynamically starts the CodSpeed instruments.
109+
*/
110+
export async function startInstruments(
111+
body: StartInstrumentsRequestBody
112+
): Promise<StartInstrumentsResponse> {
113+
if (!Measurement.isInstrumented()) {
114+
console.warn("[CodSpeed] No instrumentation found, using default mongoUrl");
115+
116+
return { remoteAddr: body.mongoUrl };
117+
}
118+
119+
return await mongoMeasurement.startInstruments(body);
120+
}

0 commit comments

Comments
 (0)