Skip to content

Commit f1af389

Browse files
committed
feat: Add @sentry/gatsby
1 parent fc53353 commit f1af389

File tree

12 files changed

+221
-0
lines changed

12 files changed

+221
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*
2+
!/dist/**/*
3+
!/esm/**/*
4+
*.tsbuildinfo

packages/gatsby/LICENSE

Lines changed: 29 additions & 0 deletions
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

Lines changed: 44 additions & 0 deletions
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 the `VERCEL_GITHUB_COMMIT_SHA` system environment variable 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

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

packages/gatsby/src/gatsby-browser.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
exports.onClientEntry = function(_, pluginParams) {
2+
require.ensure(['@sentry/browser', '@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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
exports.onCreateWebpackConfig = ({ plugins, actions }) => {
2+
actions.setWebpackConfig({
3+
plugins: [
4+
plugins.define({
5+
__SENTRY_RELEASE__:
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+
// Zeit (now known as Vercel)
13+
process.env.ZEIT_GITHUB_COMMIT_SHA,
14+
__SENTRY_DSN__: process.env.SENTRY_DSN,
15+
}),
16+
],
17+
});
18+
};

packages/gatsby/src/index.ts

Whitespace-only changes.

packages/gatsby/tsconfig.build.json

Lines changed: 8 additions & 0 deletions
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

Lines changed: 8 additions & 0 deletions
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

Lines changed: 9 additions & 0 deletions
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

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

0 commit comments

Comments
 (0)