diff --git a/docs/product/monitors-and-alerts/monitors/crons/getting-started/index.mdx b/docs/product/monitors-and-alerts/monitors/crons/getting-started/index.mdx index 6fed649bd8240..6d82517bcf7dc 100644 --- a/docs/product/monitors-and-alerts/monitors/crons/getting-started/index.mdx +++ b/docs/product/monitors-and-alerts/monitors/crons/getting-started/index.mdx @@ -21,6 +21,8 @@ To set up Sentry Crons, use the links below for supported SDKs or the Sentry CLI - [Go](/platforms/go/crons/) - [Java](/platforms/java/crons/) - [Spring Boot](/platforms/java/guides/spring-boot/crons/) +- [.NET](/platforms/dotnet/crons/) + - [Hangfire](/platforms/dotnet/crons/hangfire/) - [Ruby](/platforms/ruby/crons/) - [Elixir](/platforms/elixir/crons/) diff --git a/platform-includes/crons/setup/dotnet.mdx b/platform-includes/crons/setup/dotnet.mdx index 7f3b03b878d5a..5d89515795100 100644 --- a/platform-includes/crons/setup/dotnet.mdx +++ b/platform-includes/crons/setup/dotnet.mdx @@ -2,7 +2,33 @@ Check-in monitoring allows you to track a job's progress by completing two check-ins: one at the start of your job and another at the end of your job. This two-step process allows Sentry to notify you if your job didn't start when expected (missed) or if it exceeded its maximum runtime (failed). -Pass monitor options with the in-progress check-in so Sentry creates or updates the monitor from your code: +Wrap your job with `SentrySdk.WithMonitorAsync`. It sends an in-progress check-in with the monitor options, which creates or updates the monitor, then runs the job and sends an ok or error check-in with its duration: + +```csharp +await SentrySdk.WithMonitorAsync("", async () => +{ + // Execute your scheduled task here... +}, options => options.Interval("0 * * * *")); +``` + +If your job returns a `ValueTask` or `ValueTask`, pass `async () => await RunJobAsync()`. + +For synchronous jobs, use `SentrySdk.WithMonitor`: + +```csharp +SentrySdk.WithMonitor("", () => +{ + // Execute your scheduled task here... +}, options => options.Interval("0 * * * *")); +``` + +Exceptions thrown by the job are rethrown, and the job's return value is passed through. Each run gets its own trace, shared by its check-ins and any errors captured during the run, unless a transaction or span is already active. `SentrySdk.WithMonitor` and `SentrySdk.WithMonitorAsync` require a Sentry .NET SDK version newer than `6.12.1`. If the monitor already exists in Sentry, you can leave out the monitor options. + +See [Upserting Cron Monitors](#upserting-cron-monitors) for all configuration options. + +### Manual Check-Ins + +To send check-ins yourself, call `SentrySdk.CaptureCheckIn` at the start and end of your job. Pass monitor options with the in-progress check-in so Sentry creates or updates the monitor from your code: ```csharp // 🟡 Notify Sentry your job is running: