Skip to content

Commit e6536cf

Browse files
authored
Add instructions to tree shake tracing code in JS SDK (#5086)
1 parent 3e2c846 commit e6536cf

File tree

1 file changed

+18
-5
lines changed
  • src/platforms/javascript/common/configuration/tree-shaking

1 file changed

+18
-5
lines changed

src/platforms/javascript/common/configuration/tree-shaking/index.mdx

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,23 @@ description: "Learn how to reduce Sentry bundle size by tree shaking unused code
55
keywords: ["bundle size", "webpack", "rollup", "debug"]
66
---
77

8-
Sentry ships with code that enables you to debug your Sentry configuration, primarily through logging. While this code can be very useful in development environments, it's not typically necessary to include it in your production bundles where it takes up valuable space. The JavaScript SDK includes a special flag in its CommonJS and ESM distributions which can be used to facilitate [tree shaking](https://developer.mozilla.org/en-US/docs/Glossary/Tree_shaking) (removal) of such code during the build process.
8+
The Sentry SDK ships with code that is not strictly required for it to collect your errors. This includes, for example, code to debug your Sentry configuration or code to enable performance monitoring. While debug code can be very useful in development environments, it's not typically necessary to include it in your production bundles where it takes up valuable space. The JavaScript SDK includes a special flags in its CommonJS and ESM distributions, which can be used to facilitate [tree shaking](https://developer.mozilla.org/en-US/docs/Glossary/Tree_shaking) (removal) of such code during the build process.
99

10-
To make debugging code eligible for tree shaking, you must replace the `__SENTRY_DEBUG__` flag in the Sentry SDK with `false`.
10+
## List Of Flags
11+
12+
To make optional code eligible for tree shaking, you can replace various flags in the Sentry SDK with `false`.
13+
14+
`__SENTRY_DEBUG__`
15+
16+
: Replacing this flag with `false` will tree shake all code in the SDK that is related to debug logging.
17+
18+
`__SENTRY_TRACING__`
19+
20+
: Replacing this flag with `false` will tree shake all code in the SDK that is related to automatic instrumentation performance monitoring.
1121

1222
<PlatformSection notSupported={["javascript.nextjs"]}>
1323

14-
## Tree Shaking Debug Code With Webpack
24+
## Tree Shaking Optional Code With Webpack
1525

1626
To tree shake Sentry debug code in your webpack bundles, we recommend using webpack's [DefinePlugin](https://webpack.js.org/plugins/define-plugin/).
1727

@@ -23,6 +33,7 @@ module.exports = {
2333
plugins: [
2434
new webpack.DefinePlugin({
2535
__SENTRY_DEBUG__: false,
36+
__SENTRY_TRACING__: false,
2637
}),
2738
// ... other plugins
2839
],
@@ -33,7 +44,7 @@ module.exports = {
3344

3445
<PlatformSection notSupported={["javascript.nextjs"]}>
3546

36-
## Tree Shaking Debug Code With Rollup
47+
## Tree Shaking Optional Code With Rollup
3748

3849
If you're using `rollup.js`, we recommend using [Rollup's `replace` plugin](https://github.com/rollup/plugins/tree/master/packages/replace).
3950

@@ -47,6 +58,7 @@ export default {
4758
plugins: [
4859
replace({
4960
__SENTRY_DEBUG__: false,
61+
__SENTRY_TRACING__: false,
5062
}),
5163
// ... other plugins (best placed after)
5264
],
@@ -57,7 +69,7 @@ export default {
5769

5870
<PlatformSection supported={["javascript.nextjs"]}>
5971

60-
## Tree Shaking Debug Code With Next.js
72+
## Tree Shaking Optional Code With Next.js
6173

6274
To tree shake Sentry debug code in Next.js projects, you can use webpack's [DefinePlugin](https://webpack.js.org/plugins/define-plugin/) in your Next.js configuration.
6375

@@ -67,6 +79,7 @@ const nextConfig = {
6779
config.plugins.push(
6880
new webpack.DefinePlugin({
6981
__SENTRY_DEBUG__: false,
82+
__SENTRY_TRACING__: false,
7083
})
7184
);
7285

0 commit comments

Comments
 (0)