Skip to content

feat: add sentry schema command for API introspection#437

Merged
BYK merged 1 commit intomainfrom
feat/schema-command
Mar 17, 2026
Merged

feat: add sentry schema command for API introspection#437
BYK merged 1 commit intomainfrom
feat/schema-command

Conversation

@BYK
Copy link
Member

@BYK BYK commented Mar 16, 2026

Phase 2 of #346: Add sentry schema command for runtime API introspection by AI agents.

What

Enables AI agents to discover Sentry API endpoints at runtime without pre-loaded documentation:

sentry schema                        # List all API resources with endpoint counts
sentry schema issues                 # Endpoints for 'issues' resource
sentry schema issues retrieve        # Detailed endpoint info (method, path, params, description)
sentry schema issues retrieve --json # Machine-readable output
sentry schema -q replay              # Search across all endpoints
sentry schema --all                  # Flat list of all 215 endpoints
sentry schema 'monitor*'             # Glob pattern matching on resources

Architecture

Build-time generationscript/generate-api-schema.ts fetches the dereferenced OpenAPI spec from getsentry/sentry-api-schema (version-tagged to match the installed @sentry/api package) and extracts:

  • HTTP methods and URL templates from the OpenAPI paths
  • Human-readable descriptions and deprecation status
  • Query parameter names from OpenAPI parameter definitions
  • SDK function name mapping from the @sentry/api JS bundle
  • Resource names derived from URL paths (last non-parameter segment)

Output: src/generated/api-schema.json (215 endpoints, ~117KB) — gitignored, generated at build/dev/test time via bun run generate:schema.

Runtimesrc/lib/api-schema.ts provides query functions:

  • getResourceSummaries() — grouped resource overview
  • getEndpointsByResource() — filter by resource
  • getEndpoint() — find specific endpoint (prefers operationId prefix match)
  • searchEndpoints() — full-text search across all fields
  • Glob pattern support via regex conversion for resource matching

The sentry schema command yields CommandOutput through the standard output system with mdKvTable + renderMarkdown for endpoint detail views.

Other changes

  • Updated @sentry/api from 0.21.0 → 0.54.0
  • CI workflow updated to run generate:schema before lint, typecheck, and tests
  • src/generated/ added to .gitignore

Tests

19 unit tests for schema query functions covering all query modes, edge cases, and data invariants.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 16, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • Add sentry schema command for API introspection by BYK in #437

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 16, 2026

Codecov Results 📊

111 passed | Total: 111 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

✅ Patch coverage is 100.00%. Project has 1101 uncovered lines.
✅ Project coverage is 95.11%. Comparing base (base) to head (head).

Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    95.09%    95.11%    +0.02%
==========================================
  Files          165       167        +2
  Lines        22424     22531      +107
  Branches         0         0         —
==========================================
+ Hits         21324     21430      +106
- Misses        1100      1101        +1
- Partials         0         0         —

Generated by Codecov Action

@BYK BYK force-pushed the feat/schema-command branch from 2c58186 to 1dad125 Compare March 16, 2026 20:07
@BYK
Copy link
Member Author

BYK commented Mar 16, 2026

Addressing review comments

  1. require.resolve — Now using require.resolve('@sentry/api/package.json') to locate the package instead of hardcoded node_modules path.

  2. OpenAPI spec instead of JS parsing — Rewrote the generator to fetch the dereferenced OpenAPI spec from getsentry/sentry-api-schema. The version tag is derived from the installed @sentry/api package version (now 0.54.0). This gives us:

    • Proper operationId from the spec (e.g., "List an Organization's Issues")
    • Query parameters extracted from OpenAPI parameter definitions
    • Accurate deprecation flags from the spec
    • No fragile regex parsing of JS bundles

    The SDK function name mapping is still extracted from @sentry/api's bundled JS (to map operationIds to their TypeScript function names), but this is a secondary lookup — the primary data comes from the OpenAPI spec.

  3. Updated @sentry/api from 0.21.0 → 0.54.0 to match the latest schema.

@BYK BYK marked this pull request as ready for review March 16, 2026 20:24
@BYK BYK force-pushed the feat/schema-command branch from 1dad125 to 09e77fd Compare March 16, 2026 20:44
@BYK BYK force-pushed the feat/schema-command branch from 09e77fd to da1532a Compare March 16, 2026 20:56
@BYK
Copy link
Member Author

BYK commented Mar 16, 2026

Round 3 review fixes

All six comments addressed:

  1. mdKvTable + renderMarkdown for endpoint detail — Replaced manual string building with mdKvTable key-value rows (Resource, Operation, Function, Status, Path Params, Query Params) rendered through the markdown pipeline.

  2. Renamed --list--all — Flag now called --all for showing flat endpoint list.

  3. Fixed padding before color formatting — Color is now applied to the raw method string, then spaces are appended outside the ANSI escape codes.

  4. Empty array guard in formatResourceList — Returns early with "No resources found." before Math.max call on empty arrays.

  5. Added -q alias for --search — Can now use sentry schema -q monitor as shorthand.

  6. Glob-style search — Positional args containing * or ? are treated as glob patterns via Bun.Glob. Example: sentry schema monitor* matches resources starting with "monitor".

Re: fuzzy/levenshtein — there's a private levenshtein() in platforms.ts but it's not exported. Extracting it to a shared module is a good follow-up but out of scope for this PR. The substring + glob search covers the primary use cases.

@BYK BYK force-pushed the feat/schema-command branch from da1532a to 8bbae55 Compare March 16, 2026 21:01
@BYK BYK force-pushed the feat/schema-command branch from 8bbae55 to 0b6784a Compare March 16, 2026 21:08
@BYK BYK force-pushed the feat/schema-command branch from 0b6784a to ef79773 Compare March 16, 2026 21:15
@BYK BYK changed the title feat: add schema command for Sentry API introspection feat: add sentry schema command for API introspection Mar 16, 2026
@BYK BYK force-pushed the feat/schema-command branch 2 times, most recently from 3a4dfd2 to 4ed3be6 Compare March 16, 2026 21:35
@BYK BYK force-pushed the feat/schema-command branch from 4ed3be6 to c6dd55f Compare March 16, 2026 21:46
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

@BYK BYK force-pushed the feat/schema-command branch from c6dd55f to 1f681e6 Compare March 16, 2026 21:56
Phase 2 of #346: Add `sentry schema` command for runtime API introspection
by AI agents.

New features:
- `sentry schema` — list all API resources with endpoint counts
- `sentry schema <resource>` — list endpoints for a resource
- `sentry schema <resource> <operation>` — show endpoint details
- `sentry schema --list` — flat list of all 214 API endpoints
- `sentry schema --search <query>` — search across endpoints
- All modes support `--json` for machine-readable output

Architecture:
- `script/generate-api-schema.ts` — build-time parser that extracts
  endpoint metadata from `@sentry/api` (function names, HTTP methods,
  URL templates, JSDoc descriptions, deprecation status)
- `src/generated/api-schema.json` — lightweight index (102KB, 214
  endpoints) bundled into the CLI
- `src/lib/api-schema.ts` — runtime query functions (by resource,
  operation, or full-text search)
- `src/commands/schema.ts` — command with human + JSON output modes

Tests: 19 unit tests for schema query functions
@BYK BYK force-pushed the feat/schema-command branch from 1f681e6 to e170d8b Compare March 17, 2026 10:24
@BYK BYK merged commit 1b2a974 into main Mar 17, 2026
22 checks passed
@BYK BYK deleted the feat/schema-command branch March 17, 2026 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant