| name | sentry-multi-env-setup |
| description | Configure Sentry across development, staging, and production environments
with separate DSNs, environment-specific sample rates, per-environment
alert rules, and dashboard filtering.
Use when setting up Sentry for dev/staging/production, managing
environment-specific configurations, isolating data between environments,
or configuring .env files for per-environment DSNs.
Trigger: "sentry environments", "sentry staging setup",
"multi-environment sentry", "sentry dev vs prod", "sentry DSN per env".
|
| allowed-tools | Read, Write, Edit, Grep, Glob, Bash(npm:*), Bash(npx:*), Bash(node:*), Bash(sentry-cli:*) |
| version | 1.51.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
| tags | ["saas","sentry","environments","configuration","multi-env","dsn","alerts"] |
| compatibility | Designed for Claude Code, also compatible with Codex and OpenClaw |
Sentry Multi-Environment Setup
Overview
Configure Sentry to run across development, staging, and production with isolated DSNs, tuned sample rates, environment-aware alert routing, and dashboard filtering. Covers @sentry/node v8+ (TypeScript) and sentry-sdk v2+ (Python), targeting sentry.io or self-hosted Sentry 24.1+. The goal is to capture everything in dev, validate in staging, and protect production with tight sampling and PII scrubbing.
Prerequisites
- Sentry organization at sentry.io with at least one project created
@sentry/node v8+ installed (npm install @sentry/node) or sentry-sdk v2+ (pip install sentry-sdk)
- Environment naming convention agreed upon (this guide uses
development, staging, production)
- DSN strategy decided: single project with environment tags or separate projects per environment (see project-structure-options.md)
.env file management tooling (dotenv, direnv, or platform-native env config)
Instructions
Step 1 — Create Environment-Aware SDK Configuration with Separate DSNs
Each environment gets its own DSN pointing to a dedicated Sentry project. This prevents dev noise from inflating production quotas and allows independent rate limits per environment.
Set up .env files per environment:
SENTRY_DSN=https://dev-key@o0.ingest.sentry.io/111
SENTRY_ENVIRONMENT=development
SENTRY_RELEASE=local-dev
SENTRY_DSN=https://staging-key@o0.ingest.sentry.io/222
SENTRY_ENVIRONMENT=staging
SENTRY_DSN=https://prod-key@o0.ingest.sentry.io/333
SENTRY_ENVIRONMENT=production
TypeScript — environment-aware init with typed config:
import * as Sentry from '@sentry/node';
type Environment = | | ;
{
: ;
: ;
: ;
: ;
: ;
: ;
}
: <, > = {
: {
: ,
: ,
: ,
: ,
: ,
: ,
},
: {
: ,
: ,
: ,
: ,
: ,
: ,
},
: {
: ,
: ,
: ,
: ,
: ,
: ,
},
};
(): {
environment = env
|| (process.. )
|| (process.. )
|| ;
config = [environment] || .;
.({
: process..,
environment,
: process.. || ,
...config,
() {
(environment === ) event;
(environment === && event. === ) ;
(environment === ) {
(event.?.?.(
e.?.()
)) ;
(event.?.) {
event..[];
event..[];
event..[];
}
}
event;
},
});
}