Repository navigation
feat(cli): add sentry wizard with Next.js - #2519
Conversation
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 <126780+BYK@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
1 Skipped Deployment
|
📊 MCP Server Token Cost ReportSummary
Per-Tool Breakdown
Note: This measures the static overhead of tool definitions sent to LLM clients with every request. Lower is better. MCP Apps viewsEach
The budget applies to raw bytes, and the view's generator fails over it. |
`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 <126780+BYK@users.noreply.github.com>
| export const wizardCommand = buildCommand({ | ||
| auth: false, |
There was a problem hiding this comment.
auth: false without skipRcUrlCheck blocks spotlight and unauthenticated wizard runs
sentry wizard sets auth: false but not skipRcUrlCheck: true, so a self-hosted .sentryclirc URL with no matching credentials throws HostScopeError before the wizard (including --spotlight) can start its own URL/login flow. Add skipRcUrlCheck: true like sentry init.
Evidence
wizardCommandsetsauth: falseso Spotlight and login-less runs are allowed, and docs advertisewizard -i nextjs --spotlight.buildCommandstill runsassertRcUrlTrustedunlessskipRcUrlCheck: trueorauth: "dsn"(lib/command.ts); wizard sets neither.assertRcUrlTrustedthrowsHostScopeErrorwhen.sentryclirchas a non-SaaSdefaults.urland there is no trusted token/account for that host (lib/sentryclirc.ts).- The wizard is supposed to choose the instance itself via
selectSentryUrl/useSentryUrland log in later (lib/wizard/utils/project-data.ts);sentry initusesauth: false+skipRcUrlCheck: truefor the same reason.
Identified by Warden · code-review · YRB-XGC
There was a problem hiding this comment.
Fixed in 39e20d5: sentry wizard now sets skipRcUrlCheck, like sentry init, so --spotlight and runs before login aren't blocked by a .sentryclirc URL.
There was a problem hiding this comment.
Fix attempt detected (commit ac6b75d)
The wizard was modified in a review-fix commit, but it still sets auth: false without skipRcUrlCheck: true, so the preflight trusted-host check can still throw HostScopeError before the wizard starts.
The original issue appears unresolved. Please review and try again.
Evaluated by Warden
| if (!underscoreErrorPageFile) { | ||
| const underscoreErrorFileName = `_error.${ | ||
| typeScriptDetected ? "tsx" : "jsx" | ||
| }`; | ||
|
|
||
| await promises.writeFile( | ||
| path.join(process.cwd(), ...pagesLocation, underscoreErrorFileName), | ||
| getSentryDefaultUnderscoreErrorPage(), | ||
| { encoding: "utf8", flag: "w" }, | ||
| ); |
There was a problem hiding this comment.
Generated _error.tsx fails strict TypeScript checks
For TypeScript projects with noImplicitAny—including the default strict create-next-app configuration—the generated error page has untyped props and contextData callbacks, so next build fails its TypeScript check.
Evidence
- When no pages
_errorfile exists,nextjs-wizard.tswrites_error.tsxiftypeScriptDetectedis true and suppliesgetSentryDefaultUnderscoreErrorPage()as its contents. - That template declares
CustomErrorComponent = (props) =>and assignsgetInitialProps = async (contextData) =>; neither parameter is typed or contextually typed, sonoImplicitAnyreports errors. The property assignment also fails type checking for the inferred function type. isUsingTypeScript()detects atsconfig.json; a normal strict Next.js project includes this generated.tsxpage in its build type check, so the failure is reachable.
Also found at 1 additional location
packages/cli/src/lib/wizard/nextjs/templates.ts:600-619
Identified by Warden · code-review · RVU-2QF
There was a problem hiding this comment.
This matches upstream sentry-wizard 9.1.0 and is out of scope for this port.
| const apiRouteFileName = `sentry-example-api.${ | ||
| typeScriptDetected ? "ts" : "js" | ||
| }`; | ||
|
|
||
| await promises.writeFile( | ||
| path.join(process.cwd(), ...pagesFolderLocation, "api", apiRouteFileName), | ||
| getSentryExamplePagesDirApiRoute({ | ||
| isTypeScript: typeScriptDetected, | ||
| }), | ||
| { encoding: "utf8", flag: "w" }, | ||
| ); | ||
|
|
There was a problem hiding this comment.
Pages example API handler parameters cause strict TypeScript build errors
For a TypeScript Pages Router project with noImplicitAny, the wizard generates an API handler with untyped parameters, so a normal next build fails until the generated file is fixed.
Evidence
isUsingTypeScript()returns true when the project has atsconfig.json; the Pages Router flow then writes a.tsAPI route using this template.- The template adds a type only to the error constructor’s
messageparameter;_reqandresremain unannotated and have no contextual types. - With
noImplicitAnyenabled, TypeScript reports implicit-anyerrors for the handler parameters, which the normal Next.js build typecheck includes. - The template test for
isTypeScript: trueexplicitly expects the untyped handler declaration, so it does not catch the build failure.
Also found at 1 additional location
packages/cli/src/lib/wizard/nextjs/templates.ts:536-539
Identified by Warden · code-review · VVV-VEW
There was a problem hiding this comment.
This matches upstream sentry-wizard 9.1.0 and is out of scope for this port.
- 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 <126780+BYK@users.noreply.github.com>
BYK
left a comment
There was a problem hiding this comment.
This adds one dependency: magicast@0.2.11, which brings recast. They stay until the config edits move to the shared flow in #2510.
What is recast and why do we need it?
Telemetry goes through the CLI's Sentry client. --disable-telemetry turns it off for the run.
Don't add any new flags etc for this. Sentry CLI already has ways to disable telemetry, we should just keep using what is existing.
sentry wizard takes the @sentry/wizard integration ids and flags: -i/--integration, -u/--url, --org, --project, --saas, --spotlight, --force-install, --ignore-git-changes, --disable-telemetry and --debug. The legacy --skip-connect, --quiet and --uninstall are accepted as hidden no-ops so old command lines still run. SENTRY_WIZARD_INTEGRATION, SENTRY_WIZARD_URL and SENTRY_WIZARD_DEBUG still work; a flag wins over its env var.
Make sure these follow the CLI conventions. It's clear for instance that --org or --project doesn't as we have the org/project notation everywhere and it is required. --spotlight is replaced by sentry local now. If this is to set the SENTRY_SPOTLIGHT env var, it still is the canonical value.
Drop any SENTRY_WIZARD_ env var support.
No idea what --url or --saas or --force-install are. We have -f/--force for everything already so use that instead of --force-install if it makes sense. Definitely don't want --debug. Skeptical about -i/--integration as I don't think it needs to be a flag if it is required? We can probably use a positional arg with comma separation? There are examples of this in the CLI codebase.
Do not add legacy flags at all, even as hidden.
Apply these decisions to the entire stack and any future related work and try to enforce them with tests, lint rules, and scripts.
recast is a JS/TS parser and printer. When it writes a file back, it reprints only the AST nodes that changed, so the rest of the file keeps its formatting and comments. This PR doesn't import it directly. It comes in through magicast, which is built on it. The Next.js flow uses magicast ( |
`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 <126780+BYK@users.noreply.github.com>
|
Reworked in ac6b75d4. The command line is now: Point by point:
Target vs integration. A value with a Enforcement.
One CLI-wide thing I didn't touch: The docs fragment and the generated skill docs describe the new syntax, with a table that maps each |
| clack.log.warning( | ||
| `Failed to add auth token to ${chalk.bold.cyan( | ||
| SENTRY_DOT_ENV_FILE, | ||
| )}. Uploading source maps during build will likely not work locally.`, | ||
| ); | ||
| } | ||
| } | ||
| } else { | ||
| try { | ||
| await promises.writeFile(dotEnvFilePath, envVarContent, { | ||
| encoding: "utf8", | ||
| flag: "w", | ||
| }); | ||
| clack.log.success( | ||
| `Created ${chalk.bold.cyan( | ||
| SENTRY_DOT_ENV_FILE, | ||
| )} with auth token for you to test source map uploading locally.`, | ||
| ); | ||
| } catch { | ||
| clack.log.warning( |
There was a problem hiding this comment.
clack.log.warning throws on env file write failure
clack.log.warning is not a @clack/prompts method (the API is warn); when writing .env.sentry-build-plugin fails, the catch path throws TypeError and crashes the wizard instead of showing the write-failure message.
Evidence
@clack/promptsis re-exported asclack.loginprompts.ts; every other call site in this module usesclack.log.warn(e.g. lines 613, 630, 660, 724).- The test mock in
test/lib/wizard/utils/clack/index.test.tsonly stubslog.warn, notlog.warning, matching the real package API. addDotEnvSentryBuildPluginFileis called fromnextjs/nextjs-wizard.ts; its writeFilecatchblocks at lines 743 and 762 callclack.log.warning(...).wizard.tsrethrows any non-WizardExitError, so the TypeError aborts the run and skipsaddCliConfigFileToGitIgnore.- The same typo appears in the unused
addSentryCliConfigcatch at line 601.
Identified by Warden · code-review · 7JF-3P4
|
|
||
| const changedOrUntrackedFiles = | ||
| getUncommittedOrUntrackedFilePaths().filter(Boolean); | ||
|
|
||
| return changedOrUntrackedFiles.length ? changedOrUntrackedFiles : null; | ||
| } |
There was a problem hiding this comment.
getFormatterTargetFiles feeds deleted paths to Prettier
Deleted uncommitted paths are passed to formatters, so Prettier exits non-zero and runFormatters stops early with a warning instead of formatting the remaining files.
Evidence
getUncommittedOrUntrackedFilePaths()pushes every porcelain path and never filtersDstatuses (git.ts).getFormatterTargetFiles()only does.filter(Boolean), so deleted paths stay in the target list.runFormatters()runs Prettier withignoreExitCode: false, so a missing path rejects and hits the catch, skipping later Biome runs.- Dirty-repo continue /
--ignore-git-changesmakes pre-existing deletions a reachable input when the user agrees to format.
Identified by Warden · code-review · 9FN-E7A
…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 <126780+BYK@users.noreply.github.com>
BYK
left a comment
There was a problem hiding this comment.
sentry wizard [/] []: the target comes first, like other commands, and both are optional. The integration takes the @sentry/wizard -i ids, one at a time; without it the picker runs. The target uses the CLI's org/project syntax and resolves after login like other commands' targets; without it the org and project pickers run, with no detection. A bare integration id is never read as a target and a single bare word is always read as an integration, so a project spelled like one is written my-org/nextjs
This is using our established global target parser, right?
|
Yes for the target itself. The wizard parses it with the shared |
Stacked on #2519. Tracking issue: #2511. Nine of the remaining sentry-wizard flows (SvelteKit, Remix, React Router, Angular, Nuxt, source maps, Cloudflare, React Native, Android) use the same two helpers. Landing them here, once, lets those platform PRs stack on this one in parallel without each one re-adding the same files. - `src/lib/wizard/utils/ast-utils.ts`: finds and edits nodes in recast ASTs and reads and writes JSON-C. It's ported from sentry-wizard with strict types (`unknown` in place of `any`), and invalid JSON-C now goes to the wizard's debug log instead of being dropped. - `src/lib/wizard/utils/url.ts`: builds the issue stream URL the wizards print once setup finishes. - Its tests are ported to `test/lib/wizard/utils/ast-utils.test.ts`. `recast` and `ast-types` become direct dev dependencies. Both already came in through magicast, so nothing new is bundled. They stay until the wizard's config edits move to the shared `init`/`wizard` flow in #2510. <!-- junior-request-attribution:start --> via @BYK. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:agent%3A23ba814e02fcece5f64e00f096d03341 --> -- [View Session](https://junior-prod.sentry.dev/conversations/agent%3A23ba814e02fcece5f64e00f096d03341) [[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A23ba814e02fcece5f64e00f096d03341/?project=4510944073809921) <!-- junior-session-footer:end --> --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: BYK <126780+BYK@users.noreply.github.com>
#2519 was squash-merged into main, so this takes main's side for every file the pre-squash #2519 commits added. main also turned the standalone npm libraries into one `packages/{http,logger}` Craft workspace that merge-jobs.yml discovers and packs. The forwarder joins it as `packages/{http,logger,wizard}` and gets a `wizard` product in release.yml, and merge-jobs.yml is main's, unchanged. Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
…in (#2559) #2548 removed `isRequestOriginTrusted` while #2519 still used it in the wizard's login check, so `main` no longer builds. This uses `isRequestOriginTrustedForContext` with `getCredentialContext()`, the same check the removed helper did. Behaviour doesn't change. <!-- junior-request-attribution:start --> via @BYK. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:agent%3A2b65e7fbe80bb65b0774094cf19fc343 --> -- [View Session](https://junior-prod.sentry.dev/conversations/agent%3A2b65e7fbe80bb65b0774094cf19fc343) [[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A2b65e7fbe80bb65b0774094cf19fc343/?project=4510944073809921) <!-- junior-session-footer:end --> Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: BYK <126780+BYK@users.noreply.github.com>
#2519 and #2520 were squash-merged into main, so this branch's base is now main. The add/add conflicts came from the squashed wizard files. main's copies of run.ts and test/commands/wizard.test.ts equal f0a48de, which this branch already merged, so this branch's Android and Flutter additions are kept. project-data.ts and its test take main's copy, which has the #2559 fix for the origin trust check. Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
#2519 and #2520 were squash-merged, so this PR's base is now main. Resolved the add/add conflicts: run.ts keeps this branch's runner registrations (main's copy equals the old base), and project-data.ts and its test take main's copy, with the #2559 context-scoped origin trust fix (this branch didn't change them). Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
Gets `main` ready for a GitHub merge queue. #2548 removed `isRequestOriginTrusted`, then #2519 merged still importing it and broke `main`. Each PR was fine on its own; a merge queue tests them together. Same approach as getsentry/junior#4469 and getsentry/junior#4533. Merge queue entries skip the per-project matrix. The `quality` job typechecks, builds, and policy-checks the whole workspace instead, which is what two PRs can break together. The `test` aggregator already accepts the skipped jobs. `SENTRY_AUTH_TOKEN` stays off the `quality` job on purpose: when it's set, `@sentry/mcp-cloudflare`'s Vite plugin creates a Sentry release. ## Follow-up (admin) After this merges, a toolkit admin adds a `merge_queue` rule to the repo's `Default` ruleset (id 5058262), with Junior's values: SQUASH, max 5 entries to build, 1 to 5 entries to merge, 5 minute wait, ALLGREEN grouping, 60 minute check timeout, and `test` as the required status. First, confirm the Craft release bot (`sentry-release-bot`) is in the ruleset's `bypass_actors`, because it pushes merge-backs straight to `main`. No getsentry/security-as-code change is needed. <!-- junior-request-attribution:start --> via @BYK. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:agent%3A3843e79a6a769b421c483201d98d7d4e --> -- [View Session](https://junior-prod.sentry.dev/conversations/agent%3A3843e79a6a769b421c483201d98d7d4e) [[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A3843e79a6a769b421c483201d98d7d4e/?project=4510944073809921) <!-- junior-session-footer:end --> Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: BYK <126780+BYK@users.noreply.github.com>
Before v4.0.0, the setup wizards of getsentry/sentry-wizard move into the CLI as
sentry wizard, so there is one tool, one login and one telemetry client, and the wizards call v4sentrycommands instead of sentry-cli v2. Tracking issue: #2511 (part of #1965). This is the first PR in that stack: the command, its login, and the Next.js flow.Changes
sentry wizard [<org>/<project>] [<integration>]: the target comes first, like other commands, and both are optional. The integration takes the@sentry/wizard -iids, one at a time; without it the picker runs. The target uses the CLI's org/project syntax and resolves after login like other commands' targets; without it the org and project pickers run, with no detection. A bare integration id is never read as a target and a single bare word is always read as an integration, so a project spelled like one is writtenmy-org/nextjs.-f/--forceis the only flag: it changes a project with uncommitted changes without asking and force-installs the SDK. Everything else comes from the CLI: the instance fromSENTRY_URLor the stored login, Spotlight mode fromSENTRY_SPOTLIGHT, telemetry from the CLI's settings, and debug output from--verbose/--log-level. No other@sentry/wizardflag orSENTRY_WIZARD_*variable is accepted, hidden or not; a test pins the flags andci:policyrejectsSENTRY_WIZARD_underpackages/cli/src.-s/--signup,--promo-codeand--coming-fromfail as unknown flags, because the CLI's login has no sign-up or partner step.promoCode/comingFromare gone from the wizard options, the welcome banner and the CI step.src/lib/wizard/nextjs/, with its tests. Each flow loads lazily. The picker lists only ported flows, and naming an unported integration says it isn't available in this version yet. Cordova and Electron are dropped along with sentry-wizard'slib/.src/lib/wizard/utils/. A small pnpm catalog reader replaces js-yaml.account/settings/wizard/<hash>browser flow: the storedsentry auth loginsession, an agent handoff fromSENTRY_HANDOFF, or the device flow withorg:ciandorg:tokens. The wizard then picks the org, picks or creates the project for the flow's platform, reads its DSN, and creates an org auth token for source map uploads. If it can't create a token, for example when there's no TTY to add scopes, it writes the placeholder token and says so.sentry-clibinary needed. The wizard runs inside the CLI, so it never installs or checks forsentry-cli; the oldget-cli+sentry-cli --versioncheck isn't ported.SENTRY_CLI_NO_TELEMETRY,DO_NOT_TRACK,sentry cli defaults).sentry initstill prints the agent setup guide. Its help points tosentry wizard, and the wizard's help points back toinit. Merging the two is Unify thesentry initandsentry wizardsetup flows #2510, after v4.This adds one dependency:
magicast@0.2.11, which brings recast. They stay until the config edits move to the shared flow in #2510.Breaking for
@sentry/wizardusers: the command line changes tosentry wizard [<org>/<project>] [<integration>]with only-f/--force. Every other@sentry/wizardflag, including--signup,--promo-codeand--coming-from, now fails as an unknown flag,SENTRY_WIZARD_*variables are ignored, and the Cordova and Electron wizards are gone.Rest of the stack
sentrycommandsvia @BYK.
--
View Session [Sentry]