Log Routines as spans

This commit is contained in:
Kalle 2026-05-14 15:30:23 +03:00
parent 2a6c276431
commit a4ab792896

View File

@ -1,3 +1,4 @@
import * as Sentry from "@sentry/react-router";
import { logger } from "../utils/logger";
export class Routine {
@ -17,14 +18,25 @@ export class Routine {
async run() {
logger.info(`Running routine: ${this.name}`);
const startTime = performance.now();
try {
await this.func();
} catch (error) {
logger.error(`Error running routine ${this.name}: ${error}`);
return;
}
const endTime = performance.now();
logger.info(`Routine ${this.name} completed in ${endTime - startTime}ms`);
await Sentry.startSpan(
{
name: this.name,
op: "cron",
},
async () => {
const startTime = performance.now();
try {
await this.func();
} catch (error) {
logger.error(`Error running routine ${this.name}: ${error}`);
Sentry.captureException(error);
return;
}
const endTime = performance.now();
logger.info(
`Routine ${this.name} completed in ${endTime - startTime}ms`,
);
},
);
}
}