Skip to content

feat(tracing): enable tracing channels for unstorage#4226

Merged
pi0 merged 3 commits into
nitrojs:mainfrom
logaretm:feat/unstorage-tracing-channel
Apr 24, 2026
Merged

feat(tracing): enable tracing channels for unstorage#4226
pi0 merged 3 commits into
nitrojs:mainfrom
logaretm:feat/unstorage-tracing-channel

Conversation

@logaretm
Copy link
Copy Markdown
Member

Enables tracing channels for unstorage calls when tracingChannel config option is enabled by wrapping the call with the withTracing helper which is available as of the current minimum unstorage@2.0.0-alpha.7.

We should do the same for db0 when it gets released.

Copilot AI review requested due to automatic review settings April 23, 2026 21:05
@logaretm logaretm requested a review from pi0 as a code owner April 23, 2026 21:05
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 23, 2026

@logaretm is attempting to deploy a commit to the Nitro Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 23, 2026

📝 Walkthrough

Walkthrough

This 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

Cohort / File(s) Summary
Type definitions
src/types/config.ts
Added optional unstorage?: boolean property to the TracingOptions interface.
Tracing configuration
src/config/resolvers/tracing.ts
Enabled the unstorage tracing channel by default when tracingChannel is initialized.
Virtual storage module
src/build/virtual/storage.ts
Added conditional detection of nitro.options.tracingChannel?.unstorage to wrap the storage instance with withTracing from unstorage/tracing when enabled.
Unit tests
test/unit/virtual-storage.test.ts
Added tests verifying that the virtual storage template correctly handles tracing wrapping based on the tracingChannel.unstorage configuration flag.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly explains the change: enabling tracing channels for unstorage when tracingChannel is enabled, using withTracing helper, and notes future plans for db0.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title follows conventional commits format with type 'feat' and scope 'tracing', accurately describing the main change of enabling unstorage tracing channels.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?: boolean to tracing configuration types and defaults
  • Wrap unstorage’s createStorage() result with withTracing() 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()

Comment thread src/build/virtual/storage.ts
).template();
expect(template).not.toContain("withTracing");
});

Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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)");
});

Copilot uses AI. Check for mistakes.
Comment thread src/config/resolvers/tracing.ts
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between f92fb7b and 6a42b9b.

📒 Files selected for processing (4)
  • src/build/virtual/storage.ts
  • src/config/resolvers/tracing.ts
  • src/types/config.ts
  • test/unit/virtual-storage.test.ts

Comment thread src/build/virtual/storage.ts
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 23, 2026

Open in StackBlitz

npm i https://pkg.pr.new/nitro@4226

commit: 6a42b9b

@pi0 pi0 changed the title feat(tracing): Enable tracing channels for unstorage feat(tracing): enable tracing channels for unstorage Apr 24, 2026
Copy link
Copy Markdown
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thnx!

@pi0 pi0 merged commit f8cf6cc into nitrojs:main Apr 24, 2026
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants