diff --git a/app/routines/routine.server.ts b/app/routines/routine.server.ts index c98658fc4..c075b1815 100644 --- a/app/routines/routine.server.ts +++ b/app/routines/routine.server.ts @@ -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`, + ); + }, + ); } }