Execute common Sentry pitfalls and how to avoid them.
Use when troubleshooting Sentry issues, reviewing configurations,
or preventing common mistakes.
Trigger with phrases like "sentry mistakes", "sentry pitfalls",
"sentry common issues", "sentry anti-patterns".
Ten production-grade Sentry SDK anti-patterns that silently break error tracking, inflate costs, or leave teams blind to failures. Each pitfall includes the broken pattern, root cause, and production-ready fix.
Without environment, dev errors pollute prod dashboards. Alert rules fire on local noise. Issue counts are inflated.
// WRONG
Sentry.init({ dsn: process.env.SENTRY_DSN });
// RIGHT
Sentry.init({
dsn: process.env.SENTRY_DSN,
environment: process.env.NODE_ENV || 'development',
});
// For Vercel/Railway preview environments:
function getSentryEnvironment(): string {
if (process.env.VERCEL_ENV) return process.env.VERCEL_ENV;
if (process.env.RAILWAY_ENVIRONMENT) return process.env.RAILWAY_ENVIRONMENT;
return process.env.NODE_ENV || 'development';
}
Step 9: Pitfall 8 — Importing @sentry/node in Browser Bundle
@sentry/node depends on Node.js built-ins (http, fs). Browser import causes build failures, 100KB+ polyfill bloat, or runtime crashes.
// WRONG
import * as Sentry from '@sentry/node'; // In React/Vue/browser code
// RIGHT — platform-specific SDK
import * as Sentry from '@sentry/react'; // React
import * as Sentry from '@sentry/vue'; // Vue
import * as Sentry from '@sentry/nextjs'; // Next.js (client + server)
import * as Sentry from '@sentry/node'; // Server-only
import * as Sentry from '@sentry/aws-serverless'; // AWS Lambda
Step 10: Pitfall 9 — Ignoring 429 Too Many Requests
When quota is exceeded, Sentry returns 429 and the SDK silently drops events. You lose data during peak traffic — exactly when you need it most.
Prevention:
Enable Spike Protection in Sentry Organization Settings
Set per-key rate limits in Project Settings > Client Keys
// Client-side circuit breaker for resilience
let sentryBackoff = 0;
Sentry.init({
beforeSend(event) {
if (Date.now() < sentryBackoff) return null;
return event;
},
});
Step 11: Pitfall 10 — No Alert Rules Configured
Sentry collects errors but does not notify anyone by default. Without alerts, critical bugs go unnoticed for hours.
Three-tier alert structure:
Tier
Trigger
Channel
Immediate
New fatal/error issue in prod
PagerDuty
Urgent
Error rate > 100 events in 5 min
Slack #alerts
Awareness
Issue unresolved > 7 days
Email digest
Set up in Sentry UI: Alerts > Create Alert > Issue Alert (Tier 1) or Metric Alert (Tier 2). See monitoring pitfalls for API-based alert creation.
Step 12: Run the Full Audit Checklist
See audit script for a bash script that checks all 10 pitfalls in one pass.
Output
Audit report listing which of the 10 pitfalls were found
Code changes applied for each identified pitfall
Confirmation that beforeSend returns event on all paths
environment and release properly configured
Alert rules created or recommended (three tiers)
Error Handling
Pitfall
Symptom
Fix
Hardcoded DSN
Spam events from attackers
process.env.SENTRY_DSN or build-time injection
sampleRate: 1.0
10-50x cost overrun
tracesSampler with per-endpoint rates
No flush()
Zero events from Lambda/CLI
await Sentry.flush(2000) before exit
beforeSend drops all
Events silently vanish
Always end with return event
Release mismatch
Minified stack traces
Single SENTRY_RELEASE env var
Swallowed catch
Cascading undefined errors
Re-throw after capture
No environment
Dev noise in prod dashboard
environment: process.env.NODE_ENV
Wrong SDK import
Build failure or bloat
Platform-specific SDK package
Ignoring 429s
Data loss at peak traffic
Spike protection + circuit breaker
No alerts
Bugs accumulate unnoticed
Three-tier alert rules
Examples
Example 1: Full-stack audit of existing Sentry setup
Request: "Audit our Sentry integration for common mistakes"
Result: Found hardcoded DSN in config.ts (Pitfall 1), 100% tracesSampleRate (Pitfall 2), no environment tag (Pitfall 7), and zero alert rules (Pitfall 10). Applied fixes for all four, added CI gate for DSN detection, created three-tier alert config. See examples for more scenarios.
Example 2: Debugging missing Lambda errors
Request: "Sentry shows no errors from our Lambda functions but we know they're failing"
Result: Identified Pitfall 3 — no flush() call before Lambda return. Wrapped all handlers with Sentry.wrapHandler() from @sentry/aws-serverless. Events now appear within 5 seconds of invocation.
Example 3: Source map stack traces showing minified code
Request: "Sentry stack traces are all minified even though we upload source maps"
Result: SDK used release: "2.1.0" while CLI used "v2.1.0" (Pitfall 5). Unified both to $GIT_SHA via shared SENTRY_RELEASE env var. Stack traces now show original TypeScript source.