Skip to content

Commit

Permalink
feat(core): add mongo start instruments
Browse files Browse the repository at this point in the history
  • Loading branch information
adriencaccia committed Jan 12, 2024
1 parent 5d4ecd7 commit e0fa17e
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ export const teardownCore = () => {
linuxPerf.stop();
};

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

export type { StartInstrumentsRequestBody };

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

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

public async start(uri: string) {
if (this.tracerClient !== undefined) {
await this.tracerClient.instrumentation.start({
Expand Down
59 changes: 58 additions & 1 deletion 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.0"
"version": "0.1.1-beta.4"
},
"paths": {
"/benchmark/start": {
Expand Down Expand Up @@ -74,6 +74,40 @@
}
}
},
"/instruments/start": {
"post": {
"tags": ["instruments"],
"operationId": "start",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/StartInstrumentsRequestBody"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "successful operation",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/StartInstrumentsResponse"
}
}
}
},
"4XX": {
"$ref": "#/components/responses/Error"
},
"5XX": {
"$ref": "#/components/responses/Error"
}
}
}
},
"/status": {
"get": {
"tags": ["instrumentation"],
Expand Down Expand Up @@ -249,12 +283,35 @@
"query_documents",
"response_documents"
]
},
"StartInstrumentsRequestBody": {
"type": "object",
"properties": {
"mongoUrl": {
"description": "The full `MONGO_URL` that is usually used to connect to the database.",
"type": "string"
}
},
"required": ["mongoUrl"]
},
"StartInstrumentsResponse": {
"type": "object",
"properties": {
"remoteAddr": {
"description": "The patched `MONGO_URL` that should be used to connect to the database.",
"type": "string"
}
},
"required": ["remoteAddr"]
}
}
},
"tags": [
{
"name": "instrumentation"
},
{
"name": "instruments"
}
]
}

0 comments on commit e0fa17e

Please sign in to comment.