Skip to content

Commit 0534e4d

Browse files
committed
fix: protect storage mount() from nested instrumentation for sanity check
1 parent 088146b commit 0534e4d

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

packages/nuxt/src/runtime/plugins/storage.server.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ import type { Driver, Storage } from 'unstorage';
1717
// @ts-expect-error - This is a virtual module
1818
import { userStorageMounts } from '#sentry/storage-config.mjs';
1919

20-
type MaybeInstrumentedDriver = Driver & {
20+
type MaybeInstrumented<T> = T & {
2121
__sentry_instrumented__?: boolean;
2222
};
2323

24+
type MaybeInstrumentedDriver = MaybeInstrumented<Driver>;
25+
2426
type DriverMethod = keyof Driver;
2527

2628
/**
@@ -175,7 +177,10 @@ function createMethodWrapper(
175177
* Wraps the storage mount method to instrument the driver.
176178
*/
177179
function wrapStorageMount(storage: Storage): Storage['mount'] {
178-
const original = storage.mount;
180+
const original: MaybeInstrumented<Storage['mount']> = storage.mount;
181+
if (original.__sentry_instrumented__) {
182+
return original;
183+
}
179184

180185
function mountWithInstrumentation(base: string, driver: Driver): Storage {
181186
debug.log(`[storage] Instrumenting mount: "${base}"`);
@@ -185,6 +190,8 @@ function wrapStorageMount(storage: Storage): Storage['mount'] {
185190
return original(base, instrumentedDriver);
186191
}
187192

193+
mountWithInstrumentation.__sentry_instrumented__ = true;
194+
188195
return mountWithInstrumentation;
189196
}
190197

0 commit comments

Comments
 (0)