SentryCron Decorator

Learn about Sentry's SentryCron decorator.

The @SentryCron decorator is available from version @sentry/nestjs 8.16.0 and up.

The NestJS SDK includes a @SentryCron decorator that can be used to augment the native NestJS @Cron decorator to send check-ins to Sentry before and after each cron job run.

To get started, import SentryCron from @sentry/nestjs and use it to decorate a cron job function in your NestJS application.

The @SentryCron decorator needs to be applied after the @Cron decorator, or else the instrumentation does not work.

Copied
import { Cron } from "@nestjs/schedule";
import { SentryCron, MonitorConfig } from "@sentry/nestjs";
import type { MonitorConfig } from "@sentry/types";

const monitorConfig: MonitorConfig = {
  schedule: {
    type: "crontab",
    value: "* * * * *",
  },
  checkinMargin: 2, // In minutes. Optional.
  maxRuntime: 10, // In minutes. Optional.
  timezone: "America/Los_Angeles", // Optional.
};

export class MyCronService {
  @Cron("* * * * *")
  @SentryCron("my-monitor-slug", monitorConfig)
  handleCron() {
    // Your cron job logic here
  }
}
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").