Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Nuxt] Improve tracing functionality in ESM #13943

Closed
3 tasks done
Tracked by #9095
s1gr1d opened this issue Oct 10, 2024 · 1 comment
Closed
3 tasks done
Tracked by #9095

[Nuxt] Improve tracing functionality in ESM #13943

s1gr1d opened this issue Oct 10, 2024 · 1 comment
Assignees
Labels
Package: nuxt Issues related to the Sentry Nuxt SDK

Comments

@s1gr1d
Copy link
Member

s1gr1d commented Oct 10, 2024

Description

Problem Statement

Currently, you have to add the Sentry server config from the build output to the --input parameter of your node script like this:

node --import ./.output/server/sentry.server.config.mjs .output/server/index.mjs

The --import CLI flag makes it possible to preload a module. The server config file needs to be added with the --import flag as Sentry needs to be loaded before other modules to register a hook internally:

moduleModule.register('import-in-the-middle/hook.mjs', importMetaUrl, getRegisterOptions(esmHookConfig));

However, this needs extra configuration from the user-side and it makes the deployment setup more complicated (as different deployment providers have a different feature set and most don't fully support modification of the node run script).

Solution

The internally discussed idea is to wrap the server entry file with a dynamic import (import()), as this also runs the code after everything else (see here).

This would change the output from this:

server/
|-- index.mjs (server entry with "import './chunk/runtime.mjs'")
|-- sentry.server.config.mjs (sentry config)
|-- chunk/
|   |-- runtime.mjs (server runtime)

to this:

server/
|-- index.mjs (server entry with "import('./chunk/runtime.mjs')" and "import './sentry.server.config.mjs'")
|-- sentry.server.config.mjs (sentry config)
|-- chunk/
|   |-- runtime.mjs (server runtime)

Tasks

@s1gr1d s1gr1d self-assigned this Oct 10, 2024
@s1gr1d s1gr1d added the Package: nuxt Issues related to the Sentry Nuxt SDK label Oct 10, 2024
s1gr1d added a commit that referenced this issue Oct 14, 2024
…13945)

Feature Issue:
#13943

Adds a Rollup plugin to wrap the server entry with `import()` to load it
after Sentry was initialized.

The plugin is not yet in use (will do this in another PR - see linked
issue above)
s1gr1d added a commit that referenced this issue Oct 17, 2024
BREAKING CHANGE: The `--import` flag must not be added anymore. If it is
still set, the server-side will be initialized twice and this leads to
unexpected errors.

---

First merge this:
#13945
Part of this:
#13943

This PR makes it the default to include a rollup plugin that wraps the
server entry file with a dynamic import (`import()`). This is a
replacement for the node `--import` CLI flag.

If you still want to manually add the CLI flag you can use this option
in the `nuxt.config.ts` file:
```js
  sentry: {
    dynamicImportForServerEntry: false,
  }
```

(option name is up for discussion)
@s1gr1d
Copy link
Member Author

s1gr1d commented Oct 17, 2024

Closing this as all PRs are merged

@s1gr1d s1gr1d closed this as completed Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: nuxt Issues related to the Sentry Nuxt SDK
Projects
None yet
Development

No branches or pull requests

1 participant