Installation
Prerequisites
Add thenodejs_als or nodejs_compat compatibility flag to your wrangler.toml or wrangler.jsonc:
AsyncLocalStorage API to work correctly.
Cloudflare Pages
Middleware Setup
Add Sentry as middleware infunctions/_middleware.ts:
Multiple Middlewares
Chain multiple middlewares (Sentry should be first):Access Environment Variables
SvelteKit on Cloudflare
Cloudflare Workers
Basic Setup
Wrap your worker handler withwithSentry:
Full Worker Example
Cloudflare D1 Integration
Instrument D1 database operations:Cron Monitoring
Monitor scheduled tasks with Sentry Crons:Performance Monitoring
Custom Spans
Context & User Information
Set User Context
Add Context & Tags
Breadcrumbs
Cloudflare KV
Track KV operations:Cloudflare R2
Track R2 operations:Durable Objects
Instrument Durable Objects:Source Maps
Configure source map upload:wrangler.toml:
Best Practices
Middleware First
Always place Sentry middleware first in the chain.
Environment Variables
Store your DSN in environment variables, not in code.
Instrument Storage
Use
instrumentD1WithSentry to track database queries.Monitor Crons
Use
withMonitor to track scheduled tasks.Configuration
Complete Configuration
Complete Configuration
Common Patterns
- API Routes
- Authentication
Next Steps
Cloudflare Docs
Official Cloudflare Workers documentation
D1 Database
Learn about Cloudflare D1
Source Maps
Upload source maps for production
Performance
Performance monitoring guide