Why Use Tunneling?
Ad Blocker Prevention
Ad blockers often block requests tosentry.io, preventing error reporting:
CORS Issues
Some browsers or configurations have strict CORS policies that block cross-origin requests to Sentry.Content Security Policy
CSP rules may prevent connections to external domains.How Tunneling Works
- Browser sends events to your backend (e.g.,
/api/sentry-tunnel) - Backend forwards events to Sentry
- Sentry processes events normally
Quick Setup
1. Configure SDK
2. Create Backend Endpoint
Next.js API Route
Express.js
SvelteKit
Security Considerations
Validate DSN
Only forward to known Sentry projects:Rate Limiting
Prevent abuse:Size Limits
Limit payload size:Advanced Configurations
Multiple Projects
Support multiple Sentry projects:Filtering Events
Filter events before forwarding:Adding Server Context
Enrich events with server-side data:Troubleshooting
Events not appearing in Sentry
Events not appearing in Sentry
Check:
- Tunnel endpoint is reachable:
curl -X POST https://yourapp.com/api/sentry-tunnel - DSN in SDK config matches allowed DSN in tunnel
- Check server logs for errors
- Verify Sentry’s response in tunnel logs
CORS errors with tunnel
CORS errors with tunnel
Solution: Ensure CORS headers are set:
High server load from tunnel
High server load from tunnel
Solutions:
- Implement rate limiting
- Add caching for repeated requests
- Use async processing queue
- Scale your backend horizontally
Tunnel timeout errors
Tunnel timeout errors
Solution: Increase timeout:
Production-Ready Example
Monitoring Your Tunnel
Add observability to your tunnel endpoint:Best Practices
Use environment variables for configuration
Use environment variables for configuration
Implement health checks
Implement health checks
Log tunnel activity
Log tunnel activity
Cache Sentry responses
Cache Sentry responses
For rate-limited responses, cache to avoid repeated failures:
Next Steps
Custom Transports
Build custom transport layers
OpenTelemetry
Integrate with OpenTelemetry