-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: Add @sentry/gatsby #2652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add @sentry/gatsby #2652
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
* | ||
!/dist/**/* | ||
!/esm/**/* | ||
*.tsbuildinfo |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
{ | ||
"name": "@sentry/gatsby", | ||
"version": "5.17.0", | ||
"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/react": "5.17.0", | ||
"@sentry/types": "5.17.0" | ||
}, | ||
"peerDependencies": { | ||
"gatsby": "*" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This config will work for all gatsby versions? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dont know what versions itll work for, and I don't really want to dig through Gatsby history to figure out when specific APIs were created/etc. |
||
}, | ||
"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", | ||
dcramer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"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 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
exports.onClientEntry = function(_, pluginParams) { | ||
require.ensure(['@sentry/react', '@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__, | ||
dcramer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
dsn: __SENTRY_DSN__, | ||
...pluginParams, | ||
tracesSampleRate, | ||
integrations, | ||
}); | ||
window.Sentry = Sentry; | ||
}); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
exports.onCreateWebpackConfig = ({ plugins, actions }) => { | ||
actions.setWebpackConfig({ | ||
plugins: [ | ||
plugins.define({ | ||
__SENTRY_RELEASE__: JSON.stringify( | ||
dcramer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// 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 || | ||
dcramer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 || | ||
'', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there no way for us to make this a user set option without relying on environmental variables? Can we provide some kind of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is still able to be overwritten from pluginOptions, but we should not make a user set anything unless they absolutely have to. frictionless has always been the goal. |
||
), | ||
__SENTRY_DSN__: JSON.stringify(process.env.SENTRY_DSN || ''), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dcramer I hope this doesn't pick the wrong DSN with a Vercel project. They have some hack in the next JS Sentry example because I presume they have an internal DSN for Sentry that conflicts: https://github.com/vercel/next.js/blob/canary/examples/with-sentry-simple/next.config.js#L8 |
||
}), | ||
], | ||
}); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from '@sentry/react'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import * as GatsbyIntegration from '../src'; | ||
|
||
describe('package', () => { | ||
it('exports init', () => { | ||
expect(GatsbyIntegration.init).toBeDefined(); | ||
}); | ||
|
||
it('exports ErrorBoundary', () => { | ||
expect(GatsbyIntegration.ErrorBoundary).toBeDefined(); | ||
expect(GatsbyIntegration.withErrorBoundary).toBeDefined(); | ||
}); | ||
|
||
it('exports Profiler', () => { | ||
expect(GatsbyIntegration.Profiler).toBeDefined(); | ||
expect(GatsbyIntegration.withProfiler).toBeDefined(); | ||
expect(GatsbyIntegration.useProfiler).toBeDefined(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"outDir": "dist" | ||
}, | ||
"include": ["src/**/*"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "../../tsconfig.esm.json", | ||
"compilerOptions": { | ||
"baseUrl": ".", | ||
"outDir": "esm", | ||
}, | ||
"include": ["src/**/*"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "./tsconfig.build.json", | ||
"include": ["src/**/*.ts", "test/**/*.ts"], | ||
"exclude": ["dist"], | ||
"compilerOptions": { | ||
"rootDir": ".", | ||
"types": ["node", "jest"] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "@sentry/typescript/tslint" | ||
} |
Uh oh!
There was an error while loading. Please reload this page.