sentry-multi-env-setup
A guide to implementing isolated Sentry DSNs, sampling rates, and alert routing for multiple environments.
Install
mkdir -p .claude/skills/sentry-multi-env-setup && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/2763" && unzip -o skill.zip -d .claude/skills/sentry-multi-env-setup && rm skill.zipInstalls to .claude/skills/sentry-multi-env-setup
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Configure Sentry across development, staging, and production environmentsKey capabilities
- →Configure Sentry with separate DSNs for development, staging, and production
- →Set environment-specific sample rates for traces and errors
- →Implement PII scrubbing and event filtering based on environment
- →Initialize Sentry SDK in TypeScript and Python applications
- →Use .env files for managing environment variables
How it works
The skill uses environment variables to load specific Sentry configurations for each environment. It initializes the Sentry SDK with tailored sample rates, debug settings, and event filtering rules.
Inputs & outputs
When to use sentry-multi-env-setup
- →Isolate monitoring data between production and staging
- →Configure environment-specific alert rules
- →Set custom sampling rates per environment
- →Integrate Sentry into TypeScript or Python apps
About this skill
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/nodev8+ installed (npm install @sentry/node) orsentry-sdkv2+ (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)
.envfile 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:
# .env.development
SENTRY_DSN=https://[email protected]/111
SENTRY_ENVIRONMENT=development
SENTRY_RELEASE=local-dev
# .env.staging
SENTRY_DSN=https://[email protected]/222
SENTRY_ENVIRONMENT=staging
# .env.production
SENTRY_DSN=https://[email protected]/333
SENTRY_ENVIRONMENT=production
TypeScript — environment-aware init with typed config:
// config/sentry.ts
import * as Sentry from '@sentry/node';
type Environment = 'development' | 'staging' | 'production';
interface EnvSentryConfig {
tracesSampleRate: number;
sampleRate: number;
debug: boolean;
sendDefaultPii: boolean;
maxBreadcrumbs: number;
enabled: boolean;
}
const ENV_CONFIG: Record<Environment, EnvSentryConfig> = {
development: {
tracesSampleRate: 1.0, // Capture every transaction for local debugging
sampleRate: 1.0, // Every error
debug: true, // Verbose console output for SDK troubleshooting
sendDefaultPii: true, // Include PII for local debugging only
maxBreadcrumbs: 100, // Full breadcrumb trail
enabled: true, // Set to false to fully disable in dev
},
staging: {
tracesSampleRate: 0.5, // 50% of transactions — enough to catch regressions
sampleRate: 1.0, // All errors — staging validates error handling
debug: false,
sendDefaultPii: false, // Staging mirrors prod PII policy
maxBreadcrumbs: 50,
enabled: true,
},
production: {
tracesSampleRate: 0.1, // 10% — balances visibility with quota budget
sampleRate: 1.0, // All errors — never drop production errors
debug: false,
sendDefaultPii: false, // Never send PII in production
maxBreadcrumbs: 50,
enabled: true,
},
};
export function initSentry(env?: Environment): void {
const environment = env
|| (process.env.SENTRY_ENVIRONMENT as Environment)
|| (process.env.NODE_ENV as Environment)
|| 'development';
const config = ENV_CONFIG[environment] || ENV_CONFIG.development;
Sentry.init({
dsn: process.env.SENTRY_DSN,
environment,
release: process.env.SENTRY_RELEASE || `app@${process.env.npm_package_version || 'unknown'}`,
...config,
// Environment-specific event filtering
beforeSend(event) {
// Dev: capture everything for debugging
if (environment === 'development') return event;
// Staging: drop debug-level events to reduce noise
if (environment === 'staging' && event.level === 'debug') return null;
// Production: aggressive filtering
if (environment === 'production') {
// Drop known non-actionable browser errors
if (event.exception?.values?.some(e =>
e.value?.match(/ResizeObserver|Loading chunk|AbortError/)
)) return null;
// Scrub sensitive headers
if (event.request?.headers) {
delete event.request.headers['Authorization'];
delete event.request.headers['Cookie'];
delete event.request.headers['X-API-Key'];
}
}
return event;
},
});
}
Python — equivalent multi-environment init:
# config/sentry_config.py
import os
import sentry_sdk
ENV_CONFIG = {
"development": {
"traces_sample_rate": 1.0,
"sample_rate": 1.0,
"debug": True,
"send_default_pii": True,
"max_breadcrumbs": 100,
},
"staging": {
"traces_sample_rate": 0.5,
"sample_rate": 1.0,
"debug": False,
"send_default_pii": False,
"max_breadcrumbs": 50,
},
"production": {
"traces_sample_rate": 0.1,
"sample_rate": 1.0,
"debug": False,
"send_default_pii": False,
"max_breadcrumbs": 50,
},
}
def init_sentry() -> None:
environment = os.environ.get(
"SENTRY_ENVIRONMENT",
os.environ.get("PYTHON_ENV", "development"),
)
config = ENV_CONFIG.get(environment, ENV_CONFIG["development"])
def before_send(event, hint):
if environment == "production":
exc_info = hint.get("exc_info")
if exc_info:
exc_type = exc_info[0]
# Drop expected exceptions in production
if exc_type in (KeyboardInterrupt, SystemExit):
return None
# Scrub PII from headers
request = event.get("request", {})
headers = request.get("headers", {})
for key in ("Authorization", "Cookie", "X-API-Key"):
headers.pop(key, None)
return event
sentry_sdk.init(
dsn=os.environ.get("SENTRY_DSN", ""),
environment=environment,
release=os.environ.get("SENTRY_RELEASE", "unknown"),
before_send=before_send,
**config,
)
Step 2 — Configure Per-Environment Alert Rules and Dashboard Filtering
Alert routing prevents dev noise from waking on-call engineers. Each environment gets alert rules matching its severity tier.
Production alert rules (Sentry dashboard > Alerts > Create Rule):
| Alert Type | Condition | Filter | Action |
|---|---|---|---|
| Issue alert | New issue | environment:production | PagerDuty on-call |
| Metric alert | Error rate > 50/min for 5 min | environment:production | Slack #alerts-critical |
| Metric alert | P95 latency > 2s for 10 min | environment:production | Slack #alerts-performance |
Staging alert rules:
| Alert Type | Condition | Filter | Action |
|---|---|---|---|
| Issue alert | New issue (first seen) | environment:staging | Slack #alerts-staging |
| Metric alert | Error rate > 100/min for 5 min | environment:staging | Slack #alerts-staging |
Development: No alerts configured. Developers check the dashboard manually or use debug: true for console output.
Add environment context tags for richer filtering:
// Add to Sentry.init() for dashboard filtering
Sentry.init({
// ...base config from Step 1
initialScope: {
tags: {
environment: process.env.SENTRY_ENVIRONMENT || process.env.NODE_ENV,
region: process.env.AWS_REGION || process.env.GCP_REGION || 'us-east-1',
service: process.env.SERVICE_NAME || 'app',
deployment: process.env.DEPLOYMENT_ID || 'unknown',
},
},
});
// Dashboard filter queries:
// Issues > environment:production is:unresolved
// Performance > environment:staging service:api-gateway
// Discover > environment:production region:us-east-1
Disable Sentry in test and CI environments:
// test/setup.ts — prevent test runs from sending events
const isTestEnv = process.env.NODE_ENV === 'test' || process.env.CI === 'true';
if (!isTestEnv) {
initSentry();
} else {
// Initialize with empty DSN — SDK loads but sends nothing
// All Sentry.captureException() calls become safe no-ops
Sentry.init({ dsn: '' });
}
Step 3 — Wire CI/CD Releases to the Correct Environment
Tag Sentry releases with the deploy target so the Releases dashboard shows which commit is running where. Each sentry-cli releases deploys call records a deployment event on the timeline.
#!/usr/bin/env bash
# scripts/sentry-release.sh — call from CI after deploy
set -euo pipefail
VERSION="${SENTRY_RELEASE:-$(git rev-parse --short HEAD)}"
ENVIRONMENT="${1:?Usage: sentry-release.sh <environment>}"
ORG="${SENTRY_ORG:-my-org}"
PROJECT="${SENTRY_PROJECT:-my-app}"
echo "Creating Sentry release ${VERSION} for ${ENVIRONMENT}..."
# Create release and associate commits
sentry-cli releases --org "$ORG" --project "$PROJECT" new "$VERSION"
sentry-cli releases --org "$ORG" --project "$PROJECT" set-commits "$VERSION" --auto
# Upload source maps (if applicable)
if [ -d "./dist" ]; then
sentry-cli sourcemaps --org "$ORG" --project "$PROJECT" \
upload --release="$VERSION" ./dist
fi
# Finalize and record deployment
sentry-cli releases --org "$ORG" --project "$PROJECT" finalize "$VERSION"
sentry-cli releases --org "$ORG" --project "$PROJECT" \
deploys "$VERSION" new --env "$ENVIRONMENT"
echo "Release ${VERSION} deployed to ${ENVIRONMENT}"
# Usage in CI:
# ./scripts/sentry-release.sh staging # after staging deploy
# ./scripts/sentry-release.sh production # after production deploy
GitHub Actions integration:
# .github/workflows/deploy.yml (snippet)
- name: Create Sentry release
env:
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ORG: my-org
SENTRY_PROJECT: my-app
run: |
npm install -g @sentry/cli
./scripts/sentry-release.sh ${{ git
---
*Content truncated.*
When not to use it
- →When only a single Sentry project is used without environment isolation
- →When Sentry is not used for error monitoring and performance tracing
Prerequisites
Limitations
- →The skill requires a Sentry organization with at least one project created
- →The skill requires a DSN strategy decided (single project with tags or separate projects)
- →The skill requires .env file management tooling
How it compares
This skill provides a structured way to configure Sentry across multiple environments with isolated DSNs and tailored settings, unlike a single, generic Sentry initialization.
Compared to similar skills
sentry-multi-env-setup side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| sentry-multi-env-setup (this skill) | 2 | 27d | Review | Intermediate |
| sentry-data-handling | 0 | 27d | Caution | Advanced |
| langfuse | 7 | 6mo | No flags | Intermediate |
| engineering-skills | 4 | 2mo | Review | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by jeremylongshore
View all by jeremylongshore →You might also like
sentry-data-handling
jeremylongshore
Manage sensitive data properly in Sentry. Use when configuring PII scrubbing, data retention, GDPR compliance, or data security settings. Trigger with phrases like "sentry pii", "sentry gdpr", "sentry data privacy", "scrub sensitive data sentry".
langfuse
davila7
Expert in Langfuse - the open-source LLM observability platform. Covers tracing, prompt management, evaluation, datasets, and integration with LangChain, LlamaIndex, and OpenAI. Essential for debugging, monitoring, and improving LLM applications in production. Use when: langfuse, llm observability, llm tracing, prompt management, llm evaluation.
engineering-skills
alirezarezvani
23 production-ready engineering skills covering architecture, frontend, backend, fullstack, QA, DevOps, security, AI/ML, data engineering, computer vision, and specialized tools like Playwright Pro, Stripe integration, AWS, and MS365. 30+ Python automation tools (all stdlib-only). Works with Claude Code, Codex CLI, and OpenClaw.
sentry-rate-limits
jeremylongshore
Manage Sentry rate limits and quota optimization. Use when hitting rate limits, optimizing event volume, or managing Sentry costs. Trigger with phrases like "sentry rate limit", "sentry quota", "reduce sentry events", "sentry 429".
lint-and-validate
davila7
Automatic quality control, linting, and static analysis procedures. Use after every code modification to ensure syntax correctness and project standards. Triggers onKeywords: lint, format, check, validate, types, static analysis.
optimizing-performance
CloudAI-X
Analyzes and optimizes application performance across frontend, backend, and database layers. Use when diagnosing slowness, improving load times, optimizing queries, reducing bundle size, or when asked about performance issues.