Skip to content

Commit

Permalink
feat: Add @sentry/gatsby
Browse files Browse the repository at this point in the history
  • Loading branch information
dcramer committed Jun 8, 2020
1 parent d66e2d7 commit 1ae8b14
Show file tree
Hide file tree
Showing 12 changed files with 229 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -22,6 +22,7 @@
"packages/apm",
"packages/browser",
"packages/core",
"packages/gatsby",
"packages/hub",
"packages/integrations",
"packages/minimal",
Expand Down
4 changes: 4 additions & 0 deletions packages/gatsby/.npmignore
@@ -0,0 +1,4 @@
*
!/dist/**/*
!/esm/**/*
*.tsbuildinfo
29 changes: 29 additions & 0 deletions packages/gatsby/LICENSE
@@ -0,0 +1,29 @@
BSD 3-Clause License

Copyright (c) 2020, Sentry
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 changes: 44 additions & 0 deletions packages/gatsby/README.md
@@ -0,0 +1,44 @@
<p align="center">
<a href="https://sentry.io" target="_blank" align="center">
<img src="https://sentry-brand.storage.googleapis.com/sentry-logo-black.png" width="280">
</a>
<br />
</p>

# Official Sentry SDK for GatsbyJS

Register the package as a plugin in `gastby-config.js`:

```javascript
{
// ...
plugins: [
{
resolve: "@sentry/gatsby",
options: {
dsn: process.env.SENTRY_DSN, // this is the default
}
},
// ...
]
}
```

Options will be passed directly to `Sentry.init`. The `environment` value defaults to `NODE_ENV` (or `development` if not set).

## GitHub Actions

The `release` value is inferred from `GITHUB_SHA`.

## Netlify

The `release` value is inferred from `COMMIT_REF`.

## Vercel

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.

## Links

- [Official SDK Docs](https://docs.sentry.io/quickstart/)
- [TypeDoc](http://getsentry.github.io/sentry-javascript/)
78 changes: 78 additions & 0 deletions packages/gatsby/package.json
@@ -0,0 +1,78 @@
{
"name": "@sentry/gatsby",
"version": "5.16.1",
"description": "Offical Sentry SDK for Gatsby.js",
"repository": "git://github.com/getsentry/sentry-javascript.git",
"homepage": "https://github.com/getsentry/sentry-javascript/tree/master/packages/gatsby",
"author": "Sentry",
"license": "BSD-3-Clause",
"keywords": ["gatsby", "gatsby-plugin"],
"engines": {
"node": ">=6"
},
"main": "dist/index.js",
"module": "esm/index.js",
"types": "dist/index.d.ts",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@sentry/browser": "5.16.1",
"@sentry/types": "5.16.1"
},
"peerDependencies": {
"gatsby": "*"
},
"devDependencies": {
"jest": "^24.7.1",
"npm-run-all": "^4.1.2",
"prettier": "^1.17.0",
"prettier-check": "^2.0.0",
"rimraf": "^2.6.3",
"tslint": "^5.16.0",
"typescript": "^3.5.1"
},
"scripts": {
"build": "run-p build:es5 build:esm",
"build:es5": "tsc -p tsconfig.build.json",
"build:esm": "tsc -p tsconfig.esm.json",
"build:watch": "run-p build:watch:es5 build:watch:esm",
"build:watch:es5": "tsc -p tsconfig.build.json -w --preserveWatchOutput",
"build:watch:esm": "tsc -p tsconfig.esm.json -w --preserveWatchOutput",
"clean": "rimraf dist coverage build esm",
"link:yarn": "yarn link",
"lint": "run-s lint:prettier lint:tslint",
"lint:prettier": "prettier-check \"{src,test}/**/*.{ts,tsx}\"",
"lint:tslint": "tslint -t stylish -p .",
"lint:tslint:json": "tslint --format json -p . | tee lint-results.json",
"fix": "run-s fix:tslint fix:prettier",
"fix:prettier": "prettier --write \"{src,test}/**/*.{ts,tsx}\"",
"fix:tslint": "tslint --fix -t stylish -p .",
"test": "jest",
"test:watch": "jest --watch"
},
"jest": {
"collectCoverage": true,
"transform": {
"^.+\\.ts$": "ts-jest",
"^.+\\.tsx$": "ts-jest"
},
"moduleFileExtensions": [
"js",
"ts",
"tsx"
],
"testEnvironment": "jsdom",
"testMatch": [
"**/*.test.ts",
"**/*.test.tsx"
],
"globals": {
"ts-jest": {
"tsConfig": "./tsconfig.json",
"diagnostics": false
}
}
},
"sideEffects": false
}
20 changes: 20 additions & 0 deletions packages/gatsby/src/gatsby-browser.js
@@ -0,0 +1,20 @@
exports.onClientEntry = function(_, pluginParams) {
require.ensure(['@sentry/browser', '@sentry/apm'], function(require) {
const Sentry = require('@sentry/browser');
const TracingIntegration = require('@sentry/apm').Integrations.Tracing;
const tracesSampleRate = pluginParams.tracesSampleRate !== undefined ? pluginParams.tracesSampleRate : 0;
const integrations = [...(pluginParams.integrations || [])];
if (tracesSampleRate) {
integrations.push(new TracingIntegration());
}
Sentry.init({
environment: process.env.NODE_ENV || 'development',
release: __SENTRY_RELEASE__,
dsn: __SENTRY_DSN__,
...pluginParams,
tracesSampleRate,
integrations,
});
window.Sentry = Sentry;
});
};
24 changes: 24 additions & 0 deletions packages/gatsby/src/gatsby-node.js
@@ -0,0 +1,24 @@
exports.onCreateWebpackConfig = ({ plugins, actions }) => {
actions.setWebpackConfig({
plugins: [
plugins.define({
__SENTRY_RELEASE__: JSON.stringify(
// GitHub Actions - https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables
process.env.GITHUB_SHA ||
// Netlify - https://docs.netlify.com/configure-builds/environment-variables/#build-metadata
process.env.COMMIT_REF ||
// Vercel - https://vercel.com/docs/v2/build-step#system-environment-variables
process.env.VERCEL_GITHUB_COMMIT_SHA ||
process.env.VERCEL_GITLAB_COMMIT_SHA ||
process.env.VERCEL_BITBUCKET_COMMIT_SHA ||
// Zeit (now known as Vercel)
process.env.ZEIT_GITHUB_COMMIT_SHA ||
process.env.ZEIT_GITLAB_COMMIT_SHA ||
process.env.ZEIT_BITBUCKET_COMMIT_SHA ||
'',
),
__SENTRY_DSN__: JSON.stringify(process.env.SENTRY_DSN || ''),
}),
],
});
};
1 change: 1 addition & 0 deletions packages/gatsby/src/index.ts
@@ -0,0 +1 @@
export * from '@sentry/react';
8 changes: 8 additions & 0 deletions packages/gatsby/tsconfig.build.json
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"baseUrl": ".",
"outDir": "dist"
},
"include": ["src/**/*"]
}
8 changes: 8 additions & 0 deletions packages/gatsby/tsconfig.esm.json
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.esm.json",
"compilerOptions": {
"baseUrl": ".",
"outDir": "esm",
},
"include": ["src/**/*"]
}
9 changes: 9 additions & 0 deletions packages/gatsby/tsconfig.json
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.build.json",
"include": ["src/**/*.ts", "test/**/*.ts"],
"exclude": ["dist"],
"compilerOptions": {
"rootDir": ".",
"types": ["node", "jest"]
}
}
3 changes: 3 additions & 0 deletions packages/gatsby/tslint.json
@@ -0,0 +1,3 @@
{
"extends": "@sentry/typescript/tslint"
}

0 comments on commit 1ae8b14

Please sign in to comment.