-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
@sentry/nextjs bundle size and tree shaking #7680
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
Comments
We do have a continuous effort to keep bundle size low. Unfortunately for the amount of features we provide (and users want to see and use) there is a trade-off to be had. Trust me when I say, that the term "bundle size" is a term that is mentioned almost daily in the team ^^ I am gonna close this issue because it is not actionable at the moment. Feel free to reopen if you have a suspicion that this is a) a regression or b) if you have an idea of how to resolve this. In case of a) please also provide a link to a website where we can check if unwanted code is included. |
Inclusion of I would think that NOT doing |
I couldn't reproduce this exact issue in a test app but something caught my eye and I have a feeling it is gonna fix this: #7710 |
Do you know when that change might make it into a release @lforst ? I'm evaluating Sentry with Next at the moment at work, but adding it has taken us over our performance budget. |
@philwolstenholme probably sometime in the next few days. Just to confirm what you mean by performance budget: It's bundle size right and not Sentry Transaction quota, right? |
@lforst ah yes sorry, it's nothing to do with Sentry, it's Lighthouse in CI running against a deployment preview URL. |
Another option is not bundling Sentry in your main bundle (if you can accept the tradeoff of not having Sentry available from the very first millisecond): // sentry.js
export default function sentry() {
Sentry.init();
} // main.js
import("./sentry").then((sentry) => sentry.default()); |
@luukdv absolutely. I've been looking at ways of removing our dependency on the sentry/nextjs package and just pulling everything in manually to avoid the bundling. Nextjs packages are already fairly large and as much as we love sentry we can't take the size it imposes for many apps |
I have a feeling this won't work due to how we bundle Sentry in Next.js app but I will happily be proven otherwise! Also I think this will mess up performance measurements and request instrumentation as these usually require Sentry to be initialized asap. |
The 2 issues I see are (305KB total bundle size for @sentry)
The Nodejs integrations definitely seem like a bug |
@carbonrobot Hi, thanks for letting us know about this. The node stuff is something that slipped through. Fix: #7720 |
You're probably right! Haven't tested this setup in a Next.js app.
Yup, this is mostly for simple/non-critical use-cases, where for example only runtime error reporting is necessary (which is indeed what I meant with the "accepting tradeoffs" comment) 🙂 |
@okonet you can follow our tree shaking guide if you aren't already: https://docs.sentry.io/platforms/javascript/guides/nextjs/configuration/tree-shaking/ Note that you will miss out on features though! |
I actually already did this so I was expecting a bigger savings. Right now I see that the replay is about 50% of the bundle but it still leaves me with about 30KB if I disable it completely. If this the minimum bundle size possible? |
@okonet I am not sure where we're at with the minimum size right now but it seems about right. I am sorry that the bundle is quite large. If you have suggestions on how to improve it, let us know. |
Okay thanks for the info. I'll play around with the custom client setup to shrink it a bit further. |
Due to the attitude of the team around bundle size, we are removing sentry from our business. |
Respectable decision |
can we use sentry in party town so it should load lazy ? |
We have a loader script that will load the SDK lazily but comes with a few drawbacks - like for instance no special Next.js performance instrumentation. |
I hate to say it, but my company is dropping Sentry. The bundle size of sentry/nextjs is not reasonable at all. It adds 200 MB to our bundled slug, which is insane. |
@ailadson I can confidently say that there is no way the SDK adds 200 MB to your build unless there is something going horribly wrong. Feel free to share details. |
@lforst Will do! Hopefully this was a mistake on my end, because I reall do like Sentry This is an screenshoot of the build log when I had Sentry. Note line 4419 This is a my package.json when I had Sentry.
Now here is a screenshot of the build log after I removed Sentry. Note line 1589. This is over a 200M difference. All I did was remove Sentry. Here is my current package.json
Ah, for the record, we were using @sentry/nextjs. The logs are from github actions. We are deploying to heroku. I followed the steps given by |
@lforst my guess is that it's related to the @sentry/cli linking that happens (see the first build logs) |
@ailadson oh ok, you're referring to install size (amount of data downloaded on installation) which is something completely different than bundle size (amount of data served to your users). We generally don't optimize for install size (unless it is becoming an issue). In your case 200MB seems a bit much though. We do ship a binary with the Also, please evaluate whether you want to open another issue, since this one is specifically about bundle size and not install size. |
Is there an existing issue for this?
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using? If you use the CDN bundles, please specify the exact bundle (e.g.
bundle.tracing.min.js
) in your SDK setup.@sentry/nextjs
SDK Version
7.46.0
Framework Version
7.46.0
Link to Sentry event
No response
SDK Setup
Steps to Reproduce
Using
@sentry/nextjs": "^7.15.0
, the bundle analyzer reportsUsing
@sentry/nextjs": "^7.46.0
, the bundle analyzer reportsAttempting to follow the tree shaking guide and the following setup produces roughly the same result
Expected Result
The bundle size should not constitute a significant portion of the overall application bundle, or at least be tree shakeable.
Actual Result
The bundle size has grown significantly over past releases
The following related issue does not seem to have a resolution
#2707
The text was updated successfully, but these errors were encountered: