Setting the Environment
Theenvironment option identifies where your code is running:
Using Environment Variables
Environment-Specific Configuration
Conditional Initialization
Only initialize Sentry in certain environments:Different Settings Per Environment
Environment Variables
Node.js
Browser (with Build Tools)
Using Webpack DefinePlugin or similar:Vite
Vite automatically exposes environment variables prefixed withVITE_:
Development vs Production
Disabling in Development
Development-Specific Settings
Browser Extension Detection
The Browser SDK automatically detects browser extensions and disables itself by default:Multiple Environments in the Same Project
Use environments to segment data in your Sentry project:Server-Side Environment Detection
Express.js
Cloud Platforms
Vercel
AWS Lambda
Netlify
Framework-Specific Configuration
Next.js
Next.js supports.env.local, .env.production, etc.:
SvelteKit
Best Practices
Use consistent environment names
Use consistent environment names
Choose a standard set of environment names and use them consistently across all your projects. Common choices:
productionstagingdevelopmentqa/test
Don't hardcode sensitive values
Don't hardcode sensitive values
Never commit DSN or other sensitive configuration to source control. Use environment variables:
Configure sampling per environment
Configure sampling per environment
Production environments may need lower sampling rates to control volume:
Enable debug mode in development
Enable debug mode in development
Debug mode helps troubleshoot SDK issues during development:
Next Steps
Sampling Configuration
Control data volume with sampling rates
Filtering Events
Filter events before sending to Sentry