Repository navigation
ref(api)!: Move the response cache and retry policy out of @sentry/api/client - #132687
Merged
Merged
Conversation
@sentry/api stays dependency-free: the host that consumes it owns its cache and retry policy and plugs them in through the transport's `cache` seam and `fetch`. The toolkit CLI and MCP already do, through @sentry/http (getsentry/toolkit#2509). Removed from @sentry/api/client: lookupResponse, storeResponse, buildCacheKey, normalizeUrl, createMemoryStore, REVALIDATION_WINDOW_MS, the CacheStore, CacheEntry, BodyCodec, and memory-store types, nextRetryDelayMs, sleep, and RetryPolicy. createApiTransport no longer takes `retry` and sends each request once, plus one replay after a credential refresh. The http-cache-semantics dependency is gone. Kept: the TransportCache seam (CacheLookup is now defined in transport.ts), credential refresh, trusted-origin redirects, the TTL tiers, invalidation prefixes, parseRetryDelayMs (now in rate-limit.ts), isIdempotentRequest, and the idempotent-operation matchers. BREAKING CHANGE: the response-cache and retry exports above are gone, and `createApiTransport` rejects a `retry` option. Hosts that relied on the built-in retries wrap `transport.request` or `fetch` instead. Co-Authored-By: BYK <burak.kaya@sentry.io>
A change marked breaking (`type(scope)!:` or a `BREAKING CHANGE:` footer) releases as a major, so the removed-exports check lists its removals and passes. CI reads the PR title, or the commit message after merge. Other changes still fail on a removed export. Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
The exports check now reads the PR title, or the merged commit's message, from the run's event payload (GITHUB_EVENT_PATH) instead of a CHANGE_MESSAGE variable that the workflow sets. backend.yml stays unchanged, so this package-only PR no longer counts as a backend change.
`createApiTransport` takes an optional `retry(failure)` that returns the delay before the next attempt, or undefined to stop. The transport calls it per attempt, after the cache lookup and credential preparation, with the failed status or error, the attempt count, the time waited, and the server's requested delay. It owns the loop, the abortable wait, and the body replay; the host owns the policy. Without `retry` it sends once. A host that wraps `transport.request` repeats the cache lookup, credential lookup and refresh, and span on every attempt, so this hook replaces that wrapping. Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
`retry(attempt, { method, url, idempotent, signal })` now runs once per
request, after the cache lookup and credential preparation, and returns
the final response. `attempt()` sends once with the transport's timeout,
body buffering, redirect checks, and 401 refresh, and resolves with the
response or throws, with ApiTimeoutError for the transport's own
timeout. The cache store, write invalidation, `errors.rateLimited`, and
`errors.timeout` apply once to the result.
The host's policy now owns the loop and the wait, so @sentry/http's
fetchWithRetry implements the hook directly, and the transport keeps no
loop or sleep of its own.
Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
BYK
approved these changes
Nov 26, 2026
BYK
marked this pull request as ready for review
November 26, 2026 17:37
2 tasks done
BYK
added a commit
to getsentry/toolkit
that referenced
this pull request
Nov 26, 2026
…ok (#2542) Bumps `@sentry/api` to 3.0.0 and moves the CLI and MCP retries onto the transport's new `retry` hook, added in getsentry/sentry#132687. ### What changes - **toolkit-core:** `withSentryRetry` and `TRANSPORT_SENDS_ONCE` are replaced by `sentryRetry(options): TransportRetry`. It builds the hook on `@sentry/http`'s `fetchWithRetry`, using `SENTRY_RETRYABLE_STATUSES` and `@sentry/api`'s `parseRetryDelayMs`. `SentryRetryOptions` takes `policy`, `isRetryableError`, and an `onRetry` that also gets the retried request's method and URL. - **CLI and MCP:** both pass `retry: sentryRetry({ policy })` to `createApiTransport` instead of wrapping `transport.request`. The transport now runs the hook after the cache lookup and the credential's `prepare`. A retried request looks up the cache and the credential once, and it gets one host span instead of one per attempt. Each attempt still has its own timeout, body buffering, redirect checks, and 401 refresh, and the refresh doesn't count as a retry. - **Idempotency:** the hook gets `idempotent` from the transport, which already combines the per-request flag with the operation catalog (`isIdempotent`). So the wrapper's separate `isIdempotent` option goes away. - **CLI `isRetryableError`:** the `TimeoutError` case is gone. An attempt now throws the transport's `ApiTimeoutError`, which isn't a `CliError`, so it still retries. `errors.timeout` maps the final timeout to `TimeoutError` once, after the hook gives up. - **MCP issue-event read:** 3.0.0 types `event_id` as a string, so the cast for 32-character event IDs is removed. Without it, lint fails with an unnecessary-assertion error. - **`pnpm-workspace.yaml`:** the catalog entry and the `minimumReleaseAgeExclude` entry move to `@sentry/api@3.0.0`. ### Also picked up from 2.16.0 The bump from 2.15.0 includes getsentry/sentry#131779, which sends and reads Objectstore batches as FormData. Each operation is a JSON part named by its index, and an insert's bytes go in `<index>.payload`. The CLI's snapshot uploads use that batch client, so their wire format changes with this PR. The CLI's objectstore test fixtures now build responses in that format. `@sentry/http` needs no new export: `fetchWithRetry(send, options)` already fits the hook. <!-- junior-request-attribution:start --> via @BYK. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:agent%3A672bf07a67118adf395d2ead4a7cd9aa --> -- [View Session](https://junior-prod.sentry.dev/conversations/agent%3A672bf07a67118adf395d2ead4a7cd9aa) [[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A672bf07a67118adf395d2ead4a7cd9aa/?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>
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Breaking change: this needs a major release (3.0.0).
@sentry/apistops shipping a generic HTTP cache and retry policy. The host that consumes it now owns both and plugs them into the transport: thecacheoption (TransportCache) and a newretryhook. The toolkit CLI and MCP already work this way through@sentry/httpsince getsentry/toolkit#2509.@sentry/apigains no new dependency, andhttp-cache-semanticsgoes away.Removed from
@sentry/api/clientlookupResponse,storeResponse,buildCacheKey,normalizeUrl,createMemoryStore,REVALIDATION_WINDOW_MS, plus the typesCacheStore,CacheEntry,BodyCodec,BodyEncoding,EncodedBody,MemoryStore,MemoryStoreOptions,LookupOptionsandStoreOptions.nextRetryDelayMs,sleepandRetryPolicy.retrychanges from aRetryPolicyobject to an optional hook.Retry hook
The transport calls
retryonce per request, after the cache lookup and the credential's lookup andprepare, and inside the host span. The hook callsattempt()as often as its policy allows and returns the final response.Each
attempt()sends once with the transport's timeout, body buffering, redirect checks, and 401 refresh. That refresh replay happens inside the attempt, so it never counts as a retry. It resolves with the response, failed or not. Otherwise it throws:ApiTimeoutErrorwhen the transport's own timeout fired, the caller's abort reason, the host'serrors.fatalor redirect-rejection error, or what the fetch threw.The cache store, write invalidation,
errors.rateLimited, anderrors.timeoutapply once, to what the hook returns or throws. Without the hook, each request is sent once.The hook owns the loop and the wait, so
@sentry/apihas no retry policy, loop, or@sentry/httpdependency.@sentry/http'sfetchWithRetry(send, options)implements it directly:Kept
These are plain data and functions, and none of them depends on
@sentry/http:TransportCacheseam.CacheLookupis now defined intransport.ts.classifyUrl,FALLBACK_TTL_MS,TtlTierandcomputeInvalidationPrefixes.parseRetryDelayMs, which moved torate-limit.ts. It still readsRetry-AfterandX-Sentry-Rate-Limit-Reset, and the transport still passes its value toerrors.rateLimited.isIdempotentRequest, which moved toidempotent-operations.ts, plusselectIdempotentWritesandcreateIdempotentOperationMatcher.Migration
retry: policywith aretryhook. With@sentry/http, wrapfetchWithRetryas shown above.TransportCacheon a cache of your own.Toolkit follow-up, after 3.0.0 is published
retryhook on@sentry/http'sfetchWithRetry, withSENTRY_RETRYABLE_STATUSESandparseRetryDelayMs, and passes it tocreateApiTransport.withSentryRetrystops wrappingtransport.request, and its outer wrapping goes away.TRANSPORT_SENDS_ONCEand theretry:lines that use it in the CLI'ssentry-client.tsand MCP'sapi-client/client.ts.@sentry/httpneeds no new export, sincefetchWithRetryalready matches the hook. A named adapter, such asretryHook(options), is optional sugar.Breaking changes may remove exports
test/consumers/exports.mjsnow allows removed exports when the change is marked breaking:type(scope)!:in the PR title, or aBREAKING CHANGE:footer. That's the signal Craft reads to pick a major bump. The script reads the PR title, or the commit message after merge or in the merge queue, from the run's GitHub event, so no workflow changes. The script still lists the removals, and any change not marked breaking still fails.Release
openapi.yml's automatic release should publish this as 3.0.0 after merge. If a spec change lands before that release runs, its preflight forces aminorbump and this would ship as 2.x instead.via @BYK.
--
View Session [Sentry]