From df360c7a0ca333cae1f29e05513efdf0765b5677 Mon Sep 17 00:00:00 2001 From: Abdelrahman Awad Date: Thu, 23 Apr 2026 16:59:31 -0400 Subject: [PATCH 1/3] feat(tracing): wrap storage with unstorage tracing channel --- src/build/virtual/storage.ts | 8 +++++++- src/config/resolvers/tracing.ts | 1 + src/types/config.ts | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/build/virtual/storage.ts b/src/build/virtual/storage.ts index 6111f3bb42..46f29536a0 100644 --- a/src/build/virtual/storage.ts +++ b/src/build/virtual/storage.ts @@ -24,8 +24,14 @@ export default function storage(nitro: Nitro) { const driverImports = [...new Set(mounts.map((m) => m.driver))]; + const tracingEnabled = !!( + typeof nitro.options.tracingChannel === "object" && + nitro.options.tracingChannel?.unstorage + ); + return /* js */ ` import { createStorage } from 'unstorage' +${tracingEnabled ? `import { withTracing } from 'unstorage/tracing'` : ""} import { assets } from '#nitro/virtual/server-assets' ${driverImports.map((i) => genImport(i, genSafeVariableName(i))).join("\n")} @@ -39,7 +45,7 @@ export function initStorage() { `storage.mount('${m.path}', ${genSafeVariableName(m.driver)}(${JSON.stringify(m.opts)}))` ) .join("\n")} - return storage + return ${tracingEnabled ? "withTracing(storage)" : "storage"} } `; }, diff --git a/src/config/resolvers/tracing.ts b/src/config/resolvers/tracing.ts index 516435fdeb..6764a0ebb5 100644 --- a/src/config/resolvers/tracing.ts +++ b/src/config/resolvers/tracing.ts @@ -5,6 +5,7 @@ export async function resolveTracingOptions(options: NitroOptions) { options.tracingChannel = { srvx: true, h3: true, + unstorage: true, ...(typeof options.tracingChannel === "object" ? options.tracingChannel : {}), }; options.plugins = options.plugins || []; diff --git a/src/types/config.ts b/src/types/config.ts index e6b31ce531..16ca89535b 100644 --- a/src/types/config.ts +++ b/src/types/config.ts @@ -363,6 +363,7 @@ export interface ServerAssetDir { export interface TracingOptions { srvx?: boolean; h3?: boolean; + unstorage?: boolean; } // Storage mounts From 54996488c0a90d3a51d5becb484818d9bea048c1 Mon Sep 17 00:00:00 2001 From: Abdelrahman Awad Date: Thu, 23 Apr 2026 17:03:22 -0400 Subject: [PATCH 2/3] test(tracing): cover unstorage tracing channel template --- test/unit/virtual-storage.test.ts | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 test/unit/virtual-storage.test.ts diff --git a/test/unit/virtual-storage.test.ts b/test/unit/virtual-storage.test.ts new file mode 100644 index 0000000000..a81885eb93 --- /dev/null +++ b/test/unit/virtual-storage.test.ts @@ -0,0 +1,42 @@ +import { describe, expect, it } from "vitest"; +import type { Nitro } from "nitro/types"; + +import storage from "../../src/build/virtual/storage.ts"; + +function createNitroStub(tracingChannel: Nitro["options"]["tracingChannel"]): Nitro { + return { + options: { + dev: true, + preset: "nitro-dev", + storage: {}, + devStorage: {}, + tracingChannel, + }, + } as unknown as Nitro; +} + +describe("virtual/storage template", () => { + it("does not wrap storage when tracingChannel is disabled", () => { + const template = storage(createNitroStub(undefined)).template(); + expect(template).not.toContain("withTracing"); + expect(template).not.toContain("unstorage/tracing"); + expect(template).toContain("return storage"); + }); + + it("does not wrap storage when tracingChannel.unstorage is false", () => { + const template = storage( + createNitroStub({ srvx: true, h3: true, unstorage: false }) + ).template(); + expect(template).not.toContain("withTracing"); + }); + + it("wraps storage with withTracing when tracingChannel.unstorage is true", () => { + const template = storage( + createNitroStub({ srvx: true, h3: true, unstorage: true }) + ).template(); + expect(template).toContain( + `import { withTracing } from 'unstorage/tracing'` + ); + expect(template).toContain("return withTracing(storage)"); + }); +}); From 6a42b9bc431bd4296570ac51533a0aeafebf1b2f Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Thu, 23 Apr 2026 21:06:11 +0000 Subject: [PATCH 3/3] chore: apply automated updates --- src/build/virtual/storage.ts | 3 +-- test/unit/virtual-storage.test.ts | 8 ++------ 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/build/virtual/storage.ts b/src/build/virtual/storage.ts index 46f29536a0..acad460c45 100644 --- a/src/build/virtual/storage.ts +++ b/src/build/virtual/storage.ts @@ -25,8 +25,7 @@ export default function storage(nitro: Nitro) { const driverImports = [...new Set(mounts.map((m) => m.driver))]; const tracingEnabled = !!( - typeof nitro.options.tracingChannel === "object" && - nitro.options.tracingChannel?.unstorage + typeof nitro.options.tracingChannel === "object" && nitro.options.tracingChannel?.unstorage ); return /* js */ ` diff --git a/test/unit/virtual-storage.test.ts b/test/unit/virtual-storage.test.ts index a81885eb93..d842d96083 100644 --- a/test/unit/virtual-storage.test.ts +++ b/test/unit/virtual-storage.test.ts @@ -31,12 +31,8 @@ describe("virtual/storage template", () => { }); it("wraps storage with withTracing when tracingChannel.unstorage is true", () => { - const template = storage( - createNitroStub({ srvx: true, h3: true, unstorage: true }) - ).template(); - expect(template).toContain( - `import { withTracing } from 'unstorage/tracing'` - ); + const template = storage(createNitroStub({ srvx: true, h3: true, unstorage: true })).template(); + expect(template).toContain(`import { withTracing } from 'unstorage/tracing'`); expect(template).toContain("return withTracing(storage)"); }); });