From e0fa17e802e7c4426782857070c99896bd5601f3 Mon Sep 17 00:00:00 2001 From: Adrien Cacciaguerra Date: Fri, 12 Jan 2024 14:04:29 +0100 Subject: [PATCH] feat(core): add mongo start instruments --- packages/core/src/index.ts | 4 ++ packages/core/src/mongoMeasurement.ts | 17 +++++++- packages/core/tracer.spec.json | 59 ++++++++++++++++++++++++++- 3 files changed, 78 insertions(+), 2 deletions(-) diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 2476e09..3025b8c 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -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"; diff --git a/packages/core/src/mongoMeasurement.ts b/packages/core/src/mongoMeasurement.ts index c800bda..4307b6e 100644 --- a/packages/core/src/mongoMeasurement.ts +++ b/packages/core/src/mongoMeasurement.ts @@ -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; @@ -13,6 +19,15 @@ export class MongoMeasurement { } } + public async startInstruments( + body: StartInstrumentsRequestBody + ): Promise { + 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({ diff --git a/packages/core/tracer.spec.json b/packages/core/tracer.spec.json index 5b0a931..5b582a7 100644 --- a/packages/core/tracer.spec.json +++ b/packages/core/tracer.spec.json @@ -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": { @@ -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"], @@ -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" } ] }