From 5627854af11e7f77c6ca317eb3b26e00773a6674 Mon Sep 17 00:00:00 2001 From: Xevion Date: Thu, 23 Feb 2023 22:36:26 -0600 Subject: [PATCH] Add precise time-based series parameter for telemetry --- src/monitor.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/monitor.ts b/src/monitor.ts index 87f9b21..43200a8 100644 --- a/src/monitor.ts +++ b/src/monitor.ts @@ -54,7 +54,8 @@ function getDuration(start: Date, end: Date) { export default async function monitorAsync(execute: () => Promise): Promise { // Tell Cronitor that the job is running const start = new Date(); - await fetch(buildURL({state: "run"}).toString()); + const series = start.getTime().toString(); + await fetch(buildURL({state: "run", series}).toString()); console.log("Cronitor: Job started") // Execute the function, provide try/catch @@ -63,14 +64,14 @@ export default async function monitorAsync(execute: () => Promise): result = await execute(); } catch (error) { const duration = getDuration(start, new Date()); - await fetch(buildURL({state: "fail", message: error instanceof Error ? error.message : undefined, metric: {duration}}).toString()); + await fetch(buildURL({state: "fail", series, message: error instanceof Error ? error.message : undefined, metric: {duration}}).toString()); throw error; } // Tell Cronitor that the job is complete (success) console.log("Cronitor: Job completed") const duration = getDuration(start, new Date()); - await fetch(buildURL({state: "complete", metric: {duration}}).toString()); + await fetch(buildURL({state: "complete", series, metric: {duration}}).toString()); return result as T; } \ No newline at end of file