Skip to content

Integrate the SDK runtime with frontend apiOptions and RequestError #131203

Open

Description

@betegon

Part of v1.0.0 getsentry/sentry-api-schema#93. Follow #102's generated-contract/apiOptions phase with a real SDK runtime integration in shared frontend infrastructure.

Updated 2026-11-14: @sentry/api now lives in the same repository as the frontend, getsentry/sentry, under static/packages/api. It releases from there as [email protected], and the current version is 2.5.0. Do new SDK and frontend work for this issue in getsentry/sentry.

What exists now

Outcome

A migrated query must require no more infrastructure code than today's apiOptions call. Keep the actual frontend RequestError, existing imports, query keys, selectors, and {json, headers, status?} cache contract. Do not require retiring RequestError as a condition of adopting the SDK.

apiOptions / infinite options
        ↓
shared frontend execution + SDK integration
        ↓
SDK HTTP mechanics + retained frontend policies
        ↓
success: {json, headers, status?}
failure: the frontend's actual RequestError where applicable

What we maintain in the SDK

  • Supply and test the reusable response/error adaptation once, on top of the existing error contract and without consumer-side cloning or a WeakMap. If a frontend-specific compatibility module is needed, keep it optional and preserve the real frontend error class through the smallest typed seam validated by the pilot; do not import Sentry application code into the core or duplicate its error class.
  • Reuse existing interception/composition mechanisms where sufficient. Settle the smallest public integration API from the pilot; names such as installRequestErrorAdapter, apiOptions.sdk, and createFrontendCompatibility were sketches, not accepted APIs.

What stays with the frontend

Reuse its existing policies centrally: login/SSO, allowAuthError, sudo and its explicit retry, project redirects, regional/admin/dev routing context, credentials/CSRF decisions, telemetry, forms, user messages, and query-cache lifecycle. Feature components should not implement this adaptation.

Keeping the error class alone does not preserve these behaviors: they currently execute inside Client before the error reaches TanStack. Keep or extract that shared policy seam instead of copying the entire frontend client into the SDK with many callbacks.

The current Client.requestPromise() returns parsed data and ResponseMeta, not a native Response. Its raw fetch promise is also consumed by the client's own body parser and precedes sudo handling. Do not treat either as a drop-in Fetch adapter or reconstruct native responses by JSON stringify/parse.

Routing integration

Build on #81's metadata-driven contract in shared frontend infrastructure. Keep apiOptions and use organization locality from the existing bootstrap-populated ConfigStore; no discovery or adaptation in ordinary component queries.

  • Scope known regionUrl to its organization. Preserve explicit-host precedence, multi-region-disabled behavior, admin proxy routing, development URL rewrites and the org-domain dev proxy (which must not use the last organization's locality).
  • Keep control operations on control even when their path contains an organization. For operations available in both contexts, preserve intended control/local semantics rather than treating hosts as equivalent.
  • Retain the existing adapter for private/unsupported routes. Public OpenAPI metadata does not replace the frontend's entire internal route catalog.
  • Keep ConfigStore in page memory; do not copy it into a second SDK discovery cache. SDK-managed discovery remains separately opt-in.
  • Verify the final destination before attaching browser credentials/CSRF. Preserve body, headers, status, signal, actual RequestError behavior and request counts.
  • Test a regional read, control request, cross-organization/admin request and development proxy flow centrally, with no per-component host selection.

Backend metadata and the SDK routing foundation precede this runtime adoption. getsentry/sentry-api-schema#102 remains independent; Toolkit #1502 does not need to merge before this shared contract is settled.

Pilot and acceptance

  • Integrate one query and one related mutation centrally. Preserve request/response metadata, field errors, and exact RequestError identity where that class is produced; no converter in each component.
  • A 403 still follows the existing non-retry policy; 404 handling, localized messages, and form-field errors retain their behavior. Test network/decoding failures separately rather than pretending every error has one class.
  • Verify login/SSO and allowAuthError; sudo must preserve the final retry's actual status/headers. A normalized HTTP error must not accidentally bypass these flows.
  • Preserve Link, numeric hit counts, X-Sentry-Direct-Hit, and status. Verify existing cache readers/writers, optimistic updates, invalidation, and selectors.
  • Validate a table and an infinite query with Define a shared, opinionated pagination API for v1 sentry-api-schema#99: URL cursors/filter resets, next/previous pages, prefetch, and specialized pageParam behavior. TanStack owns page state; do not substitute paginateAll() for incremental fetching.
  • Wire TanStack's signal through the shared path, using the SDK's per-operation signal support. Distinguish cancellation from failures requiring UI/retry; do not replicate legacy indefinitely pending promises as a new SDK guarantee.
  • Keep one retry owner. Preserve the frontend's TanStack policy by default; composing the SDK's retrying transport must not multiply attempts.
  • Preserve private/unsupported endpoint fallback and deployment/admin/dev routing behavior. No whole-frontend rewrite is required.
  • Link implementation PRs and results to v1.0.0 sentry-api-schema#93. Distinguish type-only adoption, mocked tests, and real integrated browser/deployment validation.

Sequence and evidence

The generated-contract phase can improve apiOptions before this runtime migration. The getsentry/sentry-api-schema#94 response/error, getsentry/sentry-api-schema#95 cancellation and getsentry/sentry-api-schema#92 retry contracts are now in the package; this phase still depends on the auth/browser/routing contracts in #131198. Deliver SDK support and frontend integration in focused PRs.

A local mocked probe already demonstrated that an SDK error interceptor can produce the real frontend RequestError, TanStack stores that same object, and the current 403 retry policy performs only one request. That is feasibility evidence only; it does not validate this full integration, SSO/sudo, cancellation, or a deployed browser.

An optional generic TanStack binding remains useful for external applications. It is separate from preserving Sentry's existing apiOptions conventions and is not a prerequisite for the first frontend phase. Type-only adoption does not satisfy getsentry/sentry-api-schema#93's required runtime frontend workflow.

via @BYK.

--

View Session [Sentry]

Activity

  1. linear-code commented on Nov 16, 2026

    @linear-code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions