Is there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/browser
SDK Version
7.51.2
Framework Version
Nest.js 9.3.9
Link to Sentry event
https://doubble.sentry.io/crons/sync-amplitude/?environment=production&project=4505119808946176
SDK Setup
Sentry.init({
integrations: [
new RewriteFrames({
root: global.__rootdir__,
}),
],
dsn: process.env.SENTRY_DSN,
serverName:
process.env.HOST_REGION || process.env.HOSTNAME
? `${process.env.HOST_REGION ? `${process.env.HOST_REGION}_` : ''}${process.env.HOSTNAME || 'unknown'}`
: undefined,
release: process.env.APP_VERSION,
environment: process.env.NODE_ENV, // XXX-production
shutdownTimeout: 10000,
});
Steps to Reproduce
Basically I follow the documentation:
this.monitorCheckInId = Sentry.captureCheckIn({
monitorSlug: this.monitorSlug,
status: status as any,
...(this.monitorCheckInId && {
checkInId: this.monitorCheckInId,
}),
});
If I inspect the crons running I see:
[Nest] 1 - 05/11/2023, 9:15:30 AM LOG [CRON] Will check in with Sentry: in_progress for slug YYYYY...
[Nest] 1 - 05/11/2023, 9:15:30 AM LOG [CRON] Refreshing XXXX view...
[Nest] 1 - 05/11/2023, 9:18:19 AM LOG [CRON] Done
[Nest] 1 - 05/11/2023, 9:18:19 AM LOG [CRON] Will check in with Sentry: ok for slug YYYYY (b3eb88439b864bb8b72ee6d358195789)...
Heres an example of what I did before, and how I refactored the code to use the built-in feature:
enum SentryJobStatus {
JobStarted = 'in_progress',
@@ -128,7 +126,9 @@ export abstract class BaseCommand extends CommandRunner {
public async notifyJobCompleted(): Promise<void> {
await this.jobCheckin(SentryJobStatus.JobCompleted);
- Sentry.setContext('completed-job', {});
+ Sentry.configureScope((scope) => {
+ scope.setContext('completed-job', {});
+ });
}
private async jobCheckin(status: SentryJobStatus, isRunning = true) {
@@ -142,43 +142,30 @@ export abstract class BaseCommand extends CommandRunner {
- Sentry.setContext('monitor', {
- slug: this.monitorSlug,
+ Sentry.configureScope((scope) => {
+ scope.setContext('monitor', {
+ slug: this.monitorSlug,
+ });
});
- const endpointUrl = `https://sentry.io/api/0/organizations/XXXX/monitors/${this.monitorSlug}/checkins${
- isRunning ? `/${this.monitorCheckInId ? this.monitorCheckInId : `/latest`}` : ''
- }/`;
-
- this.log(`Will check in with Sentry: ${status}...`);
- await fetch(endpointUrl, {
- method: !isRunning ? 'POST' : 'PUT',
- headers: {
- Authorization: `DSN ${dsn}`,
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({ status }),
- })
- .then(async (response) => {
- if (!response.ok) {
- return response.text().then((body) => {
- throw new Error(`Request failed with status ${response.status}: ${body}`);
- });
- }
- return response.json();
- })
- .then((data) => {
- this.log(`Checked in with Sentry: ${data.id}`);
- this.monitorCheckInId = data.id;
- })
- .catch((error) => {
- this.error(`Job monitoring HTTP error. Status: ${error}`);
- });
+ this.log(
+ `Will check in with Sentry: ${status} for slug ${this.monitorSlug}${
+ this.monitorCheckInId ? ` (${this.monitorCheckInId})` : ''
+ }...`,
+ );
+
+ this.monitorCheckInId = Sentry.captureCheckIn({
+ monitorSlug: this.monitorSlug,
+ status: status as any,
+ ...(isRunning && {
+ checkInId: this.monitorCheckInId,
+ }),
+ });
}
Expected Result
It should report OK in the Cron status console, because they are all running as expected
Actual Result
They all report "MISSED"

It worked fine when we weren't using the Sentry SDK but just sending normal http requests.
Is there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/browser
SDK Version
7.51.2
Framework Version
Nest.js 9.3.9
Link to Sentry event
https://doubble.sentry.io/crons/sync-amplitude/?environment=production&project=4505119808946176
SDK Setup
Steps to Reproduce
Basically I follow the documentation:
If I inspect the crons running I see:
Heres an example of what I did before, and how I refactored the code to use the built-in feature:
enum SentryJobStatus { JobStarted = 'in_progress', @@ -128,7 +126,9 @@ export abstract class BaseCommand extends CommandRunner { public async notifyJobCompleted(): Promise<void> { await this.jobCheckin(SentryJobStatus.JobCompleted); - Sentry.setContext('completed-job', {}); + Sentry.configureScope((scope) => { + scope.setContext('completed-job', {}); + }); } private async jobCheckin(status: SentryJobStatus, isRunning = true) { @@ -142,43 +142,30 @@ export abstract class BaseCommand extends CommandRunner { - Sentry.setContext('monitor', { - slug: this.monitorSlug, + Sentry.configureScope((scope) => { + scope.setContext('monitor', { + slug: this.monitorSlug, + }); }); - const endpointUrl = `https://sentry.io/api/0/organizations/XXXX/monitors/${this.monitorSlug}/checkins${ - isRunning ? `/${this.monitorCheckInId ? this.monitorCheckInId : `/latest`}` : '' - }/`; - - this.log(`Will check in with Sentry: ${status}...`); - await fetch(endpointUrl, { - method: !isRunning ? 'POST' : 'PUT', - headers: { - Authorization: `DSN ${dsn}`, - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ status }), - }) - .then(async (response) => { - if (!response.ok) { - return response.text().then((body) => { - throw new Error(`Request failed with status ${response.status}: ${body}`); - }); - } - return response.json(); - }) - .then((data) => { - this.log(`Checked in with Sentry: ${data.id}`); - this.monitorCheckInId = data.id; - }) - .catch((error) => { - this.error(`Job monitoring HTTP error. Status: ${error}`); - }); + this.log( + `Will check in with Sentry: ${status} for slug ${this.monitorSlug}${ + this.monitorCheckInId ? ` (${this.monitorCheckInId})` : '' + }...`, + ); + + this.monitorCheckInId = Sentry.captureCheckIn({ + monitorSlug: this.monitorSlug, + status: status as any, + ...(isRunning && { + checkInId: this.monitorCheckInId, + }), + }); }Expected Result
It should report OK in the Cron status console, because they are all running as expected
Actual Result
They all report "MISSED"
It worked fine when we weren't using the Sentry SDK but just sending normal http requests.