In the ground since Sun Oct 26 2025
Last watered in Sun Oct 26 2025
Sentry Multi-Environment Setup
Use one Sentry project to monitor multiple environments (demo, staging, production) through environment tagging. Unified monitoring with clear separation.
Benefits
✅ Unified Dashboard - All errors in one place
✅ Easy Comparison - Compare error rates across environments
✅ Cost Effective - Save on Sentry quota
✅ Simplified Management - One project to configure
✅ Environment Filtering - Filter by environment in Sentry UI
Architecture Overview
1 ┌─────────────────────────────────────────────┐
2 │ Sentry Project: "api-best-shot" │
3 ├─────────────────────────────────────────────┤
4 │ ┌────────┐ ┌────────┐ ┌────────────┐ │
5 │ │ demo │ │staging │ │ production │ │
6 │ └────────┘ └────────┘ └────────────┘ │
7 │ │
8 │ Same DSN, Different Environment Tags │
9 └─────────────────────────────────────────────┘
Quick Setup
1. Create Sentry Project
Visit Sentry.io
Create new project → Choose Node.js
Name: api-best-shot-non-production
Copy the DSN
2. Configure Environment Variables
Key Insight : Use the SAME DSN for all environments. Sentry differentiates
using the environment tag set via NODE_ENV .
.env.demo
1 NODE_ENV = demo
2 SENTRY_DSN = https://your-key@o123456.ingest.sentry.io/789012
.env.staging
1 NODE_ENV = staging
2 SENTRY_DSN = https://your-key@o123456.ingest.sentry.io/789012
3. Initialize Sentry
1 // src/services/profiling/sentry-instrument.ts
2 import * as Sentry from "@sentry/node" ;
3
4 Sentry . init ({
5 dsn: process . env . SENTRY_DSN ,
6 environment: process . env . NODE_ENV , // 'demo', 'staging', or 'production'
7 tracesSampleRate: 1.0 ,
8 });
Filtering by Environment
In Sentry UI
Navigate to Issues or Performance
Use environment dropdown filter
Select: demo , staging , or production
Compare data across environments
Environment-Specific Alerts
1 Alert Rule : High Error Rate in Staging
2 Conditions :
3 - Environment : staging
4 - Error count > 10 in 5 minutes
5 Actions :
6 - Send Slack notification
Deployment Configuration
GitHub Actions
1 # .github/workflows/deploy-demo.yml
2 - name : Deploy to Demo
3 env :
4 NODE_ENV : demo
5 SENTRY_DSN : ${{ secrets.SENTRY_DSN_NON_PROD }}
AWS Lambda
1 aws lambda update-function-configuration \
2 --function-name your-demo-function \
3 --environment Variables='{
4 "NODE_ENV":"demo",
5 "SENTRY_DSN":"https://your-key@o123456.ingest.sentry.io/789012"
6 }'
Best Practices
Separate Production
Production Isolation : Consider using a separate Sentry project for
production to prevent mixing production data with test data.
Non-Production Project : demo + staging
Production Project : production only
Environment-Specific Sample Rates
Adjust sample rates based on traffic volume:
1 const tracesSampleRate =
2 ENV === "production"
3 ? 0.1 // 10% in production
4 : ENV === "staging"
5 ? 0.5 // 50% in staging
6 : 1.0 ; // 100% in demo
7
8 Sentry . init ({
9 dsn: process . env . SENTRY_DSN ,
10 environment: ENV ,
11 tracesSampleRate ,
12 });
Release Tracking
Track deployed versions for better debugging:
1 Sentry . init ({
2 dsn: process . env . SENTRY_DSN ,
3 environment: ENV ,
4 release: `api-best-shot@ ${ process . env . VERSION } ` ,
5 });
Additional Context Tags
1 Sentry . setTag ( "deployment_region" , "us-east-1" );
2 Sentry . setTag ( "service_version" , "1.2.3" );
Troubleshooting
Errors Not Appearing
Check:
✅ SENTRY_DSN is set correctly
✅ NODE_ENV matches expected value
✅ Sentry initialization happens before app code
✅ Network connectivity to Sentry
Debug:
1 // Add to initialization
2 console . log ( "Sentry Environment:" , process . env . NODE_ENV );
3 console . log ( "Sentry DSN:" , process . env . SENTRY_DSN ? "Set" : "Missing" );
Wrong Environment Tag
Verify environment variable is passed correctly:
1 # Test locally
2 NODE_ENV = demo node your-app.js
Too Many Events
Use beforeSend to filter out specific errors and reduce noise in your Sentry
dashboard.
1 Sentry . init ({
2 dsn: process . env . SENTRY_DSN ,
3 environment: ENV ,
4 beforeSend ( event ) {
5 // Filter out connection errors
6 if ( event . message ?. includes ( "ECONNREFUSED" )) {
7 return null ; // Don't send to Sentry
8 }
9 return event ;
10 },
11 });
Key Takeaways
Use one DSN for multiple environments
Set environment tag via NODE_ENV
Filter by environment in Sentry UI
Create environment-specific alerts
Consider separate project for production
Adjust sample rates per environment