sentry-cloudflare-sdk

Full Sentry SDK setup for Cloudflare Workers and Pages. Use when asked to "add Sentry to Cloudflare Workers", "install @sentry/cloudflare", or configure error monitoring, tracing, logging, crons, or AI monitoring for Cloudflare Workers, Pages, Durable Objects, Queues, Workflows, or Hono on Cloudflar

By getsentry · 2,413 installs

npx skills add getsentry/sentry-for-ai --skill sentry-cloudflare-sdk

Source repository · Upstream listing

[All Skills](../../SKILL TREE.md) [SDK Setup](../sentry sdk setup/SKILL.md) Cloudflare SDK Sentry Cloudflare SDK Opinionated wizard that scans your Cloudflare project and guides you through complete Sentry setup for Workers, Pages, Durable Objects, Queues, Workflows, and Hono. Invoke This Skill When User asks to "add Sentry to Cloudflare Workers" or "set up Sentry" in a Cloudflare project User wants to install or configure @sentry/cloudflare User wants error monitoring, tracing, logging, crons, or AI monitoring for Cloudflare Workers or Pages User asks about withSentry , sentryPagesPlugin , instrumentDurableObjectWithSentry , or instrumentD1WithSentry User wants to monitor Durable Objects, Queues, Workflows, Scheduled handlers, or Email handlers on Cloudflare Note: SDK versions and APIs below reflect current Sentry docs at time of writing ( @sentry/cloudflare v10.61.0). Always verify against [docs.sentry.io/platforms/javascript/guides/cloudflare/](https://docs.sentry.io/platforms/javascript/guides/cloudflare/) before implementing. Phase 1: Detect Run these commands to understand the project before making any recommendations: What to determine: Question Impact Workers or Pages? Determines wrapper: withSentry vs sentryPagesPlugin Hono framework? Recommend standalone @sentry/hono package (v10.55.0+) for cleaner integration @sentry/cloudflare already installed? Skip install, go to feature config Durable Objects configured? Recommend instrumentDurableObjectWithSentry D1 databases bound? withSentry auto instruments D1 bindings (v10.57.0+); no manual wrapping needed Queues configured? withSentry auto instruments queue handlers Workflows configured? Recommend instrumentWorkflowWithSentry Cron triggers configured? withSentry auto instruments scheduled handlers; recommend Crons monitoring nodejs als or nodejs compat flag set? Required — SDK needs AsyncLocalStorage AI/LLM libraries? Recommend AI Monitoring integrations Companion frontend? Trigger Phase 4 cross link Phase 2: Recommend Present a concrete recommendation based on what you found. Don't ask open ended questions — lead with a proposal: Recommended (core coverage): ✅ Error Monitoring — always; captures unhandled exceptions in fetch, scheduled, queue, email, and Durable Object handlers ✅ Tracing — automatic HTTP request spans, outbound fetch tracing, D1 query spans Optional (enhanced observability): ⚡ Logging — structured logs via Sentry.logger. ; recommend when log search is needed ⚡ Crons — detect missed/failed scheduled jobs; recommend when cron triggers are configured ⚡ D1 Instrumentation — automatic query spans and breadcrumbs; recommend when D1 is bound ⚡ Durable Objects — automatic error capture and spans for DO methods; recommend when DOs are configured ⚡ Workflows — automatic span creation for workflow steps; recommend when Workflows are configured ⚡ AI Monitoring — Vercel AI SDK, OpenAI, Anthropic, LangChain; recommend when AI libraries detected Recommendation logic: Feature Recommend when... Error Monitoring Always — non negotiable baseline Tracing Always — HTTP request tracing and outbound fetch are high value Logging App needs structured log search or log to trace correlation Crons Cron triggers configured in wrangler.toml D1 Instrumentation D1 database bindings present Durable Objects Durable Object bindings configured Workflows Workflow bindings configured AI Monitoring App uses Vercel AI SDK, OpenAI, Anthropic, or LangChain Metrics App needs custom counters, gauges, or distributions Propose: "I recommend setting up Error Monitoring + Tracing. Want me to also add D1 instrumentation and Crons monitoring?" Phase 3: Guide Option 1: Source Maps Wizard You need to run this yourself — the wizard opens a browser for login and requires interactive input that the agent can't handle. Copy paste into your terminal: This sets up source map uploading so your production stack traces show readable code. It does not set up the SDK initialization — you still need to follow Option 2 below for the actual SDK setup. Once it finishes, continue with Option 2 for SDK setup. Note: Unlike framework SDKs (Next.js, SvelteKit), there is no Cloudflare specific wizard integration. The sourcemaps wizard only handles source map upload configuration. Option 2: Manual Setup Prerequisites: Compatibility Flags The SDK requires AsyncLocalStorage . Add one of these flags to your Wrangler config: wrangler.toml: wrangler.jsonc: nodejs als is lighter — it only enables AsyncLocalStorage . Use nodejs compat if your code also needs other Node.js APIs. Install Workers Setup Wrap your handler with withSentry . This automatically instruments fetch , scheduled , queue , email , and tail handlers: Key points: The first argument is a callback that receives env — use this to read secrets like SENTRY DSN The SDK reads DSN, environment, release, debug, tunnel, and traces sample rate from env automatically (see [Environment Variables]( environment variables)) withSentry wraps all exported handlers — you do not need separate wrappers for scheduled , queue , etc. Pages Setup Use sentryPagesPlugin as middleware: Chaining multiple middlewares: Using wrapRequestHandler directly (for frameworks like SvelteKit on Cloudflare Pages): Hono on Cloudflare Workers Recommended (v10.55.0+): Use the standalone @sentry/hono package for Hono apps: The @sentry/cloudflare package is a peer dependency and must stay in sync with @sentry/hono . The sentry() middleware automatically captures errors and creates transaction spans with route patterns. Legacy approach (deprecated): Using @sentry/cloudflare with withSentry still works, but honoIntegration is deprecated: Set Up the SENTRY DSN Secret Store your DSN as a Cloudflare secret — do not hardcode it: Add the binding to your Env type: Source Maps Setup Source maps make production stack traces readable. Most Cloudflare projects build with Vite via Wrangler — wire the Sentry Vite plugin so maps upload on build: SENTRY AUTH TOKEN is a build time secret. For creating the token and wiring it into CI, see [ sentry source maps ](../sentry source maps/SKILL.md). The npx @sentry/wizard@latest i sourcemaps shortcut noted above automates this setup. Automatic Release Detection The SDK can automatically detect the release version via Cloudflare's version metadata binding: wrangler.toml: Release priority (highest to lowest): 1. release option passed to Sentry.init() 2. SENTRY RELEASE environment variable 3. CF VERSION METADATA.id binding For Each Agreed Feature Load the corresponding reference file and follow its steps: Feature Reference file Load when... Error Monitoring references/error monitoring.md Always (baseline) — unhandled exceptions, manual capture, scopes, enrichment Tracing references/tracing.md HTTP request tracing, outbound fetch spans, D1 query spans, distributed tracing Logging references/logging.md Structured logs via Sentry.logger. , log to trace correlation Crons references/crons.md Scheduled handler monitoring, withMonitor , check in API Durable Objects references/durable objects.md Instrument Durable Object classes for error capture and spans For each feature: read the reference file, follow its steps exactly, and verify before moving on. Configuration Reference Sentry.init() Options Option Type Default Notes dsn string — Required. Read from env.SENTRY DSN automatically if not set tracesSampleRate number — 0–1; 1.0 in dev, lower in prod recommended tracesSampler function — Dynamic sampling function; mutually exclusive with tracesSampleRate dataCollection object conservative unless set Controls what data the SDK captures ( userInfo , httpBodies , etc.). When omitted, falls back to sendDefaultPii (default false ); passing the object — even {} — enables permissive defaults. See [Data Collection Reference]( data collection reference) sendDefaultPii boolean false Legacy. Prefer dataCollection for control over captured data enableLogs boolean false Enable Sentry Logs product environment string auto Read from env.SENTRY ENVIRONMENT if not set release string auto Detected from CF VERSION METADATA.id or SENTRY RELEASE debug boolean false Read from env.SENTRY DEBUG if not set. Log SDK activity to console tunnel string — Read from env.SENTRY TUNNEL if not set beforeSend function — Filter/modify error events before sending beforeSendTransaction function — Filter/modify transaction events before sending beforeSendLog function — Filter/modify log entries before sending tracePropagationTargets (string\ RegExp)[] all URLs Control which outbound requests get trace headers skipOpenTelemetrySetup boolean false Opt out of OpenTelemetry compatibility tracer instrumentPrototypeMethods boolean \ string[] false Durable Object: instrument prototype methods for RPC spans Data Collection Reference Environment Variables (Read from env ) The SDK reads these from the Cloudflare env object automatically: Variable Purpose SENTRY DSN DSN for Sentry init SENTRY RELEASE Release version string SENTRY ENVIRONMENT Environment name ( production , staging ) SENTRY TRACES SAMPLE RATE Traces sample rate (parsed as float) SENTRY DEBUG Enable debug mode ( "true" / "1" ) SENTRY TUNNEL Tunnel URL for event proxying CF VERSION METADATA Cloudflare version metadata binding (auto detected release) Default Integrations These are registered automatically by getDefaultIntegrations() : Integration Purpose dedupeIntegration Prevent duplicate events (disabled for Workflows) inboundFiltersIntegration Filter events by type, message, URL functionToStringIntegration Preserve original function names linkedErrorsIntegration Follow cause chains in errors fetchIntegration Trace outbound fetch() calls, create breadcrumbs honoIntegration Deprecated in v10.55.0 — use @sentry/hono package instead. Auto capture Hono onError exceptions requestDataIntegration Attach request data to events consoleIntegration Capture console. calls as breadcrumbs Verification After setup, verify Sentry is working: Deploy and trigger the route, then check your [Sentry Issues dashboard](https://sentry.io/issues/) — the error should appear within ~30 seconds. Verification checklist: Check How Errors captured Throw in a fetch handler, verify in Sentry Tracing working Check Performance tab for HTTP spans Source maps working Check stack trace shows readable file/line names D1 spans (if configured) Run a D1 query, check for db.query spans Scheduled monitoring (if configured) Trigger a cron, check Crons dashboard Phase 4: Cross Link After completing Cloudflare setup, check for companion services: If a frontend is found, suggest the matching SDK skill: Frontend detected Suggest skill React sentry react sdk Next.js sentry nextjs sdk Svelte/SvelteKit sentry svelte sdk Vue/Nuxt See [docs.sentry.io/platforms/javascript/guides/vue/](https://docs.sentry.io/platforms/javascript/guides/vue/) If a backend is found in a different direc