66
77# Official Sentry SDK for GatsbyJS
88
9- Register the package as a plugin in ` gatsby-config.js ` :
9+ First register the package as a plugin in ` gatsby-config.js ` :
1010
1111``` javascript
1212module .exports = {
@@ -23,66 +23,32 @@ module.exports = {
2323};
2424```
2525
26- Options will be passed directly to ` Sentry.init ` . See all available options in
27- [ our docs] ( https://docs.sentry.io/error-reporting/configuration/?platform=javascript ) . The ` environment ` value defaults
28- to ` NODE_ENV ` (or ` 'development' ` if ` NODE_ENV ` is not set).
29-
30- ## GitHub Actions
31-
32- The ` release ` value is inferred from ` GITHUB_SHA ` .
33-
34- ## Netlify
35-
36- The ` release ` value is inferred from ` COMMIT_REF ` .
37-
38- ## Vercel
39-
40- To automatically capture the ` release ` value on Vercel you will need to register appropriate
41- [ system environment variable] ( https://vercel.com/docs/v2/build-step#system-environment-variables ) (e.g.
42- ` VERCEL_GITHUB_COMMIT_SHA ` ) in your project.
43-
44- ## Sentry Performance
45-
46- To enable tracing, supply either ` tracesSampleRate ` or ` tracesSampler ` to the options. This will turn on the
47- ` BrowserTracing ` integration for automatic instrumentation of pageloads and navigations.
26+ Then configure your ` Sentry.init ` call:
4827
4928``` javascript
50- module .exports = {
51- // ...
52- plugins: [
53- {
54- resolve: ' @sentry/gatsby' ,
55- options: {
56- dsn: process .env .SENTRY_DSN , // this is the default
29+ import * as Sentry from ' @sentry/gatsby' ;
5730
58- // A rate of 1 means all traces will be sent, so it's good for testing.
59- // In production, you'll likely want to either choose a lower rate or use `tracesSampler` instead (see below).
60- tracesSampleRate : 1 ,
31+ Sentry . init ({
32+ dsn : ' __PUBLIC_DSN__ ' ,
33+ integrations : [ Sentry . browserTracingIntegration (), Sentry . replayIntegration ()] ,
6134
62- // Alternatively:
63- tracesSampler : samplingContext => {
64- // Examine provided context data (along with anything in the global namespace) to decide the sample rate
65- // for this transaction.
66- // Can return 0 to drop the transaction entirely.
35+ // Set tracesSampleRate to 1.0 to capture 100%
36+ // of transactions for performance monitoring.
37+ // We recommend adjusting this value in production
38+ tracesSampleRate: 1.0 ,
6739
68- if (' ...' ) {
69- return 0.5 ; // These are important - take a big sample
70- } else if (' ...' ) {
71- return 0.01 ; // These are less important or happen much more frequently - only take 1% of them
72- } else if (' ...' ) {
73- return 0 ; // These aren't something worth tracking - drop all transactions like this
74- } else {
75- return 0.1 ; // Default sample rate
76- }
77- },
78- },
79- },
80- // ...
81- ],
82- };
40+ // Capture Replay for 10% of all sessions,
41+ // plus for 100% of sessions with an error
42+ replaysSessionSampleRate: 0.1 ,
43+ replaysOnErrorSampleRate: 1.0 ,
44+
45+ // Set `tracePropagationTargets` to control for which URLs distributed tracing should be enabled
46+ tracePropagationTargets: [' localhost' , / ^ https:\/\/ yourserver\. io\/ api/ ],
47+ });
8348```
8449
85- If you want to supply options to the ` BrowserTracing ` integration, use the ` browserTracingOptions ` parameter.
50+ The Gatsby SDK also automatically sets up sourcemaps uploading for you. To disable this functionality, set the
51+ ` enableClientWebpackPlugin ` option to be ` false ` .
8652
8753``` javascript
8854module .exports = {
@@ -91,12 +57,7 @@ module.exports = {
9157 {
9258 resolve: ' @sentry/gatsby' ,
9359 options: {
94- dsn: process .env .SENTRY_DSN , // this is the default
95- tracesSampleRate: 1 , // or tracesSampler (see above)
96- browserTracingOptions: {
97- // disable creating spans for XHR requests
98- traceXHR: false ,
99- },
60+ enableClientWebpackPlugin: false ,
10061 },
10162 },
10263 // ...
0 commit comments