Skip to content

Vercel Cron auto-instrumentation: add Turbopack + App Router support #21143

@jan10

Description

@jan10

Problem Statement

automaticVercelMonitors: true is documented as the one-line setup for Sentry Crons on Vercel: "Automatic Check-Ins (Vercel only)" in the Next.js Sentry cron docs. In practice, two stacking gaps make it useless for current Next.js projects.

  1. App Router route handlers are not instrumented. The cron docs include this line:

Automatic instrumentation of Vercel cron jobs currently only works for the Pages Router. App Router route handlers are not yet supported.

App Router has been the recommended pattern since Next.js 13.4 and is the default in create-next-app. Most cron routes added to new Next.js projects today live at app/api/cron//route.ts, none of which the feature can see.

  1. The flag is inert on Turbopack builds. Next.js 16 makes Turbopack the default production builder. The setting lives under webpack: in the Sentry config object:
withSentryConfig(config, {
  webpack: {
    automaticVercelMonitors: true,
  },
});

When the build runs on Turbopack, this branch is never executed, so no monitor metadata is emitted. The docs do not mention this restriction on the cron page.

Combined effect: a Vercel project on Next.js 16 with the documented defaults (App Router + Turbopack + Vercel Cron) gets zero auto-monitoring, even with the flag set correctly.

Solution Brainstorm

  1. Runtime auto-instrumentation for App Router cron routes. Read crons from vercel.json at SDK init, match each entry to its route handler by path, wrap the exported GET / POST with withMonitor(slug, () => handler(req), { schedule: { type: "crontab", value } }). This sidesteps the bundler entirely, so it works on Turbopack the same day it ships. The discovery surface is the file format Vercel already requires for crons to fire, so no new config is introduced.
  2. Turbopack parity for the existing build-time discovery. Port the webpack plugin's behavior to a Turbopack-compatible loader. Useful only after (1), since (1) covers both gaps; if (1) is shipped first, this becomes optional.
  3. Doc fix in the meantime. The cron page should call out both restrictions in the same callout, ideally above the automaticVercelMonitors snippet rather than buried in a later paragraph. Today the App Router restriction is mentioned once in a single sentence, and the Turbopack restriction is not on the cron page at all. Without runtime support, users adopt the feature, see no errors, assume it works, and discover the gap only when a real cron silently fails.
  4. Codemod or starter snippet. If runtime auto-instrumentation is far out, ship a small withCronMonitor(handler, monitorConfig) helper in @sentry/nextjs so the manual fallback is one import rather than four lines of boilerplate per route. Lowers the cost of the workaround until (1) lands.

Additional Context

  • @sentry/nextjs 10.53.1
  • next 16.x with Turbopack production build (next.config.js has cacheComponents enabled, which is App-Router-only)
  • Verified empty state in the Sentry Crons dashboard: no monitors were created for either schedule across multiple production deploys.

Docs page referenced: https://docs.sentry.io/platforms/javascript/guides/nextjs/crons/#automatic-check-ins-vercel-only

Priority

No response

Metadata

Metadata

Assignees

No one assigned
    No fields configured for issues without a type.

    Projects

    Status

    Waiting for: Product Owner

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions