Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/nuxt/src/runtime/plugins/database.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import {
type StartSpanOptions,
} from '@sentry/core';
import type { Database, PreparedStatement } from 'db0';
import { defineNitroPlugin, useDatabase } from 'nitropack/runtime';
import type { NitroAppPlugin } from 'nitropack';
import { useDatabase } from 'nitropack/runtime';
import type { DatabaseConnectionConfig as DatabaseConfig } from 'nitropack/types';
// @ts-expect-error - This is a virtual module
import { databaseConfig } from '#sentry/database-config.mjs';
Expand All @@ -34,7 +35,7 @@ const SENTRY_ORIGIN = 'auto.db.nuxt';
/**
* Creates a Nitro plugin that instruments the database calls.
*/
export default defineNitroPlugin(() => {
export default (() => {
try {
const _databaseConfig = databaseConfig as Record<string, DatabaseConfig>;
const databaseInstances = Object.keys(databaseConfig);
Expand All @@ -56,7 +57,7 @@ export default defineNitroPlugin(() => {

debug.error('[Nitro Database Plugin]: Failed to instrument database:', error);
}
});
}) satisfies NitroAppPlugin;

/**
* Instruments a database instance with Sentry.
Expand Down
6 changes: 3 additions & 3 deletions packages/nuxt/src/runtime/plugins/sentry.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import {
withIsolationScope,
} from '@sentry/core';
import type { EventHandler, H3Event } from 'h3';
import { defineNitroPlugin } from 'nitropack/runtime';
import type { NitroAppPlugin } from 'nitropack';
import type { NuxtRenderHTMLContext } from 'nuxt/app';
import { sentryCaptureErrorHook } from '../hooks/captureErrorHook';
import { updateRouteBeforeResponse } from '../hooks/updateRouteBeforeResponse';
import { addSentryTracingMetaTags } from '../utils';

export default defineNitroPlugin(nitroApp => {
export default (nitroApp => {
nitroApp.h3App.handler = patchEventHandler(nitroApp.h3App.handler);

nitroApp.hooks.hook('beforeResponse', updateRouteBeforeResponse);
Expand All @@ -36,7 +36,7 @@ export default defineNitroPlugin(nitroApp => {
);
}
});
});
}) satisfies NitroAppPlugin;

function patchEventHandler(handler: EventHandler): EventHandler {
return new Proxy(handler, {
Expand Down
7 changes: 4 additions & 3 deletions packages/nuxt/src/runtime/plugins/storage.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import {
startSpan,
type StartSpanOptions,
} from '@sentry/core';
import { defineNitroPlugin, useStorage } from 'nitropack/runtime';
import type { NitroAppPlugin } from 'nitropack';
import { useStorage } from 'nitropack/runtime';
Copy link
Member

Choose a reason for hiding this comment

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

q: Is there no top-level export for useStage? Iirc Pooya mentioned not needing to import from /runtime anymore.

Copy link
Member Author

Choose a reason for hiding this comment

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

No, not in nitropack. Only from Nitro v3 onwards, it can be imported from nitro.

We probably need two different plugins for v2 and v3 here as we need the import for useStorage and useDatabase.

See docs here: https://v3.nitro.build/docs/migration#changed-nitro-subpath-imports

import type { CacheEntry, ResponseCacheEntry } from 'nitropack/types';
import type { Driver, Storage } from 'unstorage';
// @ts-expect-error - This is a virtual module
Expand All @@ -34,7 +35,7 @@ const CACHE_HIT_METHODS = new Set<DriverMethod>(['hasItem', 'getItem', 'getItemR
/**
* Creates a Nitro plugin that instruments the storage driver.
*/
export default defineNitroPlugin(async _nitroApp => {
export default (async _nitroApp => {
// This runs at runtime when the Nitro server starts
const storage = useStorage();
// Mounts are suffixed with a colon, so we need to add it to the set items
Expand Down Expand Up @@ -63,7 +64,7 @@ export default defineNitroPlugin(async _nitroApp => {

// Wrap the mount method to instrument future mounts
storage.mount = wrapStorageMount(storage);
});
}) satisfies NitroAppPlugin;

/**
* Instruments a driver by wrapping all method calls using proxies.
Expand Down
Loading