From 33039666b5407ec07e4296013e359c511a558315 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Mon, 30 Nov 2026 09:40:20 +0000 Subject: [PATCH] fix(cli): Use org-scoped issue routes in sentry api examples The help and skill examples used the unscoped issues// route. Sentry deprecated it for cell routing and pins it to one region, so it 404s for organizations hosted elsewhere and 410s during deprecation brownouts. Switch the examples to organizations/my-org/issues//, and print a hint with the org-scoped form when an unscoped issue route returns 404 or 410. Fixes #2589 Co-Authored-By: BYK <126780+BYK@users.noreply.github.com> --- .../skills/sentry-cli/references/api.md | 8 ++-- packages/cli/src/commands/api.ts | 41 +++++++++++++++++-- packages/cli/test/commands/api.test.ts | 25 +++++++++++ 3 files changed, 66 insertions(+), 8 deletions(-) diff --git a/packages/cli/plugins/sentry-cli/skills/sentry-cli/references/api.md b/packages/cli/plugins/sentry-cli/skills/sentry-cli/references/api.md index 0ff1fed66..6908bb6c5 100644 --- a/packages/cli/plugins/sentry-cli/skills/sentry-cli/references/api.md +++ b/packages/cli/plugins/sentry-cli/skills/sentry-cli/references/api.md @@ -49,22 +49,22 @@ sentry api organizations/ -f per_page=2 --cursor next --json sentry api organizations/ -f per_page=2 --cursor prev --json # Get a specific issue -sentry api issues/123456789/ +sentry api organizations/my-org/issues/123456789/ # Create a release sentry api organizations/my-org/releases/ -X POST -F version=1.0.0 # Update an issue status -sentry api issues/123456789/ -X PUT -F status=resolved +sentry api organizations/my-org/issues/123456789/ -X PUT -F status=resolved # Send an inline JSON body -sentry api issues/123456789/ -X PUT -d '{"status":"resolved"}' +sentry api organizations/my-org/issues/123456789/ -X PUT -d '{"status":"resolved"}' # Set a nested field sentry api projects/my-org/my-project/ -X PUT -F options[sampleRate]=0.5 # Assign an issue -sentry api issues/123456789/ -X PUT --field assignedTo="user@example.com" +sentry api organizations/my-org/issues/123456789/ -X PUT --field assignedTo="user@example.com" # Delete a project sentry api projects/my-org/my-project/ -X DELETE diff --git a/packages/cli/src/commands/api.ts b/packages/cli/src/commands/api.ts index e6f7e0c03..d885580b0 100644 --- a/packages/cli/src/commands/api.ts +++ b/packages/cli/src/commands/api.ts @@ -1117,6 +1117,32 @@ export function formatEmptyErrorBody( return `HTTP ${statusLabel}${request}`; } +const LEGACY_ISSUE_PREFIX = /^(?:issues|groups)\/(?=[^/?]+\/)/; + +/** + * Suggest the org-scoped form of a legacy unscoped `issues//` route. + * Sentry deprecated those routes and serves them from one region only, so + * they 404 for organizations in other regions and 410 during deprecation + * brownouts. The org-scoped form is routed to the organization's region. + * @internal Exported for testing + */ +export function formatLegacyIssueRouteHint( + status: number, + endpoint: string, +): string | undefined { + if ( + (status !== 404 && status !== 410) || + !LEGACY_ISSUE_PREFIX.test(endpoint) + ) { + return; + } + const scoped = endpoint.replace( + LEGACY_ISSUE_PREFIX, + "organizations//issues/", + ); + return `Unscoped issue routes are deprecated and reach only one region. Use ${scoped} instead.`; +} + type ApiResponseOutputOptions = { silent: boolean; isTTY: boolean | undefined; @@ -1633,7 +1659,7 @@ export const apiCommand = buildCommand({ }, { description: "Get a specific issue", - run: "api issues/123456789/", + run: "api organizations/my-org/issues/123456789/", }, { description: "Create a release", @@ -1641,11 +1667,11 @@ export const apiCommand = buildCommand({ }, { description: "Update an issue status", - run: "api issues/123456789/ -X PUT -F status=resolved", + run: "api organizations/my-org/issues/123456789/ -X PUT -F status=resolved", }, { description: "Send an inline JSON body", - run: 'api issues/123456789/ -X PUT -d \'{"status":"resolved"}\'', + run: 'api organizations/my-org/issues/123456789/ -X PUT -d \'{"status":"resolved"}\'', }, { description: "Set a nested field", @@ -1653,7 +1679,7 @@ export const apiCommand = buildCommand({ }, { description: "Assign an issue", - run: 'api issues/123456789/ -X PUT --field assignedTo="user@example.com"', + run: 'api organizations/my-org/issues/123456789/ -X PUT --field assignedTo="user@example.com"', }, { description: "Delete a project", @@ -1842,6 +1868,13 @@ export const apiCommand = buildCommand({ normalizedEndpoint, flags.method, ); + const hint = formatLegacyIssueRouteHint( + response.status, + normalizedEndpoint, + ); + if (hint) { + log.warn(hint); + } } let pagination: ApiPaginationMetadata = parseLinkHeader( diff --git a/packages/cli/test/commands/api.test.ts b/packages/cli/test/commands/api.test.ts index 0c13f2fdc..d984f3bcf 100644 --- a/packages/cli/test/commands/api.test.ts +++ b/packages/cli/test/commands/api.test.ts @@ -22,6 +22,7 @@ import { extractJsonBody, formatApiResponse, formatBinaryErrorBody, + formatLegacyIssueRouteHint, isApiErrorStatus, normalizeEndpoint, normalizeFields, @@ -1080,6 +1081,30 @@ describe("formatBinaryErrorBody", () => { }); }); +describe("formatLegacyIssueRouteHint", () => { + test.each([ + [404, "issues/123/", "organizations//issues/123/"], + [ + 410, + "groups/123/events/latest/", + "organizations//issues/123/events/latest/", + ], + ])("suggests the org-scoped route for %i %s", (status, endpoint, scoped) => { + expect(formatLegacyIssueRouteHint(status, endpoint)).toContain( + `Use ${scoped} instead.`, + ); + }); + + test.each([ + [500, "issues/123/"], + [404, "organizations/my-org/issues/123/"], + [404, "issues/"], + [404, "projects/my-org/my-project/issues/"], + ])("returns undefined for %i %s", (status, endpoint) => { + expect(formatLegacyIssueRouteHint(status, endpoint)).toBeUndefined(); + }); +}); + describe("resolveApiResponseOutput", () => { const png = new Uint8Array([0x89, 0x50, 0x4e, 0x47]);