$npx -y skills add getsentry/sentry-for-ai --skill sentry-nextjs-sdkFull Sentry SDK setup for Next.js. Use when asked to "add Sentry to Next.js", "install @sentry/nextjs", or configure error monitoring, tracing, session replay, logging, profiling, AI monitoring, or crons for Next.js applications. Supports Next.js 13+ with App Router and Pages Rou
| 1 | > [All Skills](../../SKILL_TREE.md) > [SDK Setup](../sentry-sdk-setup/SKILL.md) > Next.js SDK |
| 2 | |
| 3 | # Sentry Next.js SDK |
| 4 | |
| 5 | Opinionated wizard that scans your Next.js project and guides you through complete Sentry setup across all three runtimes: browser, Node.js server, and Edge. |
| 6 | |
| 7 | ## Invoke This Skill When |
| 8 | |
| 9 | - User asks to "add Sentry to Next.js" or "set up Sentry" in a Next.js app |
| 10 | - User wants to install or configure `@sentry/nextjs` |
| 11 | - User wants error monitoring, tracing, session replay, logging, or profiling for Next.js |
| 12 | - User asks about `instrumentation.ts`, `withSentryConfig()`, or `global-error.tsx` |
| 13 | - User wants to capture server actions, server component errors, or edge runtime errors |
| 14 | |
| 15 | > **Note:** SDK versions and APIs below reflect current Sentry docs at time of writing (`@sentry/nextjs` ≥8.28.0). |
| 16 | > Always verify against [docs.sentry.io/platforms/javascript/guides/nextjs/](https://docs.sentry.io/platforms/javascript/guides/nextjs/) before implementing. |
| 17 | |
| 18 | --- |
| 19 | |
| 20 | ## Phase 1: Detect |
| 21 | |
| 22 | Run these commands to understand the project before making any recommendations: |
| 23 | |
| 24 | ```bash |
| 25 | # Detect Next.js version and existing Sentry |
| 26 | cat package.json | grep -E '"next"|"@sentry/' |
| 27 | |
| 28 | # Detect router type (App Router vs Pages Router) |
| 29 | ls src/app app src/pages pages 2>/dev/null |
| 30 | |
| 31 | # Check for existing Sentry config files |
| 32 | ls instrumentation.ts instrumentation-client.ts sentry.server.config.ts sentry.edge.config.ts 2>/dev/null |
| 33 | ls src/instrumentation.ts src/instrumentation-client.ts 2>/dev/null |
| 34 | |
| 35 | # Check next.config |
| 36 | ls next.config.ts next.config.js next.config.mjs 2>/dev/null |
| 37 | |
| 38 | # Check for existing error boundaries |
| 39 | find . -name "global-error.tsx" -o -name "_error.tsx" 2>/dev/null | grep -v node_modules |
| 40 | |
| 41 | # Check build tool |
| 42 | cat package.json | grep -E '"turbopack"|"webpack"' |
| 43 | |
| 44 | # Check for logging libraries |
| 45 | cat package.json | grep -E '"pino"|"winston"|"bunyan"' |
| 46 | |
| 47 | # Check for companion backend |
| 48 | ls ../backend ../server ../api 2>/dev/null |
| 49 | cat ../go.mod ../requirements.txt ../Gemfile 2>/dev/null | head -3 |
| 50 | ``` |
| 51 | |
| 52 | **What to determine:** |
| 53 | |
| 54 | | Question | Impact | |
| 55 | |----------|--------| |
| 56 | | Next.js version? | 13+ required; 15+ needed for Turbopack support | |
| 57 | | App Router or Pages Router? | Determines error boundary files needed (`global-error.tsx` vs `_error.tsx`) | |
| 58 | | `@sentry/nextjs` already present? | Skip install, go to feature config | |
| 59 | | Existing `instrumentation.ts`? | Merge Sentry into it rather than replace | |
| 60 | | Turbopack in use? | Tree-shaking in `withSentryConfig` is webpack-only | |
| 61 | | Logging library detected? | Recommend Sentry Logs integration | |
| 62 | | Backend directory found? | Trigger Phase 4 cross-link suggestion | |
| 63 | |
| 64 | --- |
| 65 | |
| 66 | ## Phase 2: Recommend |
| 67 | |
| 68 | Present a concrete recommendation based on what you found. Don't ask open-ended questions — lead with a proposal: |
| 69 | |
| 70 | **Recommended (core coverage):** |
| 71 | - ✅ **Error Monitoring** — always; captures server errors, client errors, server actions, and unhandled promise rejections |
| 72 | - ✅ **Tracing** — server-side request tracing + client-side navigation spans across all runtimes |
| 73 | - ✅ **Session Replay** — recommended for user-facing apps; records sessions around errors |
| 74 | |
| 75 | **Optional (enhanced observability):** |
| 76 | - ⚡ **Logging** — structured logs via `Sentry.logger.*`; recommend when `pino`/`winston` or log search is needed |
| 77 | - ⚡ **Profiling** — continuous profiling; requires `Document-Policy: js-profiling` header |
| 78 | - ⚡ **AI Monitoring** — OpenAI, Vercel AI SDK, Anthropic; recommend when AI/LLM calls detected |
| 79 | - ⚡ **Crons** — detect missed/failed scheduled jobs; recommend when cron patterns detected |
| 80 | - ⚡ **Metrics** — custom metrics via `Sentry.metrics.*`; recommend when custom KPIs or business metrics needed |
| 81 | |
| 82 | **Recommendation logic:** |
| 83 | |
| 84 | | Feature | Recommend when... | |
| 85 | |---------|------------------| |
| 86 | | Error Monitoring | **Always** — non-negotiable baseline | |
| 87 | | Tracing | **Always for Next.js** — server route tracing + client navigation are high-value | |
| 88 | | Session Replay | User-facing app, login flows, or checkout pages | |
| 89 | | Logging | App uses structured logging or needs log-to-trace correlation | |
| 90 | | Profiling | Performance-critical app; client sets `Document-Policy: js-profiling` | |
| 91 | | AI Monitoring | App makes OpenAI, Vercel AI SDK, or Anthropic calls | |
| 92 | | Crons | App has Vercel Cron jobs, scheduled API routes, or `node-cron` usage | |
| 93 | | Metrics | App needs custom counters, gauges, or histograms via `Sentry.metrics.*` | |
| 94 | |
| 95 | Propose: *"I recommend setting up Error Monitoring + Tracing + Session Replay. Want me to also add Logging or Profiling?"* |
| 96 | |
| 97 | --- |
| 98 | |
| 99 | ## Phase 3: Guide |
| 100 | |
| 101 | ### Option 1: Wizard (Recommended) |
| 102 | |
| 103 | > **You need to run this yourself** — |