diff --git a/includes/nestjs-sentry-cron-decorator.mdx b/includes/nestjs-sentry-cron-decorator.mdx index 1c678107a0de9..87e221574ce2a 100644 --- a/includes/nestjs-sentry-cron-decorator.mdx +++ b/includes/nestjs-sentry-cron-decorator.mdx @@ -1,3 +1,29 @@ +### Monitor All `@Cron` Methods + + + +We recommend enabling `monitorCronJobs` on the Nest integration, which monitors every `@Cron` method without adding `@SentryCron` to each one: + +```typescript {filename:instrument.ts} +import * as Sentry from "@sentry/nestjs"; + +Sentry.init({ + dsn: "___PUBLIC_DSN___", + integrations: [ + Sentry.nestIntegration({ + monitorCronJobs: true, + excludeCronJobs: ["cleanup-temp-files", /^Debug/], // Optional. + }), + ], +}); +``` + +The monitor slug is the `name` option of `@Cron`, or `ClassName.methodName` if there's no `name`. Set a `name` if your build minifies class names, so the slug doesn't change between deploys. `excludeCronJobs` skips jobs whose slug matches a string exactly or a regular expression. + +Each check-in sends the schedule and time zone of `@Cron`, as described in [Monitor Config From `@Cron`](#monitor-config-from-cron). Schedules that can't be expressed in the Crons schedule format (for example, a job that runs every 10 seconds) check in without a monitor config, so create those monitors in Sentry first. `@Cron` with a `Date` runs once and isn't monitored. + +### Monitor Specific Methods + 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. @@ -29,8 +55,9 @@ export class MyCronService { } ``` +`monitorCronJobs` skips methods that have `@SentryCron`, so they check in once, with the slug and options you pass to `@SentryCron`. -### Monitor Config From `@Cron` +#### Monitor Config From `@Cron`