Skip to content

Sentry.captureCheckIn not returning #8311

Closed
@hrueger

Description

@hrueger

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/sveltekit

SDK Version

^7.54.0

Framework Version

"@sveltejs/kit": "^1.20.1",

Link to Sentry event

No response

SDK Setup

Sentry.init({
    dsn: "[redacted]",
    tracesSampleRate: 1.0,
    debug: true,
});

Steps to Reproduce

I have a "cron" job running in my Sveltekit App using node-cron. I'd like to monitor it using Sentry's cron monitoring feature, but the Sentry.captureCheckIn seems to never return and completely blocks the execution of that function... Very strange.

Here's the Code I'm using:

let running = false;
function jobWrapper() {
    console.log("Cron job wrapper");
    if (running) {
        return;
    }
    console.log("Running cron job");
    const monitorSlug = "pending-payment-reminders-and-cancellation";
    const checkInId = Sentry.captureCheckIn({
        monitorSlug,
        status: "in_progress",
    });
    console.log("Captured check in");

    try {
        running = true;
        console.log("About to run cron job");
        checkPendingPaymentActions();
        console.log("Cron job finished");


        running = false;
        Sentry.captureCheckIn({
            monitorSlug,
            checkInId,
            status: "ok",
        });
        console.log("Captured check in");
    } catch (error) {
        running = false;
        Sentry.captureCheckIn({
            checkInId,
            status: "error",
            monitorSlug,
        });
        console.log("Captured check in with error");
        console.error(error);
    }
}

let initialized = false;
export function initializeCron() {
    if (initialized) {
        return;
    }
    console.log("Initializing cron jobs");
    initialized = true;

    // every 5 minutes
    console.log(cron.schedule("*/5 * * * *", jobWrapper))
    console.log("Scheduled cron job")
}

See below for logs

Expected Result

The cron status is reported as in_progress, then my checkPendingPaymentActions() is called and afterwards the status is updated to ok.

Actual Result

Logs:

Initializing Sentry...
Sentry Logger [log]: Integration installed: InboundFilters
Sentry Logger [log]: Integration installed: FunctionToString
Sentry Logger [log]: Integration installed: Console
Sentry Logger [log]: Integration installed: Http
Sentry Logger [log]: Integration installed: Undici
Sentry Logger [log]: Integration installed: OnUncaughtException
Sentry Logger [log]: Integration installed: OnUnhandledRejection
Sentry Logger [log]: Integration installed: ContextLines
Sentry Logger [log]: Integration installed: LocalVariables
Sentry Logger [log]: Integration installed: Context
Sentry Logger [log]: Integration installed: Modules
Sentry Logger [log]: Integration installed: RequestData
Sentry Logger [log]: Integration installed: LinkedErrors
Sentry Logger [log]: Integration installed: RewriteFrames
Initializing cron...
Initializing cron jobs
ScheduledTask [...]
Scheduled cron job
Listening on 0.0.0.0:3000
Cron job wrapper
Running cron job

And then nothing happens for 5 Minutes, after that, I get:

Cron job wrapper
Running cron job

It seems like Sentry.captureCheckIn never returns, otherwise Captured check in would be logged?

If I remove the Sentry.captureCheckIn calls, everything works perfectly.

By the way, "normal" Sentry transaction / performance data is delivered without any issue.

Any idea? Thanks in advance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Package: sveltekitIssues related to the Sentry SvelteKit SDK

    Type

    No type

    Projects

    Status

    Waiting for: Product Owner

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions