Install Sentry Cloudflare SDK for Worker error monitoring#91
Conversation
Linear: AP-42
AP-42 Install Sentry Cloudflare SDK for Worker error monitoring
ContextCloudflare Worker apps need server-side error monitoring through Sentry. The SDK should initialize from Worker secrets, avoid committing DSNs, and preserve the repo's existing error-envelope behavior. Scope
Out of scope
Acceptance criteria
|
|
Caution Review failedFailed to post review comments WalkthroughThis pull request adds a shared sentryOptions helper and re-exports it from the worker-runtime package, adds Sequence DiagramsequenceDiagram
participant Client as Client Request
participant Worker as Cloudflare Worker
participant Wrapper as Sentry.withSentry
participant Config as sentryOptions(env)
participant Env as Environment Bindings
participant Handler as Worker Handler
Client->>Worker: HTTP request
Worker->>Wrapper: exported worker invoked
Wrapper->>Config: call sentryOptions(env)
Config->>Env: read SENTRY_DSN, AGENT_PASTE_ENV
Env-->>Config: return values
Config-->>Wrapper: CloudflareOptions
Wrapper->>Handler: invoke worker.fetch(request, env)
Handler-->>Worker: response (or throw)
Wrapper-->>Worker: capture error and send to Sentry if enabled
Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ESLint
ESLint skipped: no ESLint configuration detected in root package.json. To enable, add Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/web/src/server.ts`:
- Around line 6-10: The wrapper entry created by createServerEntry simply
forwards fetch to handler.fetch with no extra behavior, so remove the redundant
createServerEntry/entry and call handler.fetch directly from the worker's fetch
method (or export handler as the fetch handler); update any references to entry
to use handler (or its fetch method) and delete createServerEntry usage to
simplify the flow (look for symbols createServerEntry, entry, handler.fetch and
the worker fetch export).
In `@packages/worker-runtime/src/sentry.ts`:
- Around line 10-13: Normalize env.SENTRY_DSN once into a local variable and use
that for both the dsn and enabled fields: create a const like normalizedDsn =
env.SENTRY_DSN?.trim() ?? "" and then set dsn: normalizedDsn and enabled:
normalizedDsn.length > 0 in the sentry configuration (the dsn and enabled fields
in packages/worker-runtime/src/sentry.ts), leaving environment and
sendDefaultPii unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: b123bf6e-0b57-4dde-bc44-7ba2b2470a4d
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (25)
apps/apex/package.jsonapps/apex/src/index.tsapps/apex/wrangler.jsoncapps/api/package.jsonapps/api/src/index.test.tsapps/api/src/index.tsapps/api/wrangler.jsoncapps/content/package.jsonapps/content/src/index.tsapps/content/wrangler.jsoncapps/jobs/package.jsonapps/jobs/src/index.tsapps/mcp/package.jsonapps/mcp/src/index.tsapps/upload/package.jsonapps/upload/src/index.tsapps/upload/wrangler.jsoncapps/web/package.jsonapps/web/src/server.tsapps/web/src/server/env.tsapps/web/wrangler.jsoncpackages/worker-runtime/package.jsonpackages/worker-runtime/src/index.tspackages/worker-runtime/src/sentry.test.tspackages/worker-runtime/src/sentry.ts
|
agent-paste PR preview is ready. API: https://agent-paste-api-pr-91.isaac-a46.workers.dev |
…udflare-workers # Conflicts: # apps/api/src/index.test.ts
|
agent-paste PR preview is ready. API: https://agent-paste-api-pr-91.isaac-a46.workers.dev |
|
agent-paste PR preview resources were cleaned up. The pr-preview-${context.issue.number} environment is left in place; remove it from the GitHub UI if desired. |
Summary
Adds server-side Sentry error monitoring for the Cloudflare Worker surfaces while keeping DSN values in Worker secrets and default PII collection disabled. This gives deployed Workers a common Sentry initialization path without changing existing error-envelope behavior.
Changes
@sentry/cloudflareand a sharedsentryOptionshelper with DSN-from-env,sendDefaultPii: false, and empty-DSN disablement.Sentry.withSentry.nodejs_compat, source map upload for direct Wrangler Workers, and non-secret environment labels where needed.SENTRY_DSNsecrets out-of-band for configured preview/production Worker environments: api, upload, content, apex, and web.Risk: HIGH
Test plan
bun run ci:checkpnpm verifyLinear: AP-42
Summary by CodeRabbit
New Features
Tests
Refactor
Chores
Documentation