Skip to content

Crons check-ins are not flushed when run by Vercel Crons #17136

Closed

Description

@gaprl

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nextjs

SDK Version

9.40.0

Framework Version

Next 15.4.3

Link to Sentry event

https://gabriel-lopes-organization.sentry.io/issues/alerts/rules/crons/flutter/sync-orders/details/

Reproduction Example/SDK Setup

The following Vercel Cron route src/app/api/cron/route.ts does not flush Crons check-ins, causing them to be marked as "missed".

import { NextRequest, NextResponse } from "next/server";
import * as Sentry from "@sentry/nextjs";

export const GET = async (req: NextRequest) => {
  const monitorSlug = "sync-orders";
  const checkInId = Sentry.captureCheckIn(
    {
      monitorSlug,
      status: "in_progress",
    },
    {
      schedule: {
        type: "crontab",
        value: "* * * * *",
      },
      checkinMargin: 1,
      maxRuntime: 15,
    }
  );

  try {
    Sentry.captureCheckIn({
      checkInId,
      monitorSlug: monitorSlug,
      status: "ok",
    });
  } catch (e) {
    Sentry.captureException(e);
    Sentry.captureCheckIn({
      checkInId,
      monitorSlug: monitorSlug,
      status: "error",
    });

    throw e;
  }

  return new NextResponse("OK", {
    status: 200,
  });
};

export const dynamic = "force-dynamic";
export const runtime = "nodejs";
export const maxDuration = 300;

Vercel.json:

{
    "crons": [
        {
            "path": "/api/cron",
            "schedule": "* * * * *"
        }
    ]
}

Adding a await Sentry.flush() before returning the response does the trick.

Steps to Reproduce

  1. Create a new Vercel cron route
  2. Instrument Crons
  3. Set up the Vercel cron job

Expected Result

The check-ins would be sent to Sentry and the monitor would have it's status as OK.

Actual Result

Check-ins are never sent and the monitor is in a failing state with missed check-ins.

Activity

  1. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Aug 5, 2025
  2. Lms24 commented on Aug 6, 2025

    @Lms24
    Member

    @chargome @RulaKhaled

    Likely, our wrapApiHandlerWithSentryVercelCrons wrapper needs to call flushIfSeverless after each capture call, WDYT? Related: Any reason we don't call captureException within this wrapper?

  3. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Aug 6, 2025
  4. chargome commented on Aug 6, 2025

    @chargome
    Member

    wrapApiHandlerWithSentryVercelCrons is only called for api routes in pages router, but issue is about route handlers in the app router (🫠 )

    I think #17223 should resolve this issue!

  5. chargome commented on Aug 6, 2025

    @chargome
    Member

    @gaprl I'll optimistically close this one for now as this should be fixed in the latest SDK version. Feel free to re-open otherwise!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions