Skip to content

feat(nuxt): Inject sentry config with Nuxt addPluginTemplate #12760

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

Merged
merged 8 commits into from
Jul 5, 2024

Conversation

s1gr1d
Copy link
Member

@s1gr1d s1gr1d commented Jul 4, 2024

Adding the import snippet with addPluginTemplate (docs) instead of modifying the root component code.

closes #12759

@s1gr1d s1gr1d requested review from mydea and lforst July 4, 2024 12:21
@s1gr1d s1gr1d changed the title feat(nuxt): Add sentry config with plugin template feat(nuxt): Inject sentry config with Nuxt addPluginTemplate Jul 4, 2024
@s1gr1d s1gr1d added the Package: nuxt Issues related to the Sentry Nuxt SDK label Jul 4, 2024
Copy link
Contributor

github-actions bot commented Jul 4, 2024

size-limit report 📦

Path Size
@sentry/browser 22.28 KB (0%)
@sentry/browser (incl. Tracing) 33.43 KB (0%)
@sentry/browser (incl. Tracing, Replay) 69.18 KB (0%)
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 62.51 KB (0%)
@sentry/browser (incl. Tracing, Replay with Canvas) 73.24 KB (0%)
@sentry/browser (incl. Tracing, Replay, Feedback) 85.87 KB (0%)
@sentry/browser (incl. Tracing, Replay, Feedback, metrics) 87.73 KB (0%)
@sentry/browser (incl. metrics) 26.57 KB (0%)
@sentry/browser (incl. Feedback) 38.93 KB (0%)
@sentry/browser (incl. sendFeedback) 26.9 KB (0%)
@sentry/browser (incl. FeedbackAsync) 31.52 KB (0%)
@sentry/react 25.02 KB (0%)
@sentry/react (incl. Tracing) 36.46 KB (0%)
@sentry/vue 26.39 KB (0%)
@sentry/vue (incl. Tracing) 35.29 KB (0%)
@sentry/svelte 22.41 KB (0%)
CDN Bundle 23.5 KB (0%)
CDN Bundle (incl. Tracing) 35.19 KB (0%)
CDN Bundle (incl. Tracing, Replay) 69.29 KB (0%)
CDN Bundle (incl. Tracing, Replay, Feedback) 74.48 KB (0%)
CDN Bundle - uncompressed 68.97 KB (0%)
CDN Bundle (incl. Tracing) - uncompressed 103.98 KB (0%)
CDN Bundle (incl. Tracing, Replay) - uncompressed 214.38 KB (0%)
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 227.09 KB (0%)
@sentry/nextjs (client) 36.35 KB (0%)
@sentry/sveltekit (client) 34.07 KB (0%)
@sentry/node 130.84 KB (+0.01% 🔺)
@sentry/node - without tracing 91.86 KB (+0.01% 🔺)
@sentry/aws-serverless 117.03 KB (+0.01% 🔺)

@@ -42,7 +42,7 @@
"nuxt": "3.x"
},
"dependencies": {
"@nuxt/kit": "^3.12.2",
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you know, is it normal for plugins like sentry to directly depend on nuxt kit or is it more like a peer dep thing?

Copy link
Member Author

Choose a reason for hiding this comment

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

I saw it as a dependency in other Nuxt modules and therefore added it there too

Copy link
Contributor

Choose a reason for hiding this comment

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

l: I find it odd to place this file into a common folder. The common folder usually denotes things that may run in any runtime. The code in this file is only allowed to run during the build right? Same goes for the other build code.

const serverConfigFile = findDefaultSdkInitFile('server');

if (serverConfigFile) {
nuxt.options.alias['#sentry-server-config'] = buildDirResolver.resolve(`/${serverConfigFile}`);
Copy link
Contributor

Choose a reason for hiding this comment

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

l: Maybe there's a way to get rid of this alias indirection by rendering buildDirResolver.resolve(/${clientConfigFile}) directly into the template.

if (clientConfigFile) {
nuxt.options.alias['#sentry-client-config'] = buildDirResolver.resolve(`/${clientConfigFile}`);

injectSentryConfigImport('#sentry-client-config');
Copy link
Contributor

Choose a reason for hiding this comment

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

m: I have a feeling we're including both templates for client and server in both bundles, since we are not setting the mode option.

Comment on lines 86 to 90
if (import.meta.env.SSR) {
Sentry.init({
dsn: env.DSN,
});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

h: I think if we set a mode in addPluginTemplate we can get rid of the if statements around sentry.init.

@s1gr1d s1gr1d requested a review from lforst July 4, 2024 13:17
@s1gr1d s1gr1d merged commit ecc95e7 into develop Jul 5, 2024
88 of 89 checks passed
@s1gr1d s1gr1d deleted the sig/nuxt-plugin-template branch July 5, 2024 17:32
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

Successfully merging this pull request may close these issues.

Add side effect import of sentry config to Nuxt app
3 participants