feat(nitro): Add unstorage tracing channel instrumentation#20615
feat(nitro): Add unstorage tracing channel instrumentation#20615
Conversation
There was a problem hiding this comment.
Pull request overview
Adds Nitro runtime instrumentation for unstorage tracing channels so storage/cache operations are captured as Sentry spans, aligning Nitro’s SDK behavior with Nuxt’s storage instrumentation.
Changes:
- Register
captureStorageEvents()in the Nitro server runtime plugin to subscribe tounstorage.<operation>tracing channels. - Introduce new storage-span creation logic (op/origin/cache attributes + cache-hit detection) for common storage operations.
- Add Nitro-3 e2e coverage for storage operations, storage alias methods, and cachedFunction/cachedHandler cache hit/miss behavior; bump Nitro test-app dependency to the first version with storage tracing events.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/nitro/src/runtime/plugins/server.ts | Hooks storage tracing initialization into Nitro runtime startup. |
| packages/nitro/src/runtime/hooks/captureStorageEvents.ts | New tracing-channel subscriber that creates cache/storage spans for unstorage operations. |
| dev-packages/e2e-tests/test-applications/nitro-3/tests/storage.test.ts | E2E assertions for spans + attributes for core storage methods. |
| dev-packages/e2e-tests/test-applications/nitro-3/tests/storage-aliases.test.ts | E2E assertions for spans created by storage alias APIs (get/set/has/del/remove). |
| dev-packages/e2e-tests/test-applications/nitro-3/tests/cache.test.ts | E2E assertions for cachedFunction/cachedHandler cache spans and hit/miss semantics. |
| dev-packages/e2e-tests/test-applications/nitro-3/server/api/test-storage.ts | Test endpoint exercising key storage operations. |
| dev-packages/e2e-tests/test-applications/nitro-3/server/api/test-storage-aliases.ts | Test endpoint exercising alias APIs. |
| dev-packages/e2e-tests/test-applications/nitro-3/server/api/test-cache.ts | Test endpoint exercising defineCachedFunction / defineCachedHandler. |
| dev-packages/e2e-tests/test-applications/nitro-3/package.json | Bumps Nitro to ^3.0.260429-beta to ensure storage tracing events exist. |
Comments suppressed due to low confidence (1)
packages/nitro/src/runtime/hooks/captureStorageEvents.ts:168
isResponseCacheEntrycheckskey.startsWith('nitro:handlers:'), which won't match if the key includes a storage mount prefix (e.g.cache:nitro:handlers:...). If keys are prefixed, this will prevent response-cache validation for cached handlers and can skewcache.hit. Consider adjusting the check to handle optional prefixes.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit cae896c. Configure here.
size-limit report 📦
|
- hasItem: use boolean result directly instead of generic isCacheHit - isCacheHit: handle both string and already-deserialized cache values - cache tests: replace silent if-guards with hard assertions
92ea118 to
6b37d88
Compare

Subscribes to
unstoragetracing events to create storage and cache spans for all storage operations (getItem,setItem,hasItem,removeItem,getKeys,clear, etc.).The storage instrumentation now has full feature parity with Nuxt's SDK.
Note: The instrumentation takes effect if the user uses
^3.0.260429-betasince that's the version that shipped storage events, before that version the channel will be inert.I also sneaked in a minor refactor, we don't need the
NOOPsubscribers anymore since we patched the type in thetracingChannelhelper we expose from@sentry/opentelemetry.closes #18022