feat(tracing): enable tracing channels for unstorage#4226
Conversation
|
@logaretm is attempting to deploy a commit to the Nitro Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughThis PR extends tracing support to unstorage by adding a configuration flag to TracingOptions, enabling it by default when tracing is active, and conditionally wrapping the storage instance with a tracing utility. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Enables opt-in tracing for unstorage by adding a new tracingChannel.unstorage option and wiring it into the virtual storage template generation.
Changes:
- Add
unstorage?: booleanto tracing configuration types and defaults - Wrap
unstorage’screateStorage()result withwithTracing()when enabled - Add unit tests covering template output when tracing is enabled/disabled
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| test/unit/virtual-storage.test.ts | Adds unit tests verifying the generated virtual storage template includes/excludes tracing wrappers |
| src/types/config.ts | Extends TracingOptions with an unstorage channel flag |
| src/config/resolvers/tracing.ts | Defaults tracingChannel.unstorage to true when tracing options are resolved |
| src/build/virtual/storage.ts | Conditionally imports unstorage/tracing and wraps returned storage with withTracing() |
| ).template(); | ||
| expect(template).not.toContain("withTracing"); | ||
| }); | ||
|
|
There was a problem hiding this comment.
The tests cover unstorage: false and unstorage: true, but they don't cover the defaulting behavior introduced in the resolver (i.e., tracing enabled with tracingChannel set but without an explicit unstorage property). Add a test case where tracingChannel is an object missing unstorage (and, if supported, a case where tracingChannel is true) to ensure the template behavior matches the intended defaults.
| it("wraps storage with withTracing when tracingChannel.unstorage is omitted", () => { | |
| const template = storage(createNitroStub({ srvx: true, h3: true })).template(); | |
| expect(template).toContain(`import { withTracing } from 'unstorage/tracing'`); | |
| expect(template).toContain("return withTracing(storage)"); | |
| }); |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/build/virtual/storage.ts`:
- Around line 27-33: The assets storage created via createStorage (exported as
assets in src/build/virtual/server-assets.ts) is not being conditionally wrapped
with withTracing, so direct imports of assets bypass tracing; to fix, apply the
same tracingEnabled guard used in src/build/virtual/storage.ts to wrap the
assets export: detect tracingEnabled (same typeof nitro.options.tracingChannel
=== "object" check or reuse the existing flag) and export assets as
withTracing(createStorage(...)) when true, otherwise export createStorage(...)
unchanged; keep initStorage and storage.mount behavior intact.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 02f969ad-c2a2-40b1-b649-e6b860b59aad
📒 Files selected for processing (4)
src/build/virtual/storage.tssrc/config/resolvers/tracing.tssrc/types/config.tstest/unit/virtual-storage.test.ts
commit: |
Enables tracing channels for
unstoragecalls whentracingChannelconfig option is enabled by wrapping the call with thewithTracinghelper which is available as of the current minimumunstorage@2.0.0-alpha.7.We should do the same for
db0when it gets released.