Skip to content

Commit e805c81

Browse files
committed
fix: protect against double instrumentation of database instances just in case
1 parent 110de45 commit e805c81

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ import { defineNitroPlugin, useDatabase } from 'nitropack/runtime';
1616
// @ts-expect-error - This is a virtual module
1717
import { databaseInstances } from '#sentry/database-config.mjs';
1818

19+
type MaybeInstrumentedDatabase = Database & {
20+
__sentry_instrumented__?: boolean;
21+
};
22+
1923
/**
2024
* Keeps track of prepared statements that have been patched.
2125
*/
@@ -51,7 +55,12 @@ export default defineNitroPlugin(() => {
5155
}
5256
});
5357

54-
function instrumentDatabase(db: Database): void {
58+
function instrumentDatabase(db: MaybeInstrumentedDatabase): void {
59+
if (db.__sentry_instrumented__) {
60+
debug.log('[Nitro Database Plugin]: Database already instrumented. Skipping...');
61+
return;
62+
}
63+
5564
db.prepare = new Proxy(db.prepare, {
5665
apply(target, thisArg, args: Parameters<typeof db.prepare>) {
5766
const [query] = args;
@@ -83,6 +92,8 @@ function instrumentDatabase(db: Database): void {
8392
);
8493
},
8594
});
95+
96+
db.__sentry_instrumented__ = true;
8697
}
8798

8899
/**

0 commit comments

Comments
 (0)