Skip to content

Commit 9c6f0cb

Browse files
committed
add tracesSampler example to gatsby readme
1 parent b98bded commit 9c6f0cb

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

packages/gatsby/README.md

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ To automatically capture the `release` value on Vercel you will need to register
4040

4141
## Sentry Performance
4242

43-
To enable Tracing support, supply either `tracesSampleRate` or `tracesSampler` to the options and make sure you have installed the `@sentry/tracing` package. This will also turn on the `BrowserTracing` integration for automatic instrumentation of the browser.
43+
To enable tracing, supply either `tracesSampleRate` or `tracesSampler` to the options and make sure you have installed the `@sentry/tracing` package. This will also turn on the `BrowserTracing` integration for automatic instrumentation of pageloads and navigations.
4444

4545
```javascript
4646
{
@@ -49,11 +49,31 @@ To enable Tracing support, supply either `tracesSampleRate` or `tracesSampler` t
4949
{
5050
resolve: "@sentry/gatsby",
5151
options: {
52-
dsn: process.env.SENTRY_DSN, // this is the default
52+
dsn: process.env.SENTRY_DSN, // this is the default
53+
54+
// A rate of 1 means all traces will be sent, so it's good for testing.
55+
// In production, you'll likely want to either choose a lower rate or use `tracesSampler` instead (see below).
56+
tracesSampleRate: 1,
5357

54-
// A rate of 1 means all traces will be sent, so it's good for testing.
55-
// In production, you'll likely want to either choose a lower rate or use `tracesSampler` instead.
56-
tracesSampleRate: 1,
58+
// Alternatively:
59+
tracesSampler: sampleContext => {
60+
// Examine provided context data (along with anything in the global namespace) to decide the sample rate
61+
// for this transaction.
62+
// Can return 0 to drop the transaction entirely.
63+
64+
if ("...") {
65+
return 0.5 // These are important - take a big sample
66+
}
67+
else if ("...") {
68+
return 0.01 // These are less important or happen much more frequently - only take 1% of them
69+
}
70+
else if ("...") {
71+
return 0 // These aren't something worth tracking - drop all transactions like this
72+
}
73+
else {
74+
return 0.1 // Default sample rate
75+
}
76+
}
5777
}
5878
},
5979
// ...
@@ -71,7 +91,7 @@ If you want to supply options to the `BrowserTracing` integration, use the `brow
7191
resolve: "@sentry/gatsby",
7292
options: {
7393
dsn: process.env.SENTRY_DSN, // this is the default
74-
tracesSampleRate: 1, // this is just to test, you should lower this in production
94+
tracesSampleRate: 1, // or tracesSampler (see above)
7595
browserTracingOptions: {
7696
// disable creating spans for XHR requests
7797
traceXHR: false,

0 commit comments

Comments
 (0)