From d49f1b24798673b51e39e91ca2b47e5f5b08c828 Mon Sep 17 00:00:00 2001 From: Naomi Carrigan Date: Tue, 7 Oct 2025 16:02:54 -0700 Subject: [PATCH] feat: include date in metrics for aggregations --- src/server/serve.ts | 48 +++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/src/server/serve.ts b/src/server/serve.ts index 2effa1e..20f2aae 100644 --- a/src/server/serve.ts +++ b/src/server/serve.ts @@ -87,26 +87,36 @@ export const instantiateServer = async(): Promise => { return; } const { application, name, value, metadata } = request.body; - await fetch(`https://telemetry.nhcarrigan.com/api/33kzMoHcYaaEyqCFsauKPhTvEtx/ingest/metrics/_json`, { - body: JSON.stringify([ { - // eslint-disable-next-line @typescript-eslint/naming-convention -- Needs to match API's structure. - __name__: "metrics", - // eslint-disable-next-line @typescript-eslint/naming-convention -- Needs to match API's structure. - __type__: "count", - app: application, - metadata: metadata ?? {}, - name: name, - timestamp: Date.now(), - value: value, - } ]), - headers: { - // eslint-disable-next-line @typescript-eslint/naming-convention -- Standard header. - "Authorization": `Basic ${process.env.TELEMETRY_TOKEN ?? ""}`, - // eslint-disable-next-line @typescript-eslint/naming-convention -- Standard header. - "Content-Type": "application/json", + await fetch( + `https://telemetry.nhcarrigan.com/api/33kzMoHcYaaEyqCFsauKPhTvEtx/ingest/metrics/_json`, + { + body: JSON.stringify([ + { + // eslint-disable-next-line @typescript-eslint/naming-convention -- Needs to match API's structure. + __name__: "metrics", + // eslint-disable-next-line @typescript-eslint/naming-convention -- Needs to match API's structure. + __type__: "count", + app: application, + date: new Date().toLocaleDateString("en-GB", { + day: "numeric", + month: "long", + year: "numeric", + }), + metadata: metadata ?? {}, + name: name, + timestamp: Date.now(), + value: value, + }, + ]), + headers: { + // eslint-disable-next-line @typescript-eslint/naming-convention -- Standard header. + "Authorization": `Basic ${process.env.TELEMETRY_TOKEN ?? ""}`, + // eslint-disable-next-line @typescript-eslint/naming-convention -- Standard header. + "Content-Type": "application/json", + }, + method: "POST", }, - method: "POST", - }); + ); } catch (error) { await errorHandler(error, "Metric Webhook"); await response.status(500).send({ success: false });