Repository navigation
feat(search): Publish the search syntax grammar as @sentry/search-syntax - #128514
Conversation
Move the search grammar and its token enums into a new workspace package, static/packages/search-syntax, so tools outside this repo (the Sentry CLI and MCP server in getsentry/toolkit) can use the same grammar instead of copying it. The package ships the grammar, the Token/TermOperator/FilterType/ BooleanOperator enums, and a structural TokenConverter + parseSearch that builds the same token tree as the frontend parser without the app-only validation and value parsing. Its tests run the shared fixtures in fixtures/search-syntax, the same contract the frontend parser and event_search.py already test against. The app imports the grammar and enums from the package; its own TokenConverter is unchanged. Publishing follows @sentry/icons: Craft workspace, pack workflow, release option, and publishConfig.exports. Also gate AGGREGATE_SIZE filters on a size-key argument, like the other typed aggregates. Before, any aggregate with a size-looking value parsed as an aggregate size filter. Refs getsentry/toolkit#1533 Co-Authored-By: BYK <[email protected]>
|
🚨 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 |
There was a problem hiding this comment.
This makes sense to me from a "how do we publish" perspective. Glad the monorepo work is paying dividends already 🙏
Would love for @nsdeschenes to chime in before merging since he'll be owning this
nsdeschenes
left a comment
There was a problem hiding this comment.
Two comments to take a peek at
…nfig Callers that parse with empty filterKeys only learn field types from keys found in the query. Aggregate arguments were never found, so with the stricter AGGREGATE_SIZE check, avg(http.response_content_length):>1kb fell back to free text. Also rename the package lint script to lint:js so the root lint dispatcher runs it.
JoshuaKGoldberg
left a comment
There was a problem hiding this comment.
Looking great!
Just a few small things I'd suggest cleaning up that are > the level of internal code and IMO <= the level of a shared package. Nothing major.
Type the grammar's parse() result from the converter's token builders, so the package and the frontend get their ParseResult without any or casts. Type the converter, enums and SyntaxError fields precisely, and JSDoc the operator lists and enums in @sentry/search-syntax/tokens.
Bump actions/checkout and actions/upload-artifact to their latest v7 releases, still pinned by SHA like every other workflow in the repo. Note in parser.ts and tokens.ts that they are written by hand; only grammar.pegjs is compiled, at build time.
Craft 3.3.0 expands workspace placeholders and runs the automatic version bump in the selected workspace (getsentry/craft#938, #939). Replace the three literal static/packages entries with one static/packages/* entry, drop the custom preReleaseCommands, and fold the three pack workflows into one that derives the package from the release branch. The resolved Craft config for scraps, icons and search-syntax is unchanged apart from the artifact workflow name and the dropped preReleaseCommand. Bump the release workflow's Craft action to 3.3.0 and minVersion to match.
…x-package # Conflicts: # .craft.yml # .github/workflows/release.yml
…1689) `@sentry/[email protected]` is now on npm, published from getsentry/sentry `static/packages/search-syntax` (getsentry/sentry#128514). This drops toolkit's vendored copy of the grammar and parser and uses the package instead, so the CLI, MCP and the Sentry frontend all run one grammar. **What changes** - Deletes `packages/toolkit-core/grammar/`, the committed compiled parser in `src/generated/`, `src/search-syntax.ts` (the structural `TokenConverter`), its tests, and the copied `test/fixtures/search-syntax` cases. The package's `parser.spec.ts` is the port of those tests and runs the shared fixtures in getsentry/sentry. - `toolkit-core/src/search-query.ts` and MCP's `search-events/utils.ts` import `parseSearch` and the token types from `@sentry/search-syntax/parser`, and `Token` / `TermOperator` / `FilterType` from `@sentry/search-syntax/tokens`. The `@sentry/toolkit-core/search-syntax` export is removed; those two files were its only users. - Adds `@sentry/search-syntax` to the pnpm catalog (`^1.0.0`) as a dependency of toolkit-core and mcp-core. `1.0.0` is in `minimumReleaseAgeExclude` because it was published today, like the other first-party `@sentry/*` entries. - Removes the root `generate:parsers` script, its pre-commit task, the `check:generated` path for `toolkit-core/src/generated`, and the oxlint/oxfmt ignores for the deleted files. The CLI still compiles its own `org-project-target` grammar with `scripts/generate-parsers.mjs`. - Updates the toolkit-core README and two test comments that pointed at the deleted tests. The package's API matches what toolkit had: the parser was ported from toolkit-core, with the #1534 size-filter fix. One type-level difference is that the token constants are TS enums instead of `as const` objects. Their runtime string values are unchanged. **Checks (local)** - toolkit-core: 142 tests pass, `tsc` clean - mcp-core: 1877 tests pass; `tsc` only reports the existing `@sentry/mcp-server-mocks` resolution errors from the unbuilt mocks package - mcp-core and mcp-server `tsdown` builds pass, and both ESM and CJS outputs of mcp-server bundle the package - CLI: 1041 tests across `search-query`, `issue`, `log`, `span`, `trace`, `replay`, `event` and `errors` pass. `explore.test.ts` can't load here because `sdk.generated.js` doesn't build in this sandbox, so CI is the real check for it. - A CJS esbuild bundle of `search-query.ts`, which is how the CLI builds, resolves the package and rewrites `level:error OR level:warning` to `level:[error,warning]` - `pnpm install --frozen-lockfile`, `check:generated`, oxlint and oxfmt pass Refs #1533 <!-- junior-request-attribution:start --> via @BYK. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:slack%3AC010884QHLG%3A1792178565.603129 --> -- [View Junior Session](https://junior-prod.sentry.dev/conversations/slack%3AC010884QHLG%3A1792178565.603129) [[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AC010884QHLG%3A1792178565.603129/?project=4510944073809921) <!-- junior-session-footer:end --> Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Burak Yigit Kaya <[email protected]>
Moves the search grammar and its token enums into a new workspace package,
static/packages/search-syntax, published as@sentry/search-syntax. The goal is one shared grammar, not a copy:getsentry/toolkit(Sentry CLI + MCP server) currently vendorsgrammar.pegjsand a port of the parser, and would switch to this package. See getsentry/toolkit#1533.@nsdeschenes, tagging you as agreed in that issue. Please pull in whoever else should look.
What's in the package
src/grammar.pegjs: moved here unchanged (git sees a 100% rename). The app now imports it from@sentry/search-syntax/grammar.src/tokens.ts:Token,TermOperator,FilterType,BooleanOperator, plus the wildcard and regex operator lists, moved out ofsearchSyntax/tokens.tsxandparser.tsx. Both files re-export them, so no app imports change.src/parser.ts: a structuralTokenConverterandparseSearch/parseSearchOrThrow. It builds the same token tree as the frontend parser (types, text, locations, filter classification) but leaves out the app-only parts: validation messages,t(), moment, andparsedvalues. Callers can subclass it and override thecheckInvalid*/is*Keyhooks. It's ported from the toolkit's version.src/parser.spec.ts: runs every case infixtures/search-syntaxagainst the structural parser. These are the same fixtures the frontend parser andevent_search.pyalready use, so the API↔FE contract now covers the package too.What stays the same
The app's
TokenConverterinparser.tsxis unchanged, apart from the size fix below. Having the app subclass the package converter, so the structural code lives in one place, is a good follow-up. I kept it out of this PR so the change stays reviewable. In the meantime the shared fixtures run against both converters, which catches any drift.Behavior change:
AGGREGATE_SIZEpredicateFilterchecked argument types for aggregate duration, date and percentage filters, but not size. Soavg(span.duration):>1kbparsed as an aggregate size filter. Size aggregates now need a size-key argument, like the others. Without one, the term falls through the same way a duration value on a non-duration aggregate does. The search query builder already fillssizeKeysfrom field definitions (FieldValueType.SIZE), so real size attributes still classify. The backend doesn't check this either. I didn't add a shared fixture case, because the backend would fail it; that's for a follow-up.Publishing
This follows the
@sentry/iconssetup:prepackbuilds with Rslib (the grammar is compiled by the existingbuild-utils/peggy-loader.ts),publishConfig.exportspoints atdist, and there's a Craft workspace, asearch-syntax-package-packworkflow, and a release workflow option. Plus the usual wiring: pnpm workspace, tsconfig reference, Knip, the root Jest ignore, oxlint boundaries, and CODEOWNERS (@getsentry/data-browsing, who already ownevent_search.pyand the search query builder). Before the first release, someone needs to set up npm access for the@sentry/search-syntaxname.Verification (run locally)
test(259 tests, including all 78 fixture files),typecheck,lint,knip --workspace static/packages/search-syntaxpnpm pack, then a clean ESM consumer:parseSearchworks under Node, and the types check withmoduleResolution: nodenextsentry-testoncomponents/searchSyntax,components/searchQueryBuilder,components/arithmeticBuilderandviews/explore/components(1,575 tests passing)tsc --build, React Router v6 and v8 configsoxfmt --check,sherif@sentry/search-syntax/grammarfromstatic/appthrough the existing peggy loadervia BYK.
--
View Junior Session [Sentry]