Skip to content

Commit e0fa17e

Browse files
committed
feat(core): add mongo start instruments
1 parent 5d4ecd7 commit e0fa17e

File tree

3 files changed

+78
-2
lines changed

3 files changed

+78
-2
lines changed

packages/core/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ export const teardownCore = () => {
2525
linuxPerf.stop();
2626
};
2727

28+
export type {
29+
StartInstrumentsRequestBody,
30+
StartInstrumentsResponse,
31+
} from "./generated/openapi";
2832
export { getV8Flags, tryIntrospect } from "./introspection";
2933
export { optimizeFunction, optimizeFunctionSync } from "./optimization";
3034
export * from "./utils";

packages/core/src/mongoMeasurement.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
import { MongoTracer } from "./generated/openapi";
1+
import {
2+
MongoTracer,
3+
StartInstrumentsRequestBody,
4+
StartInstrumentsResponse,
5+
} from "./generated/openapi";
6+
7+
export type { StartInstrumentsRequestBody };
28

39
export class MongoMeasurement {
410
private tracerClient: MongoTracer | undefined;
@@ -13,6 +19,15 @@ export class MongoMeasurement {
1319
}
1420
}
1521

22+
public async startInstruments(
23+
body: StartInstrumentsRequestBody
24+
): Promise<StartInstrumentsResponse> {
25+
if (this.tracerClient === undefined) {
26+
throw new Error("MongoDB Instrumentation is not enabled");
27+
}
28+
return await this.tracerClient.instruments.start(body);
29+
}
30+
1631
public async start(uri: string) {
1732
if (this.tracerClient !== undefined) {
1833
await this.tracerClient.instrumentation.start({

packages/core/tracer.spec.json

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"info": {
44
"title": "CodSpeed MongoDB Tracer",
55
"description": "Instrumentation API for CodSpeed Tracer",
6-
"version": "0.1.0"
6+
"version": "0.1.1-beta.4"
77
},
88
"paths": {
99
"/benchmark/start": {
@@ -74,6 +74,40 @@
7474
}
7575
}
7676
},
77+
"/instruments/start": {
78+
"post": {
79+
"tags": ["instruments"],
80+
"operationId": "start",
81+
"requestBody": {
82+
"content": {
83+
"application/json": {
84+
"schema": {
85+
"$ref": "#/components/schemas/StartInstrumentsRequestBody"
86+
}
87+
}
88+
},
89+
"required": true
90+
},
91+
"responses": {
92+
"200": {
93+
"description": "successful operation",
94+
"content": {
95+
"application/json": {
96+
"schema": {
97+
"$ref": "#/components/schemas/StartInstrumentsResponse"
98+
}
99+
}
100+
}
101+
},
102+
"4XX": {
103+
"$ref": "#/components/responses/Error"
104+
},
105+
"5XX": {
106+
"$ref": "#/components/responses/Error"
107+
}
108+
}
109+
}
110+
},
77111
"/status": {
78112
"get": {
79113
"tags": ["instrumentation"],
@@ -249,12 +283,35 @@
249283
"query_documents",
250284
"response_documents"
251285
]
286+
},
287+
"StartInstrumentsRequestBody": {
288+
"type": "object",
289+
"properties": {
290+
"mongoUrl": {
291+
"description": "The full `MONGO_URL` that is usually used to connect to the database.",
292+
"type": "string"
293+
}
294+
},
295+
"required": ["mongoUrl"]
296+
},
297+
"StartInstrumentsResponse": {
298+
"type": "object",
299+
"properties": {
300+
"remoteAddr": {
301+
"description": "The patched `MONGO_URL` that should be used to connect to the database.",
302+
"type": "string"
303+
}
304+
},
305+
"required": ["remoteAddr"]
252306
}
253307
}
254308
},
255309
"tags": [
256310
{
257311
"name": "instrumentation"
312+
},
313+
{
314+
"name": "instruments"
258315
}
259316
]
260317
}

0 commit comments

Comments
 (0)