Skip to content

Commit e8093c2

Browse files
authored
feat: Add @sentry/gatsby (getsentry#2652)
1 parent e8a37d2 commit e8093c2

14 files changed

+248
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- [react] feat: Add useProfiler hook (#2659)
99
- [core] feat: Export `makeMain` (#2665)
1010
- [core] fix: Call `bindClient` when creating new `Hub` to make integrations work automatically (#2665)
11+
- [gatsby] feat: Add @sentry/gatsby package (#2652)
1112

1213
## 5.17.0
1314

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"packages/apm",
2323
"packages/browser",
2424
"packages/core",
25+
"packages/gatsby",
2526
"packages/hub",
2627
"packages/integrations",
2728
"packages/minimal",

packages/gatsby/.npmignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*
2+
!/dist/**/*
3+
!/esm/**/*
4+
*.tsbuildinfo

packages/gatsby/LICENSE

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2020, Sentry
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
* Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
* Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
* Neither the name of the copyright holder nor the names of its
17+
contributors may be used to endorse or promote products derived from
18+
this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

packages/gatsby/README.md

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<p align="center">
2+
<a href="https://sentry.io" target="_blank" align="center">
3+
<img src="https://sentry-brand.storage.googleapis.com/sentry-logo-black.png" width="280">
4+
</a>
5+
<br />
6+
</p>
7+
8+
# Official Sentry SDK for GatsbyJS
9+
10+
Register the package as a plugin in `gastby-config.js`:
11+
12+
```javascript
13+
{
14+
// ...
15+
plugins: [
16+
{
17+
resolve: "@sentry/gatsby",
18+
options: {
19+
dsn: process.env.SENTRY_DSN, // this is the default
20+
}
21+
},
22+
// ...
23+
]
24+
}
25+
```
26+
27+
Options will be passed directly to `Sentry.init`. The `environment` value defaults to `NODE_ENV` (or `development` if not set).
28+
29+
## GitHub Actions
30+
31+
The `release` value is inferred from `GITHUB_SHA`.
32+
33+
## Netlify
34+
35+
The `release` value is inferred from `COMMIT_REF`.
36+
37+
## Vercel
38+
39+
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.
40+
41+
## Links
42+
43+
- [Official SDK Docs](https://docs.sentry.io/quickstart/)
44+
- [TypeDoc](http://getsentry.github.io/sentry-javascript/)

packages/gatsby/package.json

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
"name": "@sentry/gatsby",
3+
"version": "5.17.0",
4+
"description": "Offical Sentry SDK for Gatsby.js",
5+
"repository": "git://github.com/getsentry/sentry-javascript.git",
6+
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/gatsby",
7+
"author": "Sentry",
8+
"license": "BSD-3-Clause",
9+
"keywords": ["gatsby", "gatsby-plugin"],
10+
"engines": {
11+
"node": ">=6"
12+
},
13+
"main": "dist/index.js",
14+
"module": "esm/index.js",
15+
"types": "dist/index.d.ts",
16+
"publishConfig": {
17+
"access": "public"
18+
},
19+
"dependencies": {
20+
"@sentry/react": "5.17.0",
21+
"@sentry/types": "5.17.0"
22+
},
23+
"peerDependencies": {
24+
"gatsby": "*"
25+
},
26+
"devDependencies": {
27+
"jest": "^24.7.1",
28+
"npm-run-all": "^4.1.2",
29+
"prettier": "^1.17.0",
30+
"prettier-check": "^2.0.0",
31+
"rimraf": "^2.6.3",
32+
"tslint": "^5.16.0",
33+
"typescript": "^3.5.1"
34+
},
35+
"scripts": {
36+
"build": "run-p build:es5 build:esm",
37+
"build:es5": "tsc -p tsconfig.build.json",
38+
"build:esm": "tsc -p tsconfig.esm.json",
39+
"build:watch": "run-p build:watch:es5 build:watch:esm",
40+
"build:watch:es5": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
41+
"build:watch:esm": "tsc -p tsconfig.esm.json -w --preserveWatchOutput",
42+
"clean": "rimraf dist coverage build esm",
43+
"link:yarn": "yarn link",
44+
"lint": "run-s lint:prettier lint:tslint",
45+
"lint:prettier": "prettier-check \"{src,test}/**/*.{ts,tsx}\"",
46+
"lint:tslint": "tslint -t stylish -p .",
47+
"lint:tslint:json": "tslint --format json -p . | tee lint-results.json",
48+
"fix": "run-s fix:tslint fix:prettier",
49+
"fix:prettier": "prettier --write \"{src,test}/**/*.{ts,tsx}\"",
50+
"fix:tslint": "tslint --fix -t stylish -p .",
51+
"test": "jest",
52+
"test:watch": "jest --watch"
53+
},
54+
"jest": {
55+
"collectCoverage": true,
56+
"transform": {
57+
"^.+\\.ts$": "ts-jest",
58+
"^.+\\.tsx$": "ts-jest"
59+
},
60+
"moduleFileExtensions": [
61+
"js",
62+
"ts",
63+
"tsx"
64+
],
65+
"testEnvironment": "jsdom",
66+
"testMatch": [
67+
"**/*.test.ts",
68+
"**/*.test.tsx"
69+
],
70+
"globals": {
71+
"ts-jest": {
72+
"tsConfig": "./tsconfig.json",
73+
"diagnostics": false
74+
}
75+
}
76+
},
77+
"sideEffects": false
78+
}

packages/gatsby/src/gatsby-browser.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
exports.onClientEntry = function(_, pluginParams) {
2+
require.ensure(['@sentry/react', '@sentry/apm'], function(require) {
3+
const Sentry = require('@sentry/browser');
4+
const TracingIntegration = require('@sentry/apm').Integrations.Tracing;
5+
const tracesSampleRate = pluginParams.tracesSampleRate !== undefined ? pluginParams.tracesSampleRate : 0;
6+
const integrations = [...(pluginParams.integrations || [])];
7+
if (tracesSampleRate) {
8+
integrations.push(new TracingIntegration());
9+
}
10+
Sentry.init({
11+
environment: process.env.NODE_ENV || 'development',
12+
release: __SENTRY_RELEASE__,
13+
dsn: __SENTRY_DSN__,
14+
...pluginParams,
15+
tracesSampleRate,
16+
integrations,
17+
});
18+
window.Sentry = Sentry;
19+
});
20+
};

packages/gatsby/src/gatsby-node.js

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
exports.onCreateWebpackConfig = ({ plugins, actions }) => {
2+
actions.setWebpackConfig({
3+
plugins: [
4+
plugins.define({
5+
__SENTRY_RELEASE__: JSON.stringify(
6+
// GitHub Actions - https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables
7+
process.env.GITHUB_SHA ||
8+
// Netlify - https://docs.netlify.com/configure-builds/environment-variables/#build-metadata
9+
process.env.COMMIT_REF ||
10+
// Vercel - https://vercel.com/docs/v2/build-step#system-environment-variables
11+
process.env.VERCEL_GITHUB_COMMIT_SHA ||
12+
process.env.VERCEL_GITLAB_COMMIT_SHA ||
13+
process.env.VERCEL_BITBUCKET_COMMIT_SHA ||
14+
// Zeit (now known as Vercel)
15+
process.env.ZEIT_GITHUB_COMMIT_SHA ||
16+
process.env.ZEIT_GITLAB_COMMIT_SHA ||
17+
process.env.ZEIT_BITBUCKET_COMMIT_SHA ||
18+
'',
19+
),
20+
__SENTRY_DSN__: JSON.stringify(process.env.SENTRY_DSN || ''),
21+
}),
22+
],
23+
});
24+
};

packages/gatsby/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from '@sentry/react';

packages/gatsby/test/index.test.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import * as GatsbyIntegration from '../src';
2+
3+
describe('package', () => {
4+
it('exports init', () => {
5+
expect(GatsbyIntegration.init).toBeDefined();
6+
});
7+
8+
it('exports ErrorBoundary', () => {
9+
expect(GatsbyIntegration.ErrorBoundary).toBeDefined();
10+
expect(GatsbyIntegration.withErrorBoundary).toBeDefined();
11+
});
12+
13+
it('exports Profiler', () => {
14+
expect(GatsbyIntegration.Profiler).toBeDefined();
15+
expect(GatsbyIntegration.withProfiler).toBeDefined();
16+
expect(GatsbyIntegration.useProfiler).toBeDefined();
17+
});
18+
});

packages/gatsby/tsconfig.build.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../../tsconfig.json",
3+
"compilerOptions": {
4+
"baseUrl": ".",
5+
"outDir": "dist"
6+
},
7+
"include": ["src/**/*"]
8+
}

packages/gatsby/tsconfig.esm.json

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "../../tsconfig.esm.json",
3+
"compilerOptions": {
4+
"baseUrl": ".",
5+
"outDir": "esm",
6+
},
7+
"include": ["src/**/*"]
8+
}

packages/gatsby/tsconfig.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "./tsconfig.build.json",
3+
"include": ["src/**/*.ts", "test/**/*.ts"],
4+
"exclude": ["dist"],
5+
"compilerOptions": {
6+
"rootDir": ".",
7+
"types": ["node", "jest"]
8+
}
9+
}

packages/gatsby/tslint.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "@sentry/typescript/tslint"
3+
}

0 commit comments

Comments
 (0)