Top-level import
Learn about how the Nuxt SDK adds a top-level import to the build output.
Sentry needs to be initialized before the application starts. If the default way of adding an --import
CLI flag flag does not work for you, set up the SDK for adding a top-level import
. This will import the Sentry server-side config at the top of the Nuxt server entry file. In this case, Sentry isn’t initialized before the app starts, but is set up as early as possible.
Restrictions of this installation method
This installation method has fundamental restrictions:
- It only supports limited performance instrumentation.
- Only basic
http
instrumentation will work. - No DB or framework-specific instrumentation will be available.
We recommend using this only if the --import
flag is not an option for you.
Enable the top-level import
by setting autoInjectServerSentry
:
nuxt.config.ts
export default defineNuxtConfig({
sentry: {
autoInjectServerSentry: "top-level-import",
},
});
By default, the SDK will add the Sentry server config to the build output (typically, .output/server/sentry.server.config.mjs
).
With the top-level import
, the Nuxt server entry file will look something like this:
.output/server/index.mjs
import "./sentry.server.config.mjs";
// Note: The file may have some imports and code, related to debug IDs
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").