Skip to main content
Tunneling routes Sentry events through your backend server instead of sending them directly from the browser. This prevents ad blockers from blocking Sentry and avoids CORS issues.

Why Use Tunneling?

Ad Blocker Prevention

Ad blockers often block requests to sentry.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

  1. Browser sends events to your backend (e.g., /api/sentry-tunnel)
  2. Backend forwards events to Sentry
  3. 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

Check:
  1. Tunnel endpoint is reachable: curl -X POST https://yourapp.com/api/sentry-tunnel
  2. DSN in SDK config matches allowed DSN in tunnel
  3. Check server logs for errors
  4. Verify Sentry’s response in tunnel logs
Solution: Ensure CORS headers are set:
Solutions:
  1. Implement rate limiting
  2. Add caching for repeated requests
  3. Use async processing queue
  4. Scale your backend horizontally
Solution: Increase timeout:

Production-Ready Example

Monitoring Your Tunnel

Add observability to your tunnel endpoint:

Best Practices

For rate-limited responses, cache to avoid repeated failures:

Next Steps

Custom Transports

Build custom transport layers

OpenTelemetry

Integrate with OpenTelemetry