Skip to content

Commit 336a236

Browse files
authored
feat(nuxt): Improve logs about adding Node option 'import' (getsentry#13726)
Adding the node option can be a confusing step. This adds a log output which already includes the correct file path to add. It looks like this: ``` [Sentry] Using your sentry.server.config.ts file for the server-side Sentry configuration. Make sure to add the Node option import to the Node command where you deploy and/or run your application. This preloads the Sentry configuration at server startup. You can do this via a command-line flag (node --import ./.output/server/sentry.server.config.mjs [...]) or via an environment variable (NODE_OPTIONS='--import ./.output/server/sentry.server.config.mjs' node [...]). ```
1 parent 2ab7518 commit 336a236

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

packages/nuxt/src/module.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import * as path from 'path';
12
import { addPlugin, addPluginTemplate, addServerPlugin, createResolver, defineNuxtModule } from '@nuxt/kit';
23
import { consoleSandbox } from '@sentry/utils';
34
import type { SentryNuxtModuleOptions } from './common/types';
@@ -72,10 +73,16 @@ export default defineNuxtModule<ModuleOptions>({
7273
addSentryTopImport(moduleOptions, nitro);
7374
} else {
7475
if (moduleOptions.debug) {
76+
const serverDirResolver = createResolver(nitro.options.output.serverDir);
77+
const serverConfigPath = serverDirResolver.resolve('sentry.server.config.mjs');
78+
79+
// For the default nitro node-preset build output this relative path would be: ./.output/server/sentry.server.config.mjs
80+
const serverConfigRelativePath = `.${path.sep}${path.relative(nitro.options.rootDir, serverConfigPath)}`;
81+
7582
consoleSandbox(() => {
7683
// eslint-disable-next-line no-console
7784
console.log(
78-
`[Sentry] Using your \`${serverConfigFile}\` file for the server-side Sentry configuration. In case you have a \`public/instrument.server\` file, the \`public/instrument.server\` file will be ignored. Make sure the file path in your node \`--import\` option matches the Sentry server config file in your \`.output\` folder and has a \`.mjs\` extension.`,
85+
`[Sentry] Using your \`${serverConfigFile}\` file for the server-side Sentry configuration. Make sure to add the Node option \`import\` to the Node command where you deploy and/or run your application. This preloads the Sentry configuration at server startup. You can do this via a command-line flag (\`node --import ${serverConfigRelativePath} [...]\`) or via an environment variable (\`NODE_OPTIONS='--import ${serverConfigRelativePath}' node [...]\`).`,
7986
);
8087
});
8188
}

0 commit comments

Comments
 (0)