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

feat(nuxt): Setup source maps with vite config #13018

Merged
merged 6 commits into from
Jul 24, 2024
Merged

Conversation

s1gr1d
Copy link
Member

@s1gr1d s1gr1d commented Jul 23, 2024

Closes #13017

@s1gr1d s1gr1d requested review from Lms24 and lforst July 23, 2024 13:36
export default defineNuxtConfig({
modules: ['@sentry/nuxt/module'],
sentry: {
debug: true,
Copy link
Member

Choose a reason for hiding this comment

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

hmm, no strong feelings, but it feels a bit confusing that this only turns on debug mode for the vite plugin, right? It seems easy to think that this also enables debug mode for sentry itself 🤔 would it make sense to name this in a different, more specific way, e.g. viteDebug or debugVitePlugin, something along these lines? Not sure how this works in other SDKs though, if we do the same there it's probably fine.

Copy link
Member

Choose a reason for hiding this comment

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

I would keep a top-level debug option like this. Makes it very easy to ask users to enable debug mode to debug all issues related to build time stuff.

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 was thinking about the same actually before creating this PR. But this debug option is actually quite nice for the build-time debug. The debug flag in init only works during runtime. To make it more explicit, this could be renamed to buildDebug?

Copy link
Member

Choose a reason for hiding this comment

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

I would keep it at debug tbh

Copy link
Member

Choose a reason for hiding this comment

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

Fwiw (no strong opinions but from having dealt with this before): We have this pattern of multiple debug properties in different files in SvelteKit and Astro and so far people haven't complained about it. If we point out well in the JSDoc what kind of logging this specific option enables, I think going simply with debug is fine.
Especially considering, this flag can be used everywhere within the nuxt module (so not just within the vite plugin I assume) I wouldn't give it a too specific name.

* The SDK options are mostly handled inside the `init` function in separate files (see type `SentryNuxtOptions`).
* Other options, such as the source maps options are added inside the `nuxt.config.ts` to be able to access those options during build time and modify the Vite config.
*/
export type SentryNuxtModuleOptions = Pick<Options, 'debug'> & SourceMapsOptions;
Copy link
Member

Choose a reason for hiding this comment

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

  • Any reason you picked debug off the SDK options? I would just add a new debug field and document it separately, because it has nothing to do with the SDK init debug option.
  • I would phrase the JS doc for this type differently. Imagine you are a user hovering over the type. I would start with something like "Build options used by the Sentry Nuxt SDK. ...". In general I would steer away from describing how things are not and describe what they are.
  • I would restructure this type and the SourceMapsOptions type so that it is not just an interface with one property.

});

viteInlineConfig.plugins = viteInlineConfig.plugins || [];
viteInlineConfig.plugins.push(...sentryPlugins);
Copy link
Member

Choose a reason for hiding this comment

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

I think you should be able to do

Suggested change
viteInlineConfig.plugins.push(...sentryPlugins);
viteInlineConfig.plugins.push(sentryPlugins);

and I highly recommend because you theoretically can not assume that the vite plugin is an array.

Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

Looks great so far! Most things were already addressed in previews reviews. Feel free to defer the source maps deletion part to a follow up PR but we should think about it before going stable with the SDK.

export default defineNuxtConfig({
modules: ['@sentry/nuxt/module'],
sentry: {
debug: true,
Copy link
Member

Choose a reason for hiding this comment

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

Fwiw (no strong opinions but from having dealt with this before): We have this pattern of multiple debug properties in different files in SvelteKit and Astro and so far people haven't complained about it. If we point out well in the JSDoc what kind of logging this specific option enables, I think going simply with debug is fine.
Especially considering, this flag can be used everywhere within the nuxt module (so not just within the vite plugin I assume) I wouldn't give it a too specific name.


if ((sourceMapsUploadOptions.enabled ?? true) && viteInlineConfig.mode !== 'development') {
const sentryPlugins = sentryVitePlugin({
org: sourceMapsUploadOptions.org ?? process.env.SENTRY_ORG,
Copy link
Member

Choose a reason for hiding this comment

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

l: Do we need to pass in the env variable fallbacks explicitly? the plugin itself should pick them up, right?

viteInlineConfig.plugins.push(...sentryPlugins);

viteInlineConfig.build = viteInlineConfig.build || {};
viteInlineConfig.build.sourcemap = true;
Copy link
Member

Choose a reason for hiding this comment

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

m: If viteInlineConfig.build.sourcemap wasn't true before we set it, I'd recommend to log out a warning that we're changing their build config to enable emitting source maps. It's fine to do that but users are worried that their source maps then get deployed to prod.
I'd recommend we expose the filesToDeleteAfterUpload option from the plugin and hint them in the warning that they should set it if they want to delete source maps afterwards again.

@s1gr1d s1gr1d requested review from mydea, lforst and Lms24 July 24, 2024 09:44
Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

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

Thanks for addressing my feedback! Good to go from my end!

@@ -108,8 +108,8 @@ export async function makeCustomSentryVitePlugins(options?: CustomSentryVitePlug

// Modify the config to generate source maps
config: config => {
const sourceMapsPreviouslyEnabled = !config.build?.sourcemap;
if (debug && sourceMapsPreviouslyEnabled) {
const sourceMapsPreviouslyNotEnabled = !config.build?.sourcemap;
Copy link
Member

Choose a reason for hiding this comment

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

thx for fixing! :)

@s1gr1d s1gr1d merged commit ea07ec7 into develop Jul 24, 2024
125 checks passed
@s1gr1d s1gr1d deleted the sig/sourcemaps-nuxt branch July 24, 2024 10:58
Copy link
Member Author

Choose a reason for hiding this comment

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

lock changes are from this PR: #12920

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nuxt: Add source maps support
4 participants