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: Add Sentry to the bundler plugins #224

Merged
merged 23 commits into from
Jan 8, 2025

Conversation

nicholas-codecov
Copy link
Collaborator

@nicholas-codecov nicholas-codecov commented Dec 6, 2024

Description

This PR adds in the first iteration of Sentry to the bundler plugins, however, this PR does not include adding Sentry to the bundler-analyzer as that will come in a following PR as that requires a bit more work to sorted and this PR was getting big enough as it is.

Ticket: codecov/engineering-team#954

Notable Changes

  • Create Sentry helper utils and telemetry unplugin plugin - Followed along from: feat: Update Sentry telemetry to v8 getsentry/sentry-javascript-bundler-plugins#604
  • Add some spans to the Output to track some initial data points
  • Add telemetry plugin to all bundler plugins
    • Disabled telemetry from running on the integration tests
  • Fix for NextJS plugin, where we weren't using the correct webpack as we should have been doing.
    • This was included as it was causing type issues
  • Create/Update tests

@codecov-notifications
Copy link

codecov-notifications bot commented Dec 6, 2024

Copy link

codecov bot commented Dec 6, 2024

Codecov Report

Attention: Patch coverage is 58.53270% with 260 lines in your changes missing coverage. Please review.

Project coverage is 81.06%. Comparing base (0542128) to head (e167fcb).
Report is 1 commits behind head on main.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
packages/astro-plugin/src/index.ts 0.00% 27 Missing ⚠️
packages/remix-vite-plugin/src/index.ts 0.00% 27 Missing ⚠️
packages/solidstart-plugin/src/index.ts 0.00% 27 Missing ⚠️
packages/sveltekit-plugin/src/index.ts 0.00% 27 Missing ⚠️
packages/nuxt-plugin/src/index.ts 0.00% 26 Missing ⚠️
packages/vite-plugin/src/index.ts 0.00% 23 Missing ⚠️
packages/nextjs-webpack-plugin/src/index.ts 0.00% 20 Missing ⚠️
packages/rollup-plugin/src/index.ts 0.00% 18 Missing ⚠️
packages/webpack-plugin/src/index.ts 0.00% 18 Missing ⚠️
...ckages/bundler-plugin-core/src/sentry/telemetry.ts 84.82% 17 Missing ⚠️
... and 12 more
Additional details and impacted files
Components Coverage Δ
Plugin core 98.20% <93.25%> (-0.49%) ⬇️
Rollup plugin 8.69% <17.39%> (-0.89%) ⬇️
Vite plugin 8.69% <14.28%> (-1.13%) ⬇️
Webpack plugin 57.69% <16.00%> (-3.65%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@codecov-staging
Copy link

codecov-staging bot commented Dec 6, 2024

Bundle Report

Changes will increase total bundle size by 10.36kB (0.17%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
@codecov/bundler-plugin-core-cjs 64.28kB 5.25kB (8.89%) ⬆️
@codecov/bundler-plugin-core-esm 14.37kB 1.94kB (15.6%) ⬆️
@codecov/vite-plugin-cjs 3.14kB 303 bytes (10.67%) ⬆️
@codecov/nuxt-plugin-esm 855 bytes 372 bytes (-30.32%) ⬇️
@codecov/nextjs-webpack-plugin-esm 2.3kB 429 bytes (22.88%) ⬆️
@codecov/webpack-plugin-cjs 4.96kB 312 bytes (6.72%) ⬆️
@codecov/solidstart-plugin-cjs 1.69kB 368 bytes (27.75%) ⬆️
@codecov/sveltekit-plugin-cjs 1.69kB 367 bytes (27.8%) ⬆️
@codecov/sveltekit-plugin-esm 891 bytes 198 bytes (-18.18%) ⬇️
@codecov/remix-vite-plugin-esm 1.43kB 341 bytes (31.28%) ⬆️
@codecov/nuxt-plugin-cjs 1.74kB 337 bytes (24.05%) ⬆️
@codecov/nextjs-webpack-plugin-cjs 2.58kB 471 bytes (22.3%) ⬆️
@codecov/webpack-plugin-esm 3.39kB 209 bytes (-5.81%) ⬇️
@codecov/rollup-plugin-cjs 3.17kB 316 bytes (11.07%) ⬆️
@codecov/remix-vite-plugin-cjs 1.68kB 363 bytes (27.65%) ⬆️
@codecov/astro-plugin-cjs 1.68kB 337 bytes (25.04%) ⬆️
@codecov/example-sveltekit-app-client-esm 727.49kB 2 bytes (0.0%) ⬆️
@codecov/example-sveltekit-app-server-esm 984.45kB 1 bytes (0.0%) ⬆️

Copy link

codecov bot commented Dec 6, 2024

Bundle Report

Changes will decrease total bundle size by 30.43kB (-0.48%) ⬇️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
@codecov/vite-plugin-cjs 3.14kB 303 bytes (10.67%) ⬆️
@codecov/remix-vite-plugin-cjs 1.68kB 363 bytes (27.65%) ⬆️
@codecov/bundler-plugin-core-cjs 64.28kB 5.25kB (8.89%) ⬆️
@codecov/bundler-plugin-core-esm 14.37kB 38.79kB (-72.96%) ⬇️
@codecov/rollup-plugin-cjs 3.17kB 316 bytes (11.07%) ⬆️
@codecov/nuxt-plugin-cjs 1.74kB 337 bytes (24.05%) ⬆️
@codecov/rollup-plugin-esm 1.3kB 1.07kB (-45.02%) ⬇️
@codecov/nuxt-plugin-esm 1.54kB 315 bytes (25.67%) ⬆️
@codecov/sveltekit-plugin-cjs 1.69kB 367 bytes (27.8%) ⬆️
@codecov/webpack-plugin-cjs 4.96kB 312 bytes (6.72%) ⬆️
@codecov/solidstart-plugin-cjs 1.69kB 368 bytes (27.75%) ⬆️
@codecov/solidstart-plugin-esm 1.44kB 346 bytes (31.71%) ⬆️
@codecov/example-sveltekit-app-client-esm 727.49kB 2 bytes (-0.0%) ⬇️
@codecov/example-sveltekit-app-server-esm 984.45kB 1 bytes (-0.0%) ⬇️
@codecov/nextjs-webpack-plugin-cjs 2.58kB 471 bytes (22.3%) ⬆️
@codecov/bundle-analyzer-esm 3.45kB 347 bytes (11.17%) ⬆️
@codecov/astro-plugin-cjs 1.68kB 337 bytes (25.04%) ⬆️

Copy link
Collaborator

@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.

Hey, I heard you were looking for a review from the JS SDK team, so I took a look (also, sorry for the delay!). I think in general, this LGTM. We're taking care of removing stack traces and potential PII and the client/scope handling seems to be mostly in line with the Sentry bundler plugins 👍

Are there specific questions or things you'd like us to look at in detail?

.changeset/green-goats-thank.md Outdated Show resolved Hide resolved
@nicholas-codecov nicholas-codecov force-pushed the gh-eng-954-add-sentry-to-plugins branch from 0103d28 to d04efd9 Compare January 2, 2025 14:20
Copy link
Contributor

@suejung-sentry suejung-sentry left a comment

Choose a reason for hiding this comment

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

Had a couple questions, but looked good!

pluginVersion: PLUGIN_VERSION,
options,
bundler: unpluginMetaContext.framework,
metaFramework: "astro",
Copy link
Contributor

Choose a reason for hiding this comment

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

What do these 2 keys represent again? bundler vs. metaFramework? On first glance, I would have expected the values to be flipped here with bundler being "astro" and the metaFramework being from the enum from unplugin.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Bundler is the underlying bundler (Rollup, Vite, Webpack), this value is derived from Unplugin itself, whereas the meta-framework value is what we pass through as things like Astro are built on-top of bundlers (Vite in this case), bundlers being the "lowest" system in the stack.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it, thanks!
If we can declare an enum or type for the acceptable strings that may be nice in the future.

platform: "node",
runtime: { name: "node", version: global.process.version },

dsn: "https://[email protected]/4506739665207296",
Copy link
Contributor

Choose a reason for hiding this comment

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

Any thoughts on making a network call to Codecov to fetch this dsn? If we hardcode it here, we won't be able to change it for anyone using old versions of the plugin. Maybe overkill since it will make it slower and add more failure pathways, though.
Do we have any other examples of how it's done around in Sentry as guidance perhaps?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'd like to avoid any extra calls, as well as the work to maintain an endpoint to distribute this value. Typically for any client based application the DSN is just shipped with the package, this is how it is done for their bundler plugins.

Can you expand upon your concerns around users using older versions of the plugin?

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay great, good to know that's the usual pattern!

Oh yeah re: older versions of plugin - I mean say version 1 has this DSN hardcoded and that's what they're running. Say a year down the road we need to change the way we configure things and we have a new DSN for our org the old one gets deprecated, and hardcode the new one in version 2. Anyone still on version 1 is broken until they upgrade.
Basically backwards compatibility can potentially be annoying. This is probably overengineering for where we are though so we can go with hardcoding!

telemetryPlugin({
sentryClient: sentryConfig.sentryClient,
sentryScope: sentryConfig.sentryScope,
shouldSendTelemetry: options.telemetry,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I've lost track a little on why different keys of telemetry, enableTelemetry and shouldSendTelemetry across the different layers. Was it intentional to name them differently? Also should we create and push this plugin into the list at all if it's not enabled? Maybe missing something on that

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

okay i've gone through and went with telemetry for everything ... this has been in progress for too long I guess I started coming up with new names 😭

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah nice, sorry for any trouble.
That looks good!
My other thought in there was buried - what do you think RE: only creating/pushing the plugin into the list if it's enabled (to save running any unneeded code)?
We can do that in a separate pass if we think it's worthwhile


interface SentryConfig {
sentryClient?: Client;
sentryScope?: Scope;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: thoughts on naming this as client and scope since they are already in something named SentryConfig?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Hrrmrmrmrm, for this one, I think i'll leave it as is, i tend to lean towards more verbose naming. We may be looking at adding in amplitude and if we do there may be more clients (idk about scopes) but this keeps it a bit clearer as to what's going on with these.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure sounds good - thanks!

}
debug(`Error uploading stats: "${error}"`, { enabled: this.debug });
return;
throw error;
Copy link
Contributor

Choose a reason for hiding this comment

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

Was it intentional to remove the if (emitError) throw error check here? It's possible more things will slip through to throw that used to be "swallowed" with this change I think, in case that has any unintended effects.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Uhh this was a newly added in throw, sooooo nice catch and my bad 😅

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh okay sounds good! I think either way works if we have some errors we treat as more "catastrophic". Adding the check here makes sense - thanks!

},
};
};
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nice, these look tricky

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

#thanks-sentry 💪

@nicholas-codecov nicholas-codecov merged commit 01de9e5 into main Jan 8, 2025
65 of 69 checks passed
@nicholas-codecov nicholas-codecov deleted the gh-eng-954-add-sentry-to-plugins branch January 8, 2025 18:04
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.

3 participants