Skip to content

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

@gaprl

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.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions