Skip to content

Commit 37bde11

Browse files
committed
fix: Make APM optional in gatsby package
1 parent 913b0ca commit 37bde11

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott
66
- [react] feat: Export `createReduxEnhancer` to log redux actions as breadcrumbs, and attach state as an extra. (#2717)
77
- [tracing] feat: `Add @sentry/tracing` (#2719)
8+
- [gatsby] fix: Make APM optional in gatsby package
89

910
## 5.19.2
1011

packages/gatsby/README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Register the package as a plugin in `gastby-config.js`:
2424
}
2525
```
2626

27-
Options will be passed directly to `Sentry.init`. The `environment` value defaults to `NODE_ENV` (or `development` if not set).
27+
Options will be passed directly to `Sentry.init`. See all available options in [our docs](https://docs.sentry.io/error-reporting/configuration/?platform=javascript). The `environment` value defaults to `NODE_ENV` (or `development` if not set).
2828

2929
## GitHub Actions
3030

@@ -38,6 +38,26 @@ The `release` value is inferred from `COMMIT_REF`.
3838

3939
To automatically capture the `release` value on Vercel you will need to register appropriate [system environment variable](https://vercel.com/docs/v2/build-step#system-environment-variables) (e.g. `VERCEL_GITHUB_COMMIT_SHA`) in your project.
4040

41+
## Sentry Performance
42+
43+
To enable Tracing support, supply the `tracesSampleRate` to the options and make sure you have installed the `@sentry/tracing` package.
44+
45+
```javascript
46+
{
47+
// ...
48+
plugins: [
49+
{
50+
resolve: "@sentry/gatsby",
51+
options: {
52+
dsn: process.env.SENTRY_DSN, // this is the default
53+
tracesSampleRate: 1, // this is just to test, you should lower this in production
54+
}
55+
},
56+
// ...
57+
]
58+
}
59+
```
60+
4161
## Links
4262

4363
- [Official SDK Docs](https://docs.sentry.io/quickstart/)

packages/gatsby/gatsby-browser.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
11
exports.onClientEntry = function(_, pluginParams) {
2-
require.ensure(['@sentry/react', '@sentry/apm'], function(require) {
2+
require.ensure(['@sentry/react'], function(require) {
33
const Sentry = require('@sentry/react');
4-
const TracingIntegration = require('@sentry/apm').Integrations.Tracing;
4+
5+
let TracingIntegration = undefined;
6+
let BrowserTracingIntegration = undefined;
7+
try {
8+
BrowserTracingIntegration = require('@sentry/tracing').Integrations.BrowserTracing;
9+
} catch (_) {}
10+
try {
11+
/** @deprecated Remove when @sentry/apm is no longer used */
12+
TracingIntegration = require('@sentry/apm').Integrations.Tracing;
13+
} catch (_) {}
14+
515
const tracesSampleRate = pluginParams.tracesSampleRate !== undefined ? pluginParams.tracesSampleRate : 0;
616
const integrations = [...(pluginParams.integrations || [])];
17+
718
if (tracesSampleRate) {
8-
integrations.push(new TracingIntegration());
19+
if (BrowserTracingIntegration) {
20+
integrations.push(new BrowserTracingIntegration());
21+
} else if (TracingIntegration) {
22+
integrations.push(new TracingIntegration());
23+
}
924
}
25+
1026
Sentry.init({
1127
environment: process.env.NODE_ENV || 'development',
1228
release: __SENTRY_RELEASE__,
@@ -15,6 +31,7 @@ exports.onClientEntry = function(_, pluginParams) {
1531
tracesSampleRate,
1632
integrations,
1733
});
34+
1835
Sentry.addGlobalEventProcessor(event => {
1936
event.sdk = {
2037
...event.sdk,

0 commit comments

Comments
 (0)