question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[sentry/nextjs] sentry/tracing adds 30kb, can we opt-out ?

See original GitHub issue

Problem Statement

Following the sentry/nextjs recommended approach, it’s difficult to opt-out from tracing in the browser.

The sentry/tracing adds more or less 30kb to the browser final bundle which is a hard blocker in some circumstances.

Here’s a tree map taken with the recommended approach and tested with @sentry/nextjs 6.18.2

image

Solution Brainstorm

I was able to remove the sentry/tracing from the browser, by importing sentry/react rather than sentry/nextjs

// import { init as sentryInit } from '@sentry/nextjs';
import { init as sentryInit } from '@sentry/react';

sentryInit({
  dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
  // tracesSampleRate: 1.0,
});

That reduced the bundle from 103kb to 73kb

image

The setup is https://github.com/belgattitude/nextjs-monorepo-example/pull/1409

Is there any drawbacks or risks to this approach (apart from not sending traces) ?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
belgattitudecommented, May 30, 2022

@AbhiPrasad congrats it works perfect 💯 Thanks a lot

PS: Note for others, simply add this in next.config.js

  webpack: (config, { webpack }) => {
    // https://docs.sentry.io/platforms/javascript/configuration/tree-shaking
    config.plugins.push(
      new webpack.DefinePlugin({
        __SENTRY_DEBUG__: false,
        __SENTRY_TRACING__: false,
      })
    );
1reaction
AbhiPrasadcommented, May 30, 2022

Closing this for now since we’ve released v7: https://github.com/getsentry/sentry-javascript/releases/tag/7.0.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Next.js - Sentry Documentation
On this page, we get you up and running with Sentry's SDK, so that it will automatically report errors and exceptions in your...
Read more >
Shu on Twitter: "If you are using Sentry in Next.js, make sure to ...
We have a utility `isLoggedIn()` to check if the current visitor is logged in by reading `document.cookie`. And it turned out to be...
Read more >
Integrate your Next.js site with Sentry - RudderStack.com
RudderStack's open source JavaScript SDK allows you to integrate RudderStack with your Next.js site to track event data and automatically send it to...
Read more >
Exclude nextjs api url from sentry events - Stack Overflow
I did a small research and it seems that there is an array of urls you can exclude from being tracked. It's called...
Read more >
Sentry Expands Code Observability for Next.js - Business Wire
Next.js is one of the fastest-growing React frameworks because it offers built-in search engine optimization, focuses on web app performance ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found