Skip to content

feat(cli): Route org-scoped SDK requests with @sentry/api resolveBaseUrl - #1979

Open
sentry-junior[bot] wants to merge 2 commits into
mainfrom
feat/cli-resolve-base-url
Open

sentry-junior[bot] wants to merge 2 commits into
mainfrom
feat/cli-resolve-base-url

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Note

Blocked on getsentry/sentry-api-schema#130 and the @sentry/api release that ships it. CI will fail tsc until @sentry/api is bumped in pnpm-workspace.yaml. I'll bump it here once the release is out.

Follow-up to #1978. The routing that #1978 kept in the CLI now uses a per-request hook in @sentry/api. resolveOrgRegion moves out of the call sites and into that hook.

What changes

  • resolveOrgBaseUrl (in lib/api/infrastructure.ts) is the CLI's resolveBaseUrl. When a request's path names an organization, it returns resolveOrgRegion(org). That call picks the stored account that knows the org (on any server, unless one is set explicitly) and returns the org's region. Unscoped paths keep the base URL. All of this runs before the URL is built.
  • getOrgSdkConfig() is now synchronous and takes no org. It sets resolveBaseUrl, so the 55 await getOrgSdkConfig(orgSlug) call sites no longer resolve the region up front. The SDK operation picks the region from its own path. Every one of these call sites uses an org- or project-scoped operation.
  • sentry api (prepareRawApiRequest) uses the same hook. Org-scoped endpoints now go to the org's region (for example https://us.sentry.io), the same way typed commands already do. That replaces the getDefaultSdkConfig({ path }) workaround from fix(cli): Route sentry api org requests to accounts on other servers #1978, which is removed. A full URL is still sent as given.
  • Docs: apps/cli-docs/src/fragments/commands/api.md explains the routing.

Behavior notes

  • When an org's region isn't cached for the chosen account, sentry api organizations/<org>/... now makes one region lookup first (GET /organizations/<org>/), as typed commands do. --dry-run shows the region URL, so it may make that read-only lookup too.
  • The hand-built apiRequestToRegion(await resolveOrgRegion(org), path) call sites (about 25) don't go through the SDK client, so they are unchanged. They can move to the same resolver in a follow-up.

Tests

account-routing.test.ts:

  • New: sentry api sends an org-scoped path to the org's cached region (us.sentry.io). This test fails on main.
  • Updated two tests to expect the region lookup the account makes for an org whose region it hasn't cached.

Checked against a local build of sentry-api-schema#130: CLI tsc and lint pass, and the account-routing, commands/api, and lib/api suites pass (1249 tests). In the full unit suite, the only failures are sandbox-only ones that also fail on main (completions, upgrade, resilient DB, code-scanner, file-changes, and the auth-message tests in errors, oauth, and auto-login-host-guard).

via @BYK.

--

View Session in Sentry

getOrgSdkConfig() and sentry api now set @sentry/api's resolveBaseUrl
(getsentry/sentry-api-schema#130). Each request whose path names an
organization picks its account, server, and region before its URL is
built, through resolveOrgRegion.

- The 55 getOrgSdkConfig(orgSlug) call sites stop resolving the region
  up front. getOrgSdkConfig() is now synchronous and takes no org.
- sentry api sends org-scoped endpoints to the org's region, as typed
  commands do, and drops the getDefaultSdkConfig({ path }) workaround
  from #1978. A full URL is still sent as given.

Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
@vercel

vercel Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
sentry-local Ready Ready Preview Nov 5, 2026 1:05pm UTC

Request Review

@BYK
BYK marked this pull request as ready for review November 5, 2026 12:44
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 5, 2026
1.29.0 ships Config.resolveBaseUrl (getsentry/sentry-api-schema#130), which getOrgSdkConfig() now passes.

This branch was successfully deployed

1 active deployment
Preview — d24efb2b Deployed Nov 5, 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