Gatsby
To use Sentry with your Gatsby application, you will need to use @sentry/gatsby
(Sentry’s Gatsby SDK):
npm install --save @sentry/gatsby
@sentry/gatsby
is a wrapper around the @sentry/react
package, with added functionality related to Gatsby. All methods available in the @sentry/react
package can also be imported from @sentry/gatsby
.
Connecting the SDK to Sentry
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.
Sentry Configuration File
The minimum version supporting the Sentry configuration file is 6.14.0
.
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.
gatsby-config.js
module.exports = {
plugins: [
{
resolve: "@sentry/gatsby",
},
]
};
Configure your Sentry.init
:
sentry.config.js
import * as Sentry from '@sentry/gatsby';
Sentry.init({
dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
sampleRate: 1.0, // Adjust this value in production
beforeSend(event) {
// Modify the event here
if (event.user) {
// Don't send user's email address
delete event.user.email;
}
return event;
},
// ...
});
Gatsby Plugin Configuration
Another alternative is to use Gatsby's plugin configuration options. While this keeps the SDK options with the plugin definition, it doesn't support non-serializable options.
gatsby-config.js
module.exports = {
{
resolve: "@sentry/gatsby",
options: {
dsn: "https://examplePublicKey@o0.ingest.sentry.io/0",
sampleRate: 1.0, // Adjust this value in production
// Cannot set `beforeSend`
},
},
]
};
With this approach, the SDK sets some options automatically based on environmental variables, but these can be overridden by setting custom options.
environment
(string)- Defaults to
process.env.NODE_ENV
ordevelopment
release
(string)- Defaults to certain environment variables based on the platform
- GitHub Actions:
process.env.GITHUB_SHA
- Netlify:
process.env.COMMIT_REF
- Vercel:
process.env.VERCEL_GIT_COMMIT_SHA
- Package:
- npm:@sentry/gatsby
- Version:
- 8.24.0
- Repository:
- https://github.com/getsentry/sentry-javascript