feat: Migrate to Cloudflare Workers - #238
Conversation
This reverts commit a3e03a5.
…lemetry gating nodejs_compat already provides AsyncLocalStorage at our compatibility date (>= 2024-09-23 enables nodejs_compat_v2), so nodejs_als was a no-op in both wrangler configs. Move @opentelemetry/api and @opentelemetry/sdk-trace-node to dependencies, alongside the other seven @opentelemetry/* packages. Document that PUBLIC_SIGNOZ_LOGS_ENABLED is intentionally one switch for all telemetry signals despite its name, and that being a $env/static/public import means the whole tracing block is dead-code eliminated unless the flag is set in the build environment -- not just at runtime. Note in the CSP comment that the _headers X-Frame-Options fallback for prerendered pages is Cloudflare-only: adapter-node serves prerendered HTML through sirv before the SvelteKit handler, so hooks.server.ts never runs for it. Moot while prerender = false at the root layout.
Workers Builds is the only Cloudflare deploy path now, so the dual-config arrangement is gone: wrangler.workers.jsonc is promoted to wrangler.jsonc, which wrangler and @sveltejs/adapter-cloudflare both auto-discover. The adapter selects Workers output over Pages output because the config declares main/assets and no pages_build_output_dir, so the explicit `config` option and the `--config` deploy flag are no longer needed, and there are no longer two files whose compatibility settings must be hand-synced. Drop CF_PAGES detection from vite.config.ts and rename isWorkersCI to isCloudflare now that it is the only Cloudflare branch. This also removes the CF_PAGES_COMMIT_SHA fallback in getGitHash(). _headers and _redirects are kept — Workers static assets support both, and adapter-cloudflare copies them from the project root in either mode.
develop deliberately stripped the Cloudflare Workers deployment (c4f549d) so this branch owns it, so the deletions it carries for wrangler.jsonc, src/worker-configuration.d.ts, and the wrangler devDependency are reverted here -- they are this branch's reason to exist. Conflict resolutions: - package.json: keep @opentelemetry/sdk-trace-node and drop develop's swap to sdk-trace-base (see below). Restore the wrangler devDependency, which adapter-cloudflare imports (unstable_readConfig) and `wrangler deploy` needs. - vite.config.ts: keep develop's adapter comment; the Workers/Node split itself is unchanged. - wrangler.jsonc: keep ours (deleted on develop). - src/worker-configuration.d.ts: keep ours (deleted on develop). - pnpm-lock.yaml: regenerated. f636c8b swapped sdk-trace-node for sdk-trace-base plus a hand-rolled AsyncLocalStorage context manager because the Cloudflare Pages Functions bundler could not resolve @opentelemetry/context-async-hooks' bare require("async_hooks") and require("events"). That reason does not apply here: Pages support is gone as of 42c51ab, and wrangler's Workers bundler maps those bare requires onto the builtin via a node-built-in-modules:async_hooks shim -- confirmed by inspecting a `wrangler deploy --dry-run` bundle. Reverting drops ~40 lines of custom ContextManager, including a subtle bind() that forwards dynamic `this`, in favour of the maintained upstream class. NodeTracerProvider.register() only needs AsyncLocalStorage, which nodejs_compat supplies; the sibling AsyncHooksContextManager that needs the unsupported createHook is imported but never constructed.
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
openshock-app | c510e04 | Aug 06 2026, 12:18 PM |
There was a problem hiding this comment.
Pull request overview
This PR migrates the project’s Cloudflare deployment from Pages to Workers (Workers Builds), removing Pages-specific configuration and adjusting build/runtime detection and tracing setup to align with the Workers toolchain.
Changes:
- Added a
wrangler.jsoncWorkers configuration (auto-discovered) and updated Cloudflare detection invite.config.tsto rely onWORKERS_CI. - Simplified server-side OpenTelemetry tracing bootstrap by switching to
@opentelemetry/sdk-trace-node’sNodeTracerProvider. - Updated repo tooling/docs: submodule URL to HTTPS, README instructions, and dependency/lockfile updates (including adding
wrangler).
Reviewed changes
Copilot reviewed 6 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| wrangler.jsonc | Introduces the Workers (Wrangler) config for Workers Builds deployment. |
| vite.config.ts | Updates Cloudflare CI detection and related build behavior (adapter selection, git SHA, production gating). |
| src/worker-configuration.d.ts | Adds generated Wrangler types for Worker bindings/env. |
| src/instrumentation.server.ts | Switches tracing provider to NodeTracerProvider for Workers-friendly bundling/runtime. |
| README.md | Updates setup/self-hosting notes and API client generation command documentation. |
| package.json | Adjusts dependencies (adds wrangler, moves/adds OTel packages for node tracing). |
| pnpm-lock.yaml | Locks new/updated dependencies introduced by the migration. |
| .gitmodules | Switches submodule URL from SSH to HTTPS to support Workers Builds cloning. |
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Warning Review limit reached
Next review available in: 48 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. 📝 WalkthroughWalkthroughThe pull request adds Cloudflare Worker deployment configuration, generated environment typings, and Workers CI detection. It changes server tracing to use ChangesCloudflare runtime and project setup
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 8 changed files in this pull request and generated no new comments.
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
Suppressed comments (2)
src/instrumentation.server.ts:38
- Telemetry gating for server spans treats PUBLIC_SIGNOZ_LOGS_ENABLED='1' as enabled, but the consent prompt (src/lib/telemetry/consent-prompt.ts:14) only enables when the flag is exactly 'true'. This can lead to inconsistent behavior when a deploy sets the flag to '1' (server spans on, but no consent prompt). Consider standardizing on a single value (preferably 'true').
const enabled = PUBLIC_SIGNOZ_LOGS_ENABLED === 'true' || PUBLIC_SIGNOZ_LOGS_ENABLED === '1';
README.md:42
- README now recommends a global Git config rewrite from https://github.com/ to git@github.com:, which can unexpectedly affect all repositories on a developer machine. The PR description suggests using a repo-local rewrite instead; the docs should match that safer default.
To clone the project you may need to rewrite git HTTPS urls to SSH for the submodule checkout to work on your machine.
You can do this with `git config --global url."git@github.com:".insteadOf "https://github.com/"`
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@README.md`:
- Line 37: Update the README API client generation command from pnpx regen-api
to pnpm run regen-api so it invokes the local regen-api package script.
🪄 Autofix
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: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 5ac748ae-30ea-4275-b6d5-fc6c64181196
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (7)
.gitmodulesREADME.mdpackage.jsonsrc/instrumentation.server.tssrc/worker-configuration.d.tsvite.config.tswrangler.jsonc
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 8 changed files in this pull request and generated no new comments.
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
Suppressed comments (2)
README.md:165
- The README says the project can be deployed to Workers with Wrangler, but the build selects
adapterCloudflare()only whenWORKERS_CIis set (seevite.config.ts), andwrangler.jsoncexpects.svelte-kit/cloudflare/_worker.js. Without guidance, a localpnpm build+wrangler deploywill likely produce Node adapter output instead of the required Workers output.
## Selfhosting
A guide to selfhost can be found [on the wiki.](https://wiki.openshock.org/guides/selfhosting)
Alternatively you can deploy it to cloudflare workers using wrangler (or forking it).
README.md:42
- These instructions suggest rewriting all GitHub HTTPS URLs globally, which is a broad side-effect and doesn’t match the new motivation (submodule now uses HTTPS by default). Consider making this optional and scoped to the repo via
--local.
To clone the project you may need to rewrite git HTTPS urls to SSH for the submodule checkout to work on your machine.
You can do this with `git config --global url."git@github.com:".insteadOf "https://github.com/"`
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 8 changed files in this pull request and generated no new comments.
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
Suppressed comments (2)
README.md:164
- Minor wording/capitalization issues in the self-hosting section ("Selfhosting"/"selfhost" and "cloudflare"/"workers" naming). Cleaning this up makes the docs look more polished and consistent.
## Selfhosting
A guide to selfhost can be found [on the wiki.](https://wiki.openshock.org/guides/selfhosting)
Alternatively you can deploy it to cloudflare workers using wrangler (or forking it).
README.md:42
- This reads like SSH rewriting is required for the submodule to work, but .gitmodules now uses an HTTPS URL so checkout should work by default. Consider rephrasing this as an optional tip for developers who prefer SSH, and avoid a global rewrite that may break other GitHub HTTPS workflows.
To clone the project you may need to rewrite git HTTPS urls to SSH for the submodule checkout to work on your machine.
You can do this with `git config --global url."git@github.com:".insteadOf "https://github.com/"`
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 8 changed files in this pull request and generated no new comments.
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
Suppressed comments (2)
README.md:45
- The README implies HTTPS→SSH rewriting is required for the submodule to clone, and suggests a global rewrite. Since the submodule URL is now HTTPS specifically to work in Cloudflare Workers Builds, it’s safer to present SSH rewriting as optional and keep it repo-local (or at least not recommended globally).
To clone the project you may need to rewrite git HTTPS urls to SSH for the submodule checkout to work on your machine.
You can do this with `git config --global url."git@github.com:".insteadOf "https://github.com/"`
To get started with development, you will need to have **Node.js** and **pnpm** installed.
We recommend using a node version manager of your choice.
README.md:165
- Minor wording/capitalization issues in the new self-hosting section ("Selfhosting", "selfhost", and "cloudflare workers"). This section reads more cleanly with standard hyphenation and proper nouns capitalized.
## Selfhosting
A guide to selfhost can be found [on the wiki.](https://wiki.openshock.org/guides/selfhosting)
Alternatively you can deploy it to cloudflare workers using wrangler (or forking it).
Moves the Cloudflare deploy from Pages to Workers, and drops Pages support.
Why
sveltejs/kit#16604 removes Pages support from
@sveltejs/adapter-cloudflareentirely (breaking, targets SvelteKit v3).Staying on Pages means pinning the adapter forever.
Cloudflare's own Workers best practices say it plainly: "If you are starting a new project, use Workers instead of Pages."
There's no EOL date, but all future investment goes to Workers, and Pages still lacks Durable Objects, Cron Triggers, Queues, and decent observability.
See the migration guide.
Changes
wrangler.workers.jsonctowrangler.jsonc, deleted the Pages config. It's auto-discovered, so no--configflag and no two files to hand-sync.openshock-app.CF_PAGESdetection fromvite.config.ts, and renamedisWorkersCItoisCloudflare. The Node adapter still covers local/Docker/selfhost.nodejs_als, which is redundant undernodejs_compatat our compatibility date.git@fails the build. If you want SSH locally:Required before merge
Dashboard changes. Builds fail without them:
Follow-ups
Out of scope here:
Summary by CodeRabbit
New Features
Documentation
pnpx regen-apiAPI client generation command.