Error Monitoring in Next.jsSentry in Production, Alerts, and PII Scrubbing (2026)

sentry6 min readJuly 20, 2026

Author: DevStudio.it

TL;DR

Sentry in Next.js 15 is not just console.error in the cloud — it is one dashboard for client errors, Server Actions, route handlers, and middleware. In production you configure DSN per environment, release tracking tied to deploys on DevStudioIT Cloud, Slack alerts on 500 spikes, and PII scrubbing before form email hits logs. Without error monitoring the client sees "something went wrong" when submitting a lead — you find out three days later from support. Below: full @sentry/nextjs setup, beforeSend rules, and CI pipeline integration.

Who is this for

  • Next.js teams with contact forms and Server Actions — a 500 error means a lost lead
  • B2B companies on DevStudioIT Cloud without a dedicated SRE — Sentry is the first line of defense
  • Developers implementing GDPR — you need to know what Sentry collects from form payloads
  • Projects with CRM integration (n8n) — webhook failures must be visible immediately
  • Anyone with "works on my localhost" and zero visibility after deploy

Keyword

sentry nextjs production, next.js error monitoring, sentry server actions, pii scrubbing sentry, slack alerts sentry, error tracking app router 2026

Why console.log is not enough in production

In development a Server Action error shows a stack trace in the terminal. In production Next.js hides details from the user — correctly, but without Sentry you cannot see them either. Typical scenarios:

Scenario Without Sentry With Sentry
PostgreSQL timeout in Branchly Silent 500, lead lost Alert + stack + query context
Zod validation error in Server Action User sees generic message You see exact field and payload (after scrub)
Hydration mismatch on /en Hard to reproduce Breadcrumbs + session replay (optional)
Error spike after deploy You learn from support Alert in 2 min, rollback decision

Error monitoring is part of maintenance SLA — not a luxury for large SaaS only.

Installing Sentry in Next.js App Router

The official wizard @sentry/wizard@latest -i nextjs generates config files. Minimal structure:

npx @sentry/wizard@latest -i nextjs

Key files:

File Role
sentry.client.config.ts Browser errors, hydration
sentry.server.config.ts Server Components, route handlers
sentry.edge.config.ts Middleware, edge routes
instrumentation.ts Next.js init hook

In next.config.ts the withSentryConfig wrapper uploads source maps on build — CI only, not locally with production keys.

Production config — DSN, environments, sampling

// sentry.server.config.ts
import * as Sentry from '@sentry/nextjs';

Sentry.init({
  dsn: process.env.SENTRY_DSN,
  environment: process.env.SENTRY_ENVIRONMENT ?? 'production',
  release: process.env.SENTRY_RELEASE,
  tracesSampleRate: 0.1,
  profilesSampleRate: 0.1,
  beforeSend(event) {
    return scrubPii(event);
  },
});
Env variable (DevStudioIT Cloud) Value
SENTRY_DSN Sentry project DSN
SENTRY_ENVIRONMENT production / staging
SENTRY_RELEASE git sha from CI — e.g. abc1234
SENTRY_AUTH_TOKEN CI only — source map upload

Use staging on a separate Sentry project or same project with environment: staging — do not mix test errors with production.

PII scrubbing — forms, GDPR, beforeSend

A contact form sends email, phone, message body. A Server Action may log payload to Sentry on validation failure — you must scrub it:

function scrubPii(event: Sentry.Event): Sentry.Event | null {
  if (event.request?.data) {
    const data = typeof event.request.data === 'string'
      ? JSON.parse(event.request.data)
      : event.request.data;

    delete data.email;
    delete data.phone;
    delete data.message;
    event.request.data = JSON.stringify(data);
  }

  event.user = event.user ? { id: event.user.id } : undefined;
  return event;
}

Also in Sentry panel: Settings → Security & Privacy → Data Scrubbing — enable default rules for email, credit card, IP (optionally hash IP instead of removing — less useful for geo debugging).

Data In Sentry Recommendation
Lead email ❌ never Scrub in beforeSend
User ID (session) ✅ hash Identification without PII
Stack trace Core value
Request URL No query with tokens
Cookies sendDefaultPii: false

Alerts — Slack, spike detection, post-deploy regressions

In Sentry Alerts → Create Alert:

  1. New issue — first occurrence of unknown error → Slack #dev-alerts
  2. Spike — >10 events/min of same issue → PagerDuty or SMS on-call
  3. Regression — resolved issue returns after deploy → link to release in Sentry

Tie release to deploy on DevStudioIT Cloud:

# GitHub Actions fragment
- name: Set Sentry release
  run: |
    export SENTRY_RELEASE="${{ github.sha }}"
    npx @sentry/cli releases new "$SENTRY_RELEASE"
    npx @sentry/cli releases finalize "$SENTRY_RELEASE"

After deploy you see which commit introduced the regression — no guessing among five PRs from this week.

Server Actions and route handlers — error context

Server Action saving to PostgreSQL in Branchly:

'use server';

import * as Sentry from '@sentry/nextjs';

export async function submitContact(formData: FormData) {
  return Sentry.withServerActionInstrumentation(
    'submitContact',
    { recordResponse: false },
    async () => {
      const parsed = contactSchema.safeParse(Object.fromEntries(formData));
      if (!parsed.success) {
        Sentry.captureMessage('Contact validation failed', 'warning');
        return { ok: false, errors: parsed.error.flatten() };
      }
      // save to Branchly / n8n webhook
    }
  );
}

recordResponse: false — do not send responses with personal data to Sentry. For API route handlers use Sentry.captureException(error, { tags: { route: '/api/webhook' } }).

Performance vs cost — sampling and limits

Sentry Performance (traces) costs more than error tracking alone. For a corporate site:

Type Sample rate Rationale
Errors 100% Every 500 counts
Transactions 10% Enough for backend LCP trends
Profiling 5–10% Only when debugging slow Server Actions

On staging set tracesSampleRate: 1.0 — full visibility without production cost.

Release health — dashboard after deploy

In Sentry Releases compare crash-free sessions between versions:

Metric Target Action on regression
Crash-free rate > 99.5% Rollback on DevStudioIT Cloud
New issues 1 h after deploy 0 critical Hotfix or revert
P95 transaction duration ±10% vs previous release Profile Server Action

Deploy → release link requires one variable SENTRY_RELEASE=${GITHUB_SHA} in pipeline — without it Sentry groups errors in "unknown release" and regression alerts lose meaning.

FAQ

Does Sentry replace server logs on DevStudioIT Cloud?

No — Sentry is errors and performance traces. Stdout logs (requests, startup) stay in the hosting panel. Use both: Sentry for exceptions, logs for audit and infrastructure debugging.

Session Replay — enable on pages with forms?

Carefully. Replay records the DOM — it may capture typed email before form submit. Disable on /contact or use maskAllText: true and blocklist form selectors.

Self-hosted Sentry vs SaaS?

For most DevStudio clients Sentry SaaS with EU region and PII scrubbing is enough. Self-hosted makes sense at thousands of events/min with dedicated DevOps — maintenance cost grows faster than license.

How to test integration before production?

Route /api/sentry-test behind env flag, called only on staging. Or Sentry.captureException(new Error('Staging test')) in deploy preview. Never leave test endpoint on production without auth.

Want error monitoring in your Next.js app?

Related posts

n8n — Form Automation: Webhook from Next.js → CRM → Slack (2026)
6 min read
Lead Scoring, Contact Forms, and Sales Pipeline — Next.js Integration (2026)
6 min read
Next.js 15 Server Actions vs Route Handlers — contact forms in 2026
10 min read

About the author

We build fast websites, web/mobile apps, AI chatbots and hosting setups — with a focus on SEO and conversion.

Recommended links

From theory to production — Branchly, our hosting stack and shipped work.

Like how we think? Let's build something together.

Start project configuration