Skip to main content
The Sentry Cloudflare SDK provides error monitoring and performance tracking for Cloudflare Workers and Cloudflare Pages applications.

Installation

Prerequisites

Add the nodejs_als or nodejs_compat compatibility flag to your wrangler.toml or wrangler.jsonc:
The SDK needs AsyncLocalStorage API to work correctly.

Cloudflare Pages

Middleware Setup

Add Sentry as middleware in functions/_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 with withSentry:

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

Cloudflare KV

Track KV operations:

Cloudflare R2

Track R2 operations:

Durable Objects

Instrument Durable Objects:

Source Maps

Configure source map upload:
Or manually in 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

Common Patterns

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