Skip to content

Commit de45cf0

Browse files
Add Gatsby docs for sentry config file (#4347)
Adds the docs supporting the Gatsby SDK initialization in a config file, see getsentry/sentry-javascript#4064.
1 parent 59dc6c0 commit de45cf0

File tree

2 files changed

+82
-19
lines changed

2 files changed

+82
-19
lines changed

src/includes/sourcemaps/upload/webpack/javascript.mdx

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ You can do this with the help of the our Webpack plugin, which internally uses o
66
2. Confirm you have `project:write` selected under "Scopes"
77
3. Install `@sentry/webpack-plugin` using `npm`
88
4. Create `.sentryclirc` file with necessary configuration, as documented on this page
9-
5. Update your `webpack.config.js`
9+
5. Update your Webpack config
1010

11-
```javascript
11+
<PlatformSection notSupported={["javascript.gatsby"]}>
12+
13+
```javascript {filename:webpack.config.js}
1214
const SentryPlugin = require("@sentry/webpack-plugin");
1315

1416
module.exports = {
@@ -22,6 +24,28 @@ module.exports = {
2224
};
2325
```
2426

27+
</PlatformSection>
28+
29+
<PlatformSection supported={["javascript.gatsby"]}>
30+
31+
```javascript {filename:gatsby-node.js}
32+
const SentryPlugin = require('@sentry/webpack-plugin');
33+
34+
exports.onCreateWebpackConfig = ({ actions }) => {
35+
actions.setWebpackConfig({
36+
plugins: [
37+
new SentryPlugin({
38+
include: 'public',
39+
ignore: ['app-*', 'polyfill-*', 'framework-*', 'webpack-runtime-*'],
40+
}),
41+
],
42+
});
43+
};
44+
```
45+
46+
</PlatformSection>
47+
48+
2549
Learn more about further configuration of the plugin using our [Sentry Webpack Plugin documentation](https://github.com/getsentry/sentry-webpack-plugin).
2650

2751
Additionally, you’ll need to configure the client to send the `release`:

src/platforms/javascript/guides/gatsby/index.mdx

Lines changed: 56 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,47 +24,86 @@ yarn add @sentry/gatsby
2424

2525
## Connecting the SDK to Sentry
2626

27-
Register the plugin in your Gatsby configuration file (typically `gatsby-config.js`).
27+
You can configure the SDK in one of two ways discussed below: by creating a configuration file, or defining the options along with the Gatsby configuration. If you define options in both places, the SDK will prioritize the `init` in the configuration file and ignore the options in the Gatsby configuration.
28+
29+
### Sentry Configuration File
30+
31+
<Note>
32+
33+
The minimum version supporting the Sentry configuration file is `6.14.0`.
34+
35+
</Note>
36+
37+
Using a Sentry configuration file is the approach we recommend since it supports defining non-serializable options in the `init`. Note that you still need to include the plugin, even if you don't set any options.
2838

2939
```javascript {filename:gatsby-config.js}
3040
module.exports = {
31-
// ...
3241
plugins: [
3342
{
3443
resolve: "@sentry/gatsby",
35-
options: {
36-
dsn: "___PUBLIC_DSN___",
37-
},
3844
},
39-
// ...
40-
],
45+
]
4146
};
4247
```
4348

44-
## Options
49+
Configure your `Sentry.init`:
50+
51+
```javascript {filename:sentry.config.js}
52+
import * as Sentry from '@sentry/gatsby';
53+
54+
Sentry.init({
55+
dsn: "___PUBLIC_DSN___",
56+
sampleRate: 1.0, // Adjust this value in production
57+
beforeSend(event) {
58+
// Modify the event here
59+
if (event.user) {
60+
// Don't send user's email address
61+
delete event.user.email;
62+
}
63+
return event;
64+
},
65+
// ...
66+
});
67+
```
68+
69+
```typescript {filename:sentry.config.ts}
70+
import * as Sentry from '@sentry/gatsby';
71+
72+
Sentry.init({
73+
dsn: "___PUBLIC_DSN___",
74+
sampleRate: 1.0, // Adjust this value in production
75+
beforeSend(event) {
76+
// Modify the event here
77+
if (event.user) {
78+
// Don't send user's email address
79+
delete event.user.email;
80+
}
81+
return event;
82+
},
83+
// ...
84+
});
85+
```
4586

46-
The options field in the plugin configuration is passed directly to `Sentry.init`. Check our configuration docs for a [full list of the available options](configuration/options/).
87+
### Gatsby Plugin Configuration
4788

48-
For example, the configuration below adjusts the `sampleRate` and `maxBreadcrumbs` options.
89+
Another alternative is to use Gatsby's [plugin configuration options](https://www.gatsbyjs.com/docs/how-to/plugins-and-themes/using-a-plugin-in-your-site/#using-plugin-configuration-options). While this keeps the SDK options with the plugin definition, it doesn't support non-serializable options.
4990

5091
```javascript {filename:gatsby-config.js}
5192
module.exports = {
52-
// ...
53-
plugins: [
5493
{
5594
resolve: "@sentry/gatsby",
5695
options: {
5796
dsn: "___PUBLIC_DSN___",
58-
maxBreadcrumbs: 80,
59-
sampleRate: 0.7,
97+
sampleRate: 1.0, // Adjust this value in production
98+
// Cannot set `beforeSend`
6099
},
61100
},
62-
// ...
63-
],
101+
102+
]
64103
};
65104
```
66105

67-
The Gatsby SDK will set certain options automatically based on environmental variables, but these can be overridden by setting custom options in the plugin configuration.
106+
With this approach, the SDK sets some options automatically based on environmental variables, but these can be overridden by setting custom options.
68107

69108
`environment` (string)
70109

0 commit comments

Comments
 (0)