Repository navigation
feat(api): Move the @sentry/api package into static/packages/api - #130472
sentry-junior[bot] wants to merge 6 commits into
Conversation
|
🚨 Warning: This pull request contains Frontend and Backend changes! It's discouraged to make changes to Sentry's Frontend and Backend in a single pull request. The Frontend and Backend are not atomically deployed. If the changes are interdependent of each other, they must be separated into two pull requests and be made forward or backwards compatible, such that the Backend or Frontend can be safely deployed independently. Have questions? Please ask in the |
Sentry Snapshot Testing
|
68de88b to
6470e77
Compare
6470e77 to
21b537f
Compare
Move the generated TypeScript client for Sentry's public API from getsentry/sentry-api-schema into this repository, next to the spec it is built from. - Build it from tests/apidocs/openapi-derefed.json, upgraded to TypeScript 6 with exact dev tool pins and zod 4.6.7. - Ship the spec, the API ownership stats and the RPC method schema under @sentry/api/spec/ so consumers can read them from npm. - Add a required api-client job to backend.yml that builds, typechecks and tests the client on spec or package changes. - Pack it in package-pack.yml and release it from openapi.yml when what it ships changes. Releases stay off until the first api@ tag is cut by hand. Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
Stop the path parameter pattern from backtracking on runs of '{', and write
the generated-code match in build step generate-request-preparation as a plain
string so CodeQL does not read its template escapes as regex escapes.
Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
Keep the npm package at its 1.54.0 size. The pack job adds the spec, API ownership stats and RPC schema to the release artifact, so craft's github target attaches them to each api@ release while npm takes only the tarball. The release preflight now compares against those release assets. Also make ocpo a code owner of static/packages/api alongside owners-api. Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
…c files Treating a release without its spec files as "everything changed" would cut a minor release with nothing in it. Craft attaches the files before it merges the release branch, so this only happens when something went wrong, and a failed run is easier to notice than an empty release.
21b537f to
74efdbf
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 74efdbf. Configure here.
Ported from getsentry/sentry#130518, per @BYK's request there: get the docs aligned here first, then move `@sentry/api` into getsentry/sentry. The commit applied cleanly on top of 2.0.0. Cursor Bugbot found the bug while reviewing the move ([thread](getsentry/sentry#130472 (comment))). It ships in the published `@sentry/api` 2.0.0. ## Bug `listPage` asked each later page for only the rows still missing: `per_page = min(100, limit - items.length)`. `listProjects`, `listTeams` and `listOrganizations` are served by Sentry's `OffsetPaginator`. Its cursor is `<page size>:<page>:<is_prev>`. When `per_page` doesn't match the cursor's page size, it reads the cursor's window and keeps only the last `per_page` rows (`src/sentry/api/paginator.py` in getsentry/sentry). So `100:1:0` with `per_page=50` returns rows 150–199, and rows 100–149 are lost. Any `limit` above 100 dropped rows without an error. ## Fix `listPage` now walks through the package's existing `paginate`, which: - uses one `per_page` for the whole walk. A fresh walk splits `limit` evenly: 150 becomes 2 × 75. - reuses the page size that an offset cursor encodes when resuming, whatever the new `limit` is. - returns a cursor that resumes at the first row not returned, including partway through a page. `listPage` still validates each page with the schema, and still rejects a page with more rows than requested or a repeated cursor. One behavior changes: if a walk reaches `MAX_LIST_PAGES`, it now returns the rows it has and a resume cursor instead of throwing. Before this change, a stable page size couldn't hit that cap in a normal walk. Now a resumed small-page cursor can, for example `25:1:0` with `limit: 5000`. ## Tests - `test/api-client/core.test.ts` models `OffsetPaginator`. It confirms that `100:1:0` with `per_page=50` reads rows 150–199. Then it checks two things: - a 150-row walk and its resume return rows 0–299 in order, all with `per_page=75`; - resuming `100:1:0` with `limit: 50` returns rows 100–149, then 150–199, both requested with `per_page=100`. - The `listOrganizations` test now expects `per_page` to stay at 3 on the second request. It was 1, which was the bug. `pnpm build`, `pnpm typecheck` and `pnpm test` pass locally (53 files, 675 tests). No UI change. Co-Authored-By: BYK <126780+BYK@users.noreply.github.com> <!-- junior-session-footer:start --> <!-- junior-conversation-id:agent%3A69da19b385017e68b7f9eace56e9477f --> -- [View Session](https://junior-prod.sentry.dev/conversations/agent%3A69da19b385017e68b7f9eace56e9477f) [[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A69da19b385017e68b7f9eace56e9477f/?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>

Moves
@sentry/api, the generated TypeScript client for Sentry's public API, from getsentry/sentry-api-schema (at 1.54.0,9774a3d) tostatic/packages/api. It now builds fromtests/apidocs/openapi-derefed.json, the spec this repository generates. The npm name stays@sentry/api, so getsentry/toolkit and other consumers don't change. This PR replaces the pre-merge check from #130450, which was closed.This PR doesn't change npm publishing. Releases from here stay off until a person cuts the first
api@tag (see the cutover section below).Package
@typescript/typescript6alias as the rest of the repo. zod is 4.6.7, the versionstatic/app, gsApp, gsAdmin and scraps already pin, so sentry itself needs no zod bump. The other dev tools (hey-api, esbuild, vitest, valibot, fast-check,@types/*) are pinned to exact versions inside the package workspace.dist/byte-identical to the published 1.54.0, so the toolchain upgrade doesn't change the output.source-analysisnow uses a path-parameter pattern that can't backtrack on runs of{: 50,000{characters took 2.1 s before and 1 ms after. In one build script, a template literal that CodeQL misread as a regex became a plain string; the generated output is unchanged.test:vitest, nottest. The repo'stest-ciandtest-allpass Jest flags to every workspace'stestscript, and these tests also need the spec build first.Spec files on GitHub releases
Each
api@x.y.zGitHub release gets the files that version was built from as assets. The pack job adds them to the release artifact; craft's github target attaches every file in it, and its npm target publishes only the tarball:openapi-derefed.json, the dereferenced OpenAPI spec.api_ownership_stats_dont_modify.json, for eng-pipes.make build-api-docsgenerates this file; it isn't committed.rpc_method_schema.json, for the openapi-diff/RPC check. It comes from a newmake build-rpc-schematarget.For example:
https://github.com/getsentry/sentry/releases/download/api@x.y.z/openapi-derefed.json.The npm package doesn't include them. Its unpacked size stays at the 1.54.0 baseline (34.1 MB).
CI:
api clientis a required checkThe new
api-clientjob inbackend.ymlbuilds, typechecks and tests the client against the PR's own spec. It is part ofbackend-required-check. A spec change that broke the client caused a 2-day stall in releases, and nothing caught it before merge; this check catches that class of change.api-docsjob (shared as a workflow artifact), so the spec isn't built twice.api_clientfilter matches: the existingapi_docspaths plusstatic/packages/api/**. On other PRs both jobs are skipped, andbackend-required-checkcounts skipped jobs as passing.Releases
package-pack.ymlsets up the Python env forapi, then builds the spec, the RPC schema and the package beforepnpm pack.release-api-packagejob inopenapi.ymlruns after the master spec build, whenever the spec or the package might have changed. It runs.github/workflows/scripts/api-package-release-preflight.sh, thencraft preparewithgetsentry/publish. The preflight skips the release when:api@tag yet, so the job stays inert until the first release is cut by hand;api/release/*branch is still pending. When that release merges back, its own run releases whatever landed in the meantime;api@tag;cancel-in-progress: false, so a burst of merges produces one release.static/packages/apioption.api_clientfilter. It copies the samespec/files, and the release doesn't wait for it.Cutover (separate PRs, in this order)
auto-approve-repos.txt, replace thegetsentry/sentry-api-schemaline with this repo'sstatic/packages/apientry (a one-line change).static/packages/apiand the next minor version after sentry-api-schema's last. From then on,openapi.ymlreleases on change.Retiring sentry-api-schema after the cutover
releases/download/api@x.y.z/…for a pinned version, or from the newestapi@release. GitHub'sreleases/latestpoints at sentry's calver release, so "newestapi@" means listing releases and taking the firstapi@tag.openapi-derefed.jsonfrom the release, or build the API reference from@sentry/apiitself.openapi.ymland archive getsentry/sentry-api-schema.static/packages/api/is owned by @getsentry/owners-api and @getsentry/ocpo in CODEOWNERS.This PR touches
static/as well as backend CI files. The package is a standalone npm package and isn't part of either deploy, so splitting it wouldn't change what gets deployed.No UI change.
via @BYK.
--
View Session in Sentry