Repository navigation
fix(nuxt): Keep storage instrumentation plugin synchronous - #25949
Conversation
size-limit report 📦Compared: 081f440 (PR test merge using develop at 8d6b875) Against: 8d6b875 (develop) · base run #64749 ✅ Baseline matches: this diff contains only this PR's changes.
|
Optional E2E testsSome optional checks were not successful. They do not block the merge. 2 not successful, 3 successful. See the run.
Successful checks
|
Nitro v3 RC awaits async plugins and defers every later plugin until the promise settles. Our async (but never awaiting) storage plugin turned all subsequent plugins async, so a plugin throwing at startup became an unhandled rejection instead of crashing the server. Also opt the nuxt-5 e2e app into the `kv` cache driver: Nitro v3 RC's default `memory` cache driver no longer goes through KV storage, so cached functions/handlers are not visible to the storage instrumentation. Co-Authored-By: Francesco Gringl-Novy <francesco.novy@sentry.io>
24d8402 to
ac1c310
Compare
chargome
left a comment
There was a problem hiding this comment.
Is changing this export type breaking?
|
@chargome re "Is changing this export type breaking?": no. |
**Why:** Starting with the RC, Nitro v3 runs `defineCachedFunction` / `defineCachedHandler` (and `cache` route rules) on an `ocache` storage. That storage only goes through KV storage when the `kv` cache driver is set, so with the default `memory` driver (and with `fs`) our KV driver instrumentation never sees cache reads or writes, and no `cache.*` spans are produced. Nitro doesn't offer a tracing channel for its cache, and the storage instance is private to Nitro's runtime. It is created in the build-time `#nitro/virtual/cache` module, though, so a bundler transform wraps that module's `createCacheStorage` export and the storage gets patched in place. It has to be patched in place because `ocache` also reads `binary` and `maxEntryBytes` from the storage object. The `kv` driver is skipped because the existing KV instrumentation already covers it. `cache.hit` comes from the stored entry: it must have a value, be unexpired, and not be marked `stale`. This PR also undoes the `kv` workaround in the nuxt-5 E2E app, so the default driver is what gets tested. **How to review:** Start with `cacheStorageInstrumentationPlugin` in `vite/storageConfig.ts`, then `instrumentCacheStorage` in `runtime/utils/instrumentStorage.ts`. The span wrapper is now shared with the KV driver instrumentation, and KV behavior is unchanged. **Unsure about:** The transform matches the exact `export const createCacheStorage =` line that Nitro generates. If Nitro changes that template, the transform does nothing (no crash), but cache spans would disappear again. Is that acceptable, or should we push upstream for a tracing channel or hook in Nitro/ocache? Note this is stacked on #25949. <!-- junior-request-attribution:start --> via **Francesco Gringl-Novy**. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:slack%3AD0CA8FXFXAS%3A1793366214.663899 --> -- [View Session](https://junior-prod.sentry.dev/conversations/slack%3AD0CA8FXFXAS%3A1793366214.663899) [[Sentry]](https://sentry.sentry.io/explore/conversations/slack%3AD0CA8FXFXAS%3A1793366214.663899/?project=4510944073809921) <!-- junior-session-footer:end --> --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Francesco Gringl-Novy <francesco.novy@sentry.io>
Why: The optional
nuxt-5E2E job broke whennitro@latestmoved from3.0.260903-betato3.0.261029-rc. The same develop SHA passed before that release and failed after it. Two separate Nitro changes caused it:asyncbut never awaited anything, so it pushed every plugin after it (including user plugins) into the async path. A plugin that throws at startup then turns into an unhandled rejection. OuronUnhandledRejectionhandler keeps the process running, so instead of exiting with code 1 the server keeps listening behind a rejectedreadygate. Making the plugin synchronous restores the old behavior. Nitro v2 never awaited plugins, so nothing changes there.defineCachedFunction/defineCachedHandlerare now built onocache, and the defaultmemorycache driver skips KV storage completely. The storage instrumentation can't see those calls anymore. The test app now setscache: { driver: 'kv' }, which is also what Nitro picks by default when acacheKV mount is configured, so cache instrumentation stays tested.Unsure about: With Nitro v3 RC's default config, users no longer get
cache.*spans for cached functions or handlers. Supporting that would need new instrumentation around ocache's storage, since there is no tracing channel for it. Cache keys also changed shape (nitrofunctions.<hash>:...instead ofnitro:functions:...), so the expired-entry check inisCacheHitno longer runs, and it falls back to checking whether a value is present. Should that be handled here, or tracked as a follow-up?via Francesco Gringl-Novy.
--
View Session [Sentry]