Skip to content

Commit

Permalink
feat: update mongo-tracer and change startInstruments into setupInstr…
Browse files Browse the repository at this point in the history
…uments
  • Loading branch information
adriencaccia committed Jan 16, 2024
1 parent f5788e2 commit d8350cd
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export const teardownCore = () => {
};

export type {
StartInstrumentsRequestBody,
StartInstrumentsResponse,
SetupInstrumentsRequestBody,
SetupInstrumentsResponse,
} from "./generated/openapi";
export { getV8Flags, tryIntrospect } from "./introspection";
export { optimizeFunction, optimizeFunctionSync } from "./optimization";
Expand Down
14 changes: 7 additions & 7 deletions packages/core/src/mongoMeasurement.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {
MongoTracer,
StartInstrumentsRequestBody,
StartInstrumentsResponse,
SetupInstrumentsRequestBody,
SetupInstrumentsResponse,
} from "./generated/openapi";

export type { StartInstrumentsRequestBody };
export type { SetupInstrumentsRequestBody };

export class MongoMeasurement {
private tracerClient: MongoTracer | undefined;
Expand All @@ -19,13 +19,13 @@ export class MongoMeasurement {
}
}

public async startInstruments(
body: StartInstrumentsRequestBody
): Promise<StartInstrumentsResponse> {
public async setupInstruments(
body: SetupInstrumentsRequestBody
): Promise<SetupInstrumentsResponse> {
if (this.tracerClient === undefined) {
throw new Error("MongoDB Instrumentation is not enabled");
}
return await this.tracerClient.instruments.start(body);
return await this.tracerClient.instruments.setup(body);
}

public async start(uri: string) {
Expand Down
16 changes: 9 additions & 7 deletions packages/core/tracer.spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"info": {
"title": "CodSpeed MongoDB Tracer",
"description": "Instrumentation API for CodSpeed Tracer",
"version": "0.1.1-beta.4"
"version": "0.1.4-beta.8"
},
"paths": {
"/benchmark/start": {
Expand Down Expand Up @@ -74,15 +74,17 @@
}
}
},
"/instruments/start": {
"/instruments/setup": {
"post": {
"tags": ["instruments"],
"operationId": "start",
"summary": "Start the instruments (proxy and aggregator) for the given `body.mongo_url`.",
"description": "If other endpoints of the instrumentation server are called before this one, they will likely fail as the proxy and aggregator are not running yet.",
"operationId": "setup",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/StartInstrumentsRequestBody"
"$ref": "#/components/schemas/SetupInstrumentsRequestBody"
}
}
},
Expand All @@ -94,7 +96,7 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/StartInstrumentsResponse"
"$ref": "#/components/schemas/SetupInstrumentsResponse"
}
}
}
Expand Down Expand Up @@ -284,7 +286,7 @@
"response_documents"
]
},
"StartInstrumentsRequestBody": {
"SetupInstrumentsRequestBody": {
"type": "object",
"properties": {
"mongoUrl": {
Expand All @@ -294,7 +296,7 @@
},
"required": ["mongoUrl"]
},
"StartInstrumentsResponse": {
"SetupInstrumentsResponse": {
"type": "object",
"properties": {
"remoteAddr": {
Expand Down
14 changes: 7 additions & 7 deletions packages/tinybench-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
mongoMeasurement,
optimizeFunction,
setupCore,
StartInstrumentsRequestBody,
StartInstrumentsResponse,
SetupInstrumentsRequestBody,
SetupInstrumentsResponse,
teardownCore,
tryIntrospect,
} from "@codspeed/core";
Expand Down Expand Up @@ -105,16 +105,16 @@ function getCallingFile(): string {
}

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

return { remoteAddr: body.mongoUrl };
}

return await mongoMeasurement.startInstruments(body);
return await mongoMeasurement.setupInstruments(body);
}

0 comments on commit d8350cd

Please sign in to comment.