Skip to content

fix(cli): instrument new Cloudflare workers and harden the Wrangler flow - #2563

Open
sentry-junior[bot] wants to merge 50 commits into
mainfrom
feat/cli-wizard-sourcemaps-cloudflare-fixes
Open

sentry-junior[bot] wants to merge 50 commits into
mainfrom
feat/cli-wizard-sourcemaps-cloudflare-fixes

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #2529 (merged): behaviour changes against upstream sentry-wizard 9.1.0.

Behaviour changes against sentry-wizard 9.1.0

  • Cloudflare, missing main file (SHJ-RG7): when Wrangler's main points to a file that doesn't exist, the wizard creates the starter worker there and wraps it. Upstream skipped setup silently and still reported success.
  • Cloudflare, no main (YBF-MLA): the starter worker written to src/index.ts is now wrapped with Sentry.withSentry(). Upstream wrote a plain worker with no Sentry.
  • Cloudflare, existing src/index.ts with no main: the existing file is wrapped instead of being overwritten by the starter worker.
  • Cloudflare, empty main in wrangler.json: treated as no main, so the starter worker goes to src/index.ts, which the config then points to. Upstream tried to wrap the project directory and pointed the config at a file it never created.
  • Cloudflare, wrap message: "Wrapped … with Sentry initialization" shows only when the wizard wrapped the worker. When Sentry is already set up, only the skip warning shows. When the entry point has no export default, the file is left unchanged and the manual wrap instructions show. Upstream reported the wrap in both cases, and added an unused Sentry import to a file with no default export.
  • Cloudflare, wrangler.toml (WHX-UYU): the copy-paste snippet includes main = "src/index.ts" when the wizard sets main. Upstream left it out.
  • webpack, non-array plugins (UNB-FTW): plugins: existingPlugins or plugins: getPlugins() becomes [...existingPlugins, sentryWebpackPlugin(…)]. Upstream replaced the value and dropped those plugins. undefined and null are still replaced.
  • Wrangler, existing post<deploy> (5YD-7F8): an existing post<deploy> script is kept, with && <pm> sentry:sourcemaps added after it. Upstream overwrote it. It's left alone when it already runs sentry:sourcemaps.
  • Wrangler, Yarn 2+ (RP5-3PG): Yarn Berry doesn't run post scripts, so the upload is chained onto the deploy script (&& yarn sentry:sourcemaps). npm, pnpm, Yarn 1 and Bun keep the post<deploy> hook. When the wizard can't edit the deploy script, it leaves that script alone and ends the manual deploy command with the upload instead.
  • Wrangler, no deploy script (5WP-827): the wizard still writes sentry:sourcemaps, the .sentryclirc upload target and the auth token, then shows the deploy command to add. Upstream stopped before writing any of them and still reported success.
  • Wrangler, wrapped commands (HJA-K3Y): deploy scripts where npx, pnpm, yarn or bunx comes straight before wrangler deploy are now edited. Upstream accepted only a bare wrangler deploy. Any other form, such as runner flags (-y, -C, --cwd), pnpm exec / dlx, bun x, wrangler@<version>, cross-env or a leading VAR=value, gets the manual instructions.
  • Wrangler, manual fallback: when the wizard can't edit the deploy script, it shows wrangler deploy with the --outdir, --var SENTRY_RELEASE:… and --upload-source-maps flags. Upstream showed the unchanged script.
  • Source maps, framework redirect (YSZ-BFQ): the SvelteKit and React Native redirect is offered only when this CLI version has that wizard. Without it, the wizard shows the framework's guides and asks whether to continue or exit, instead of throwing ValidationError once the redirect is accepted. SvelteKit shows up again on its own once its runner lands.
  • Cloudflare, missing .js or .mjs main: the starter worker written there is plain JavaScript. Only TypeScript entry points get the typed starter.
  • Wrangler, deploy text earlier in the script (EL5-RSX): the flags go on the real wrangler deploy command, not on earlier text that matches it, such as echo Running wrangler deploy. Upstream edited the first match.
  • Wrangler, rerun: a deploy script that already sets SENTRY_RELEASE doesn't get a second --var SENTRY_RELEASE:…. Upstream added one on every run.
  • Cloudflare, existing compatibility_date: the Worker's date is kept, and today's date is only added when the config has none. The TOML snippet marks it "only if not set yet". Upstream always overwrote it with today's date.
  • Wrangler, pages deploy and versions deploy: these aren't treated as a Workers deploy, bare or through a runner, so they don't get the Workers-only flags that would break them. The wizard shows the manual instructions instead. Upstream edited a bare wrangler pages deploy or wrangler versions deploy.

Product calls

  • Wrapping with withSentry: follows the Wrangler install guide and the existing wrap path for configured entry points.
  • post<deploy> hook, merged rather than overwritten: the Wrangler source maps guide uses a postdeploy hook, so that stays the default. An existing hook is kept, the way the other flows keep user scripts.
  • && chaining for Yarn 2+ only: matches how the sentry-cli flow attaches sentry:sourcemaps to the build script. Other package managers keep the hook from the docs.
  • Warn, not fail, with no deploy script: matches the sentry-cli flow, which writes the script and config and then shows what to add by hand.
  • Wrapped npx / pnpm / yarn / bunx deploy commands: the new flags go after the wrangler deploy segment, as they do for a bare command.

via @BYK.

--

View Session [Sentry]

sentry-junior Bot and others added 23 commits November 26, 2026 11:48
Start moving getsentry/sentry-wizard into the CLI as `sentry wizard`.
This adds the command with the `@sentry/wizard` integrations and flags
(`-i`, `--url`, `--org`, `--project`, `--saas`, `--spotlight`, and the
rest), the shared wizard helpers, and the Next.js flow. The other
integrations report that they are not available in this version yet.

The wizard logs in with the CLI's own login: a stored `sentry auth
login` session, an agent handoff, or the device flow, instead of the
`account/settings/wizard/<hash>` browser flow. It then picks or creates
the project, reads its DSN, and creates an org auth token for source map
uploads. Telemetry goes through the CLI's client.

`sentry init` stays the agent setup guide; its help now points to
`sentry wizard` for the interactive setup.

Co-Authored-By: BYK <[email protected]>
Port `ast-utils` and `url` from getsentry/sentry-wizard into
`src/lib/wizard/utils/`. The SvelteKit, Remix, React Router, Angular,
Nuxt, source maps, Cloudflare, React Native and Android wizards all use
them, so they land once here and the platform PRs that follow build on
them in parallel.

`ast-utils` edits recast ASTs, so recast and ast-types become direct
dev dependencies; both already came in through magicast.

Co-Authored-By: BYK <[email protected]>
`sentry wizard` logs in with the CLI's login, which has no sign-up or
partner step, so `--signup`, `--promo-code` and `--coming-from` no longer
do anything. Passing one now fails with a message that points to
https://sentry.io/signup/ instead of being accepted silently.

`promoCode` and `comingFrom` leave `WizardOptions`, the welcome banner and
`setupCI`, which loses its Vercel partner branch. The help text and the
docs say which `@sentry/wizard` flags were removed.

Co-Authored-By: BYK <[email protected]>
Port the source maps wizard (all build tools) and the Cloudflare Workers
wizard from sentry-wizard 9.1.0 into `sentry wizard`, with their tests,
and register `sourcemaps` and `cloudflare` in WIZARD_RUNNERS.

The generated projects now use the v4 `sentry` CLI instead of sentry-cli
v2: the wizard installs the `sentry` npm package and writes
`sentry sourcemap inject/upload` and `sentry release create` scripts.
`.sentryclirc` stays, since v4 still reads it. A self-hosted URL is passed
in `SENTRY_URL`, which replaced the sentry-cli `--url` flag.

`sourcemaps/ci.ts` gains the step that asks to run the `sentry:sourcemaps`
script in CI. The Cloudflare test fixtures keep their upstream bytes, so
the formatter, linter and test typecheck skip wizard fixtures.

Co-Authored-By: BYK <[email protected]>
…sourcemaps-cloudflare

Picks up the removed sign-up and partner flags. The source maps and
Cloudflare wizards no longer pass `promoCode` to `printWelcome`, and
`setupCI` loses the `comingFrom` argument. The `sourcemaps/ci.ts`
conflict is resolved to the shared version from
#2525.

Co-Authored-By: BYK <[email protected]>
Generated `sentry` commands no longer pass the hidden `--org` and
`--project` compat flags. The generic and Wrangler source maps flows
merge `org` and `project` into the project's `.sentryclirc` `[defaults]`,
next to the existing `[auth] token` and any other keys, and v4 reads them
from there. Wrangler's `sentry:sourcemaps` script drops the `SENTRY_URL=`
prefix and the flags from `sentry release create` and
`sentry sourcemap upload`.

The self-hosted URL is not written to the file. v4 only trusts a non-SaaS
`[defaults] url` when the token's host or a stored login vouches for it,
and a token from the same file does not, so the upload would be refused.
Self-hosted users are told to set `SENTRY_URL` instead.

`setupCI` gets the upload target, so the CI step lists `SENTRY_AUTH_TOKEN`,
`SENTRY_ORG`, `SENTRY_PROJECT` and, for self-hosted, `SENTRY_URL`. Wrangler
counts as a `sentry`-command tool there (its token lives in `.sentryclirc`),
but skips the "run the script in CI" prompt, since its `post<deploy>`
script already runs it.

`sentry@^4` is installed as a devDependency. `sourcemaps/ci.ts`,
`sourcemaps/tools/sentry-cli.ts`, `angular.ts`, `types.ts` and
`abort-if-sportlight-not-supported.ts` now match #2525,
apart from exporting `addOrgAndProjectToSentryCliRc` for Wrangler, the
devDependency install, and the Wrangler CI case.

Co-Authored-By: BYK <[email protected]>
The Cloudflare wizard fixtures are upstream sentry-wizard Worker sources
that `wrap-worker` and `update-wrangler-config` tests read and compare as
text. The test tsconfig excludes them, so the tsconfig policy check needs
them in its list of files no type check covers on purpose.
- Skip the `.sentryclirc` URL check, like `sentry init`: the wizard picks
  its instance (`--url`, `--saas` or a prompt) before it logs in.
- Use the stored login's instance for `sentryUrl` when none was chosen,
  and log in again when the stored login is for another instance.
- Link self-hosted users to `/settings/<org>/auth-tokens/`.
- Leave an unparseable MCP config alone (show the copy-paste fallback),
  and let a cancel inside the MCP setup stop the wizard.
- Resolve `catalog:` and `catalog:default` against both pnpm default
  catalog forms.
- Find an existing `SENTRY_AUTH_TOKEN` after the comment header of
  `.env.sentry-build-plugin`, so re-runs don't add a second one.
- Run Windows formatters with Node in the standalone binary, where
  `process.execPath` is `sentry`.
- Ask before updating an `@sentry/nextjs` listed in devDependencies, and
  treat an unknown SDK version as the `^11` the wizard installs.

Co-Authored-By: BYK <[email protected]>
On self-hosted Sentry, the generic and Wrangler source maps flows now
write `url` to `.sentryclirc` `[defaults]` next to `org` and `project`.
v4 rejects that URL from the same file as the token today. The trust
check fix is separate, and the generated script depends on it.

The CI step on sentry.io now lists only `SENTRY_AUTH_TOKEN`. On
self-hosted Sentry it also lists `SENTRY_ORG`, `SENTRY_PROJECT` and
`SENTRY_URL`. The wizard docs fragment says the same.

Co-Authored-By: BYK <[email protected]>
Address review feedback on the shared wizard helpers:

- Enable unicorn/no-array-for-each repo-wide and convert every
  .forEach call site to for...of, including getLastRequireIndex.
- Add buildProjectIssuesUrl to lib/sentry-urls.ts, built on
  getOrgBaseUrl like buildEventSearchUrl, and delete the
  wizard-specific wizard/utils/url.ts.
- Move findFile into lib/dsn/fs-utils.ts and build it on
  isRegularFile, so a directory or FIFO with a matching name is
  skipped. It is async now.

Co-Authored-By: BYK <[email protected]>
`sentry wizard [<org>/<project>] [<integration>]` replaces the
`@sentry/wizard` flags, with the target first like other commands.

- The integration is a positional, one at a time. A bare integration id
  is never read as a target, and a single bare word is always read as an
  integration, so a project or org spelled like one is written
  `my-org/nextjs`, `nextjs/` or `/nextjs`.
- The target parses with the CLI's org/project grammar and resolves after
  login with `resolveOrgOptionalTarget`, like other commands. Without one
  the org and project pickers run, with no detection.
- `-f/--force` is the only flag. It sets both `forceInstall` and
  `ignoreGitChanges`.
- The instance comes from `SENTRY_URL` or the stored login, so the
  SaaS/self-hosted prompt, `--url`, `--saas` and `skipRcUrlCheck` go.
- Spotlight mode follows `SENTRY_SPOTLIGHT`, telemetry follows
  `isTelemetryEnabled()`, and debug output goes through the CLI logger
  (`--verbose`, `--log-level`).
- Every other `@sentry/wizard` flag and `SENTRY_WIZARD_*` variable is
  gone, hidden ones included, with `disableTelemetryForRun` and
  `rejectRemovedFlags`.

A test pins the wizard's own flags to `force`, and `check:env-coverage`
(part of `ci:policy`) fails when any file under `src/` names
`SENTRY_WIZARD_`.

Co-Authored-By: BYK <[email protected]>
Re-export buildProjectIssuesUrl from lib/sentry-web-urls.ts through
withSentryBaseUrl(getApiBaseUrl()), like the other user-facing link
builders, so self-hosted and regional logins get links on the host they
are authenticated against.

Co-Authored-By: BYK <[email protected]>
…izard base

Merges origin/feat/cli-wizard-shared-ast-helpers at f0a48de (#2520, the
chart-app fix and #2519's positional rework) and fixes what it breaks:

- `runWizard` no longer takes `debug`, so the redirect to another wizard
  drops it.
- `wizard/utils/url.ts` is gone. The source maps outro links to the
  project's issues with `buildProjectIssuesUrl` from `lib/sentry-web-urls`.
- `findFile` now comes from `lib/dsn/fs-utils` and is async, so the tsc,
  Vite and webpack tools await it.
- The new `no-array-for-each` lint rule: two `forEach` loops become
  `for...of`.
- The wizard docs fragment keeps the base's flag table and the source maps
  paragraph from this branch.

Co-Authored-By: BYK <[email protected]>
…already runs it

When the production build script already ends with `sentry:sourcemaps`,
`addSentryCommandToBuildCommand` left `addedToBuildCommand` false, so
`setupNpmScriptInCI` still asked for a separate CI step and the upload
would run twice. That branch now sets the flag too.

Co-Authored-By: BYK <[email protected]>
Takes `sourcemaps/tools/sentry-cli.ts` and its test from
#2525 (f5ca46e) as they are, so both PRs carry the same
copy. Its `.sentryclirc` writer is `addUploadTargetToSentryCliRc`, so the
Wrangler tool and the `.sentryclirc` defaults test call it by that name.

Co-Authored-By: BYK <[email protected]>
…emaps-cloudflare

Co-Authored-By: BYK <[email protected]>

# Conflicts:
#	apps/cli-docs/src/fragments/commands/wizard.md
#	packages/cli/src/lib/wizard/run.ts
#	packages/cli/src/lib/wizard/sourcemaps/ci.ts
#	packages/cli/src/lib/wizard/utils/project-data.ts
#	packages/cli/test/lib/wizard/utils/project-data.test.ts
#	scripts/tsconfig-policy.test.mjs
Takes `sourcemaps/tools/sentry-cli.ts`, `sourcemaps/tools/angular.ts` and
their tests from #2525 (370f74d) unchanged, so both PRs
carry the same copies. This brings in the Angular snippet that sets
`sourceMap` in the production configuration and the `forceInstall` option
for the `sentry` install.

Co-Authored-By: BYK <[email protected]>
Fixes bugs carried over from sentry-wizard 9.1.0 that Warden and Bugbot
found on review, without changing how the flows work:

- Cloudflare: offer the data collection prompt when the installed SDK
  version is unknown, using the `^11` range the wizard installs
- Cloudflare: stop the TOML `main` match at the closing quote
- Vite: recognize quoted `build` and `sourcemap` keys, using the shared
  `getObjectProperty` helper
- Webpack: link the webpack docs when creating a new config
- Create React App: name the `GENERATE_SOURCEMAP` variable, and detect
  CRA from `react-scripts`
- Wrangler: exit when the user keeps an existing `sentry:sourcemaps`
  script, as the prompt says, and read `--outdir` values after several
  spaces
Changes how the ported source maps and Cloudflare wizards behave where
sentry-wizard 9.1.0 left a project half set up:

- Cloudflare: create a missing entry point where Wrangler's `main` points,
  and wrap new and existing workers with `Sentry.withSentry()`
- Cloudflare: show `main` in the wrangler.toml snippet when it is added
- webpack: keep a non-array `plugins` value by spreading it
- Wrangler: keep an existing `post<deploy>` script, chain the upload onto
  the deploy script for Yarn 2+, and still set up the upload script and
  CLI config when no deploy script is picked
- Wrangler: edit deploy scripts that run wrangler through npx, pnpm exec,
  yarn, bunx, or cross-env, and show the flags to add when it can't
- Source maps: offer the SvelteKit or React Native wizard only when this
  version has it
@sentry-junior
sentry-junior Bot requested a review from BYK November 27, 2026 17:14
@sentry-junior
sentry-junior Bot added this pull request to stack #2564 November 27, 2026 17:14
@vercel

vercel Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cli Ready Ready Preview Nov 28, 2026 1:55am UTC
1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Nov 28, 2026 1:55am UTC

Request Review

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

An empty `main` in wrangler.json(c) was returned as the entry point, so
the wizard tried to wrap the project directory while the config update
wrote `src/index.ts`, a file it never created. Return undefined, as the
TOML branch already does, so the starter worker goes to `src/index.ts`.
…emaps-cloudflare

# Conflicts:
#	packages/cli/src/lib/wizard/run.ts
#	scripts/tsconfig-policy.test.mjs
The wizard installed `sentry@^4`, which matches no published version, so
source map setup stopped after the SDK and config changes. Install the
major of the running CLI instead (`[email protected]` today), with no shell
metacharacters, since installPackage runs the package manager through a
shell.
The Wrangler flow still installed `sentry@^4`, which matches no published
version, and `^` is a shell metacharacter for installPackage. Use
SENTRY_CLI_PACKAGE_SPEC, as the generic flow does.
…zard-sourcemaps-cloudflare-fixes

# Conflicts:
#	packages/cli/src/lib/wizard/sourcemaps/tools/wrangler.ts
#	packages/cli/test/lib/wizard/sourcemaps/tools/wrangler-flow.test.ts

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 61f2654. Configure here.

The wizard logged "Wrapped … with Sentry initialization" whenever
wrapWorkerWithSentry returned, including when Sentry was already set up
and the wrap was skipped, and when the file had no default export, where
it only added an unused import. Return whether it wrapped, and throw for
a file with no default export, leaving it unchanged, so the wizard shows
the manual wrap instructions instead.
…'t be edited

When the wizard can't add the source map flags to the chosen deploy
script, it shows a manual `wrangler deploy` command. For Yarn 2+, which
doesn't run `post` scripts, it still chained the upload onto that same
script, so replacing the script with the manual command dropped the
upload. For Yarn 2+, leave the script alone and end the manual command
with the upload instead.
@vercel
vercel Bot temporarily deployed to Preview – sentry-local November 28, 2026 00:19 Inactive
Base automatically changed from feat/cli-wizard-sourcemaps-cloudflare to main November 28, 2026 01:07
…emaps-cloudflare-fixes

Co-Authored-By: BYK <[email protected]>

# Conflicts:
#	packages/cli/src/lib/wizard/cloudflare/cloudflare-wizard.ts
#	packages/cli/src/lib/wizard/cloudflare/sdk-setup.ts
#	packages/cli/src/lib/wizard/cloudflare/templates.ts
#	packages/cli/src/lib/wizard/cloudflare/wrangler/get-entry-point-from-wrangler-config.ts
#	packages/cli/src/lib/wizard/cloudflare/wrangler/update-wrangler-config.ts
#	packages/cli/src/lib/wizard/cloudflare/wrap-worker.ts
#	packages/cli/src/lib/wizard/sourcemaps/ci.ts
#	packages/cli/src/lib/wizard/sourcemaps/tools/webpack.ts
#	packages/cli/src/lib/wizard/sourcemaps/tools/wrangler.ts
#	packages/cli/src/lib/wizard/sourcemaps/utils/other-wizards.ts
#	packages/cli/test/lib/wizard/cloudflare/__snapshots__/wrap-worker.test.ts.snap
#	packages/cli/test/lib/wizard/cloudflare/cloudflare-wizard.test.ts
#	packages/cli/test/lib/wizard/cloudflare/get-entry-point-from-wrangler-config.test.ts
#	packages/cli/test/lib/wizard/cloudflare/sdk-setup.test.ts
#	packages/cli/test/lib/wizard/cloudflare/update-wrangler-config.test.ts
#	packages/cli/test/lib/wizard/cloudflare/wrap-worker.test.ts
#	packages/cli/test/lib/wizard/sourcemaps/tools/webpack.test.ts
#	packages/cli/test/lib/wizard/sourcemaps/tools/wrangler-flow.test.ts
#	packages/cli/test/lib/wizard/sourcemaps/tools/wrangler.test.ts

This branch was successfully deployed

1 active and 1 inactive deployments
Preview – cli — 1474145f Deployed Nov 28, 2026 by vercel[bot]
Preview – sentry-local — 1474145f Deployed Nov 28, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant