Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion includes/nestjs-sentry-cron-decorator.mdx
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
### Monitor All `@Cron` Methods

<AvailableSince version="11.9.0" />

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

<AvailableSince version="8.16.0" />

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.
Expand Down Expand Up @@ -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`

<AvailableSince version="11.5.0" />

Expand Down
Loading