Merge pull request #999 from sharetribe/update-sentry

Update sentry
This commit is contained in:
Jenni Nurmi 2019-01-17 12:40:30 +02:00 committed by GitHub
commit 5ffe9a45c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 160 additions and 72 deletions

View file

@ -27,8 +27,7 @@ REACT_APP_ENV=production
# REACT_APP_SHARETRIBE_USING_SSL=true
# SERVER_SHARETRIBE_TRUST_PROXY=true
# REACT_APP_PUBLIC_SENTRY_DSN=change-me
# SERVER_SENTRY_DSN=change-me
# REACT_APP_SENTRY_DSN=change-me
# REACT_APP_CSP=report
# BASIC_AUTH_USERNAME=sharetribe
# BASIC_AUTH_PASSWORD=secret

View file

@ -14,6 +14,9 @@ way to update this template, but currently, we follow a pattern:
## Upcoming version 2019-XX-XX
- [change] Change from Raven to Sentry SDKs for browser and Node.js to version 4.5.1. With the new
SDKs only one DSN needs to be configured so update also environment variables and documentation
related to Sentry. [#999](https://github.com/sharetribe/flex-template-web/pull/999)
- [fix] Use environment variable `REACT_APP_AVAILABILITY_ENABLED` to enable or disable availability
calendar. In the config.js file variable fetchAvailableTimeSlots is now renamed to more general
enableAvailability because it affects both fetching availability data and enabling the

View file

@ -16,8 +16,7 @@ them have defaults that work for development environment. For production deploys
| REACT_APP_ENV | A more fine grained env definition than NODE_ENV. Is used for example to differentiate envs in logging. |
| REACT_APP_SHARETRIBE_USING_SSL | Redirect HTTP to HTTPS? |
| SERVER_SHARETRIBE_TRUST_PROXY | Set when running the app behind a reverse proxy, e.g. in Heroku. |
| REACT_APP_PUBLIC_SENTRY_DSN | See: [Error logging with Sentry](./sentry.md) |
| SERVER_SENTRY_DSN | See: [Error logging with Sentry](./sentry.md) |
| REACT_APP_SENTRY_DSN | See: [Error logging with Sentry](./sentry.md) |
| REACT_APP_CSP | See: [Content Security Policy (CSP)](./content-security-policy.md) |
| BASIC_AUTH_USERNAME | Set to enable HTTP Basic Auth |
| BASIC_AUTH_PASSWORD | Set to enable HTTP Basic Auth |

View file

@ -7,17 +7,16 @@ be used but the Sentry client comes already strapped into application.
## Setting up Sentry keys
To enable the Sentry error logging a DSN, _Data Source Name_ has to be provided as an environment
variable. Browser and Node environments both require their own keys. The key names are as follows:
variable. Browser and Node environments use both the same key:
- **SERVER_SENTRY_DSN** - the private Sentry DSN, used on the server side
- **REACT_APP_PUBLIC_SENTRY_DSN** - the public Sentry DSN, used in the browser
- **REACT_APP_SENTRY_DSN**
The DSN keys can be aquired from the Sentry project settings. To test them in your local environment
they can be passed for example to the `yarn run dev-server` command:
The DSN key can be aquired from the Sentry project settings. To test it in your local environment it
can be passed for example to the `yarn run dev-server` command:
REACT_APP_PUBLIC_SENTRY_DSN='<public-sentry-dsn>' SERVER_SENTRY_DSN='<private-sentry-dsn>' yarn run dev-server
REACT_APP_SENTRY_DSN='<sentry-dsn>' yarn run dev-server
If the Sentry DSN keys are not provided the template app will log errors to the console. The logging
If the Sentry DSN key is not provided the template app will log errors to the console. The logging
and Sentry setup is implemented in [util/log.js](../src/util/log.js) and
[server/log.js](../server/log.js) so refer to those files to change the external logging service or
the logging logic in general.

View file

@ -5,6 +5,8 @@
"license": "Apache-2.0",
"dependencies": {
"@mapbox/polyline": "^1.0.0",
"@sentry/browser": "4.5.1",
"@sentry/node": "4.5.1",
"array-includes": "^3.0.3",
"array.prototype.find": "^2.0.4",
"autosize": "^4.0.0",
@ -32,8 +34,6 @@
"prop-types": "^15.6.2",
"query-string": "^5.1.1",
"raf": "3.4.0",
"raven": "^2.6.4",
"raven-js": "^3.27.0",
"react": "^16.6.3",
"react-dates": "^18.2.2",
"react-dom": "^16.6.3",

View file

@ -4,10 +4,10 @@
* or just plain printing errors to the log.
*/
const Raven = require('raven');
const Sentry = require('@sentry/node');
const ENV = process.env.REACT_APP_ENV;
const SENTRY_DSN = process.env.SERVER_SENTRY_DSN;
const SENTRY_DSN = process.env.REACT_APP_SENTRY_DSN;
/**
* Set up error loggin. If a Sentry DSN is defined
@ -19,12 +19,7 @@ exports.setup = () => {
// exceptions from starting the server etc. but does not catch the
// ones thrown from Express.js middleware functions. For those
// an error handler has to be added to the Express app.
Raven.config(SENTRY_DSN, {
environment: ENV,
autoBreadcrumbs: {
http: true,
},
}).install();
Sentry.init({ dsn: SENTRY_DSN, environment: ENV });
}
};
@ -34,7 +29,7 @@ exports.setup = () => {
*/
exports.requestHandler = () => {
if (SENTRY_DSN) {
return Raven.requestHandler();
return Sentry.Handlers.requestHandler();
} else {
return (req, res, next) => {
next();
@ -48,7 +43,7 @@ exports.requestHandler = () => {
*/
exports.errorHandler = () => {
if (SENTRY_DSN) {
return Raven.errorHandler();
return Sentry.Handlers.errorHandler();
} else {
return (err, req, res, next) => {
next(err);
@ -67,7 +62,15 @@ exports.errorHandler = () => {
*/
exports.error = (e, code, data) => {
if (SENTRY_DSN) {
Raven.captureException(e, { tags: { code }, extra: data });
const extra = { ...data, apiErrorData: responseApiErrorInfo(e) };
Sentry.withScope(scope => {
scope.setTag('code', code);
Object.keys(extra).forEach(key => {
scope.setExtra(key, extra[key]);
});
Sentry.captureException(e);
});
} else {
console.error(e);
console.error(code);

View file

@ -62,7 +62,7 @@ const currency = process.env.REACT_APP_SHARETRIBE_MARKETPLACE_CURRENCY;
const listingMinimumPriceSubUnits = 0;
// Sentry DSN (Data Source Name), a client key for authenticating calls to Sentry
const sentryDsn = process.env.REACT_APP_PUBLIC_SENTRY_DSN;
const sentryDsn = process.env.REACT_APP_SENTRY_DSN;
// If webapp is using SSL (i.e. it's behind 'https' protocol)
const usingSSL = process.env.REACT_APP_SHARETRIBE_USING_SSL === 'true';

View file

@ -6,7 +6,7 @@
*
*/
import Raven from 'raven-js';
import * as Sentry from '@sentry/browser';
import config from '../config';
import { responseApiErrorInfo } from './errors';
@ -18,7 +18,10 @@ export const setup = () => {
if (config.sentryDsn) {
// Configures the Sentry client. Adds a handler for
// any uncaught exception.
Raven.config(config.sentryDsn, { environment: config.env }).install();
Sentry.init({
dsn: config.sentryDsn,
environment: config.env,
});
}
};
@ -29,18 +32,19 @@ export const setup = () => {
* @param {String} userId ID of current user
*/
export const setUserId = userId => {
if (Raven.isSetup()) {
Raven.setUserContext({ id: userId });
}
Sentry.configureScope(scope => {
scope.setUser({ id: userId });
});
};
/**
* Clears the user ID.
*/
export const clearUserId = () => {
if (Raven.isSetup()) {
Raven.setUserContext();
}
Sentry.configureScope(scope => {
scope.remove_user();
});
};
/**
@ -53,9 +57,16 @@ export const clearUserId = () => {
* @param {Object} data Additional data to be sent to Sentry
*/
export const error = (e, code, data) => {
if (Raven.isSetup()) {
if (config.sentryDsn) {
const extra = { ...data, apiErrorData: responseApiErrorInfo(e) };
Raven.captureException(e, { tags: { code }, extra });
Sentry.withScope(scope => {
scope.setTag('code', code);
Object.keys(extra).forEach(key => {
scope.setExtra(key, extra[key]);
});
Sentry.captureException(e);
});
} else {
console.error(e); // eslint-disable-line
console.error('Error code:', code, 'data:', data);

148
yarn.lock
View file

@ -17,10 +17,84 @@
version "1.0.0"
resolved "https://registry.yarnpkg.com/@mapbox/polyline/-/polyline-1.0.0.tgz#b6f1c3cf61f8dddcf9ac6dce0b2e50e5f4e965bc"
"@sentry/browser@4.5.1":
version "4.5.1"
resolved "https://registry.yarnpkg.com/@sentry/browser/-/browser-4.5.1.tgz#a095f9636c3fd88f97086b6888c6f32f445c8fe8"
integrity sha512-sI/EGbKpHiBYcgVoJl3oxdCc8OpIL3SKjdSpgk7njBFdPJZbkbvi+N/iaJdm70dTeZAgKEmm8jiwNf845gzybQ==
dependencies:
"@sentry/core" "4.5.1"
"@sentry/types" "4.5.0"
"@sentry/utils" "4.5.1"
tslib "^1.9.3"
"@sentry/core@4.5.1":
version "4.5.1"
resolved "https://registry.yarnpkg.com/@sentry/core/-/core-4.5.1.tgz#bfc98a276974a670e25ca5873ba7ac078bf5410d"
integrity sha512-ml4Z1PZ7GjsJip5vYkRMkqCLpK5u3jxUYtECOWVsYHIHgVlvERV+HWCdyH0PoiEwr97ZU+4mjnc9Av8P7a18Mw==
dependencies:
"@sentry/hub" "4.5.1"
"@sentry/minimal" "4.5.1"
"@sentry/types" "4.5.0"
"@sentry/utils" "4.5.1"
tslib "^1.9.3"
"@sentry/hub@4.5.1":
version "4.5.1"
resolved "https://registry.yarnpkg.com/@sentry/hub/-/hub-4.5.1.tgz#979c0a826a9abfa567516b0da0e6f4017130def9"
integrity sha512-msftpMDSvWaENdYMHX8GPBQ5jTLxClWCprtAlE0AFZ90WHFrwvA0bHpGLzseFDjYwGUKoG2psxejoSstoBy53A==
dependencies:
"@sentry/types" "4.5.0"
"@sentry/utils" "4.5.1"
tslib "^1.9.3"
"@sentry/minimal@4.5.1":
version "4.5.1"
resolved "https://registry.yarnpkg.com/@sentry/minimal/-/minimal-4.5.1.tgz#a6128aab2a3967d8eb99afb3029057e1b4d9aaa5"
integrity sha512-/PaBrzuGkL6c137KRz5iIpmIfCj1FY/rYOffBAYrZADmmZyVrHfP2cNreneze+9OYy5dCFylBFEQpNOCMDdARw==
dependencies:
"@sentry/hub" "4.5.1"
"@sentry/types" "4.5.0"
tslib "^1.9.3"
"@sentry/node@4.5.1":
version "4.5.1"
resolved "https://registry.yarnpkg.com/@sentry/node/-/node-4.5.1.tgz#e8218b952695548d276274d2b6cc4f9d0676e063"
integrity sha512-qClDjSvRAAKnXkww5uiXQ+TySHjdmjr3c/scp4QxvjR9tNhYhdfimwdr4ZM6K9jhvK35vKVruuTVFzzSDukWHw==
dependencies:
"@sentry/core" "4.5.1"
"@sentry/hub" "4.5.1"
"@sentry/types" "4.5.0"
"@sentry/utils" "4.5.1"
"@types/stack-trace" "0.0.29"
cookie "0.3.1"
https-proxy-agent "2.2.1"
lru_map "0.3.3"
lsmod "1.0.0"
stack-trace "0.0.10"
tslib "^1.9.3"
"@sentry/types@4.5.0":
version "4.5.0"
resolved "https://registry.yarnpkg.com/@sentry/types/-/types-4.5.0.tgz#59e2a27d48b01b44e8959aa5c8a30514fe1086a9"
integrity sha512-IstPjFoebQGrQWdM732D/+S0BTovmDgezyplk4kLEb87+/B+YK0hlhziUa7B2byTFJGgQQKXy7h2sKZBrA3GUA==
"@sentry/utils@4.5.1":
version "4.5.1"
resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-4.5.1.tgz#23f8a8fbe84e06d2546d3f1a72e30b34cbc2a3d8"
integrity sha512-ihzvgKBuvHBjKtbjz3EtuTW0OAJH5nw1L3tNVOCi+fbEdp10DiyL0i3hQKdE87CLoNEAt/SPRmTrG1cP2dNa7Q==
dependencies:
"@sentry/types" "4.5.0"
tslib "^1.9.3"
"@types/node@*":
version "9.6.0"
resolved "https://registry.yarnpkg.com/@types/node/-/node-9.6.0.tgz#d3480ee666df9784b1001a1872a2f6ccefb6c2d7"
"@types/stack-trace@0.0.29":
version "0.0.29"
resolved "https://registry.yarnpkg.com/@types/stack-trace/-/stack-trace-0.0.29.tgz#eb7a7c60098edb35630ed900742a5ecb20cfcb4d"
integrity sha512-TgfOX+mGY/NyNxJLIbDWrO9DjGoVSW9+aB8H2yy1fy32jsvxijhmyJI9fDFgvz3YP4lvJaq9DzdR/M1bOgVc9g==
abab@^1.0.3:
version "1.0.4"
resolved "https://registry.yarnpkg.com/abab/-/abab-1.0.4.tgz#5faad9c2c07f60dd76770f71cf025b62a63cfd4e"
@ -77,6 +151,13 @@ address@1.0.3, address@^1.0.1:
version "1.0.3"
resolved "https://registry.yarnpkg.com/address/-/address-1.0.3.tgz#b5f50631f8d6cec8bd20c963963afb55e06cbce9"
agent-base@^4.1.0:
version "4.2.1"
resolved "https://registry.yarnpkg.com/agent-base/-/agent-base-4.2.1.tgz#d89e5999f797875674c07d87f260fc41e83e8ca9"
integrity sha512-JVwXMr9nHYTUXsBFKUqhJwvlcYU/blreOEUkhNR2eXZIvwd+c+o5V4MgDPKWnMS/56awN3TRzIP+KoPn+roQtg==
dependencies:
es6-promisify "^5.0.0"
airbnb-prop-types@^2.10.0:
version "2.11.0"
resolved "https://registry.yarnpkg.com/airbnb-prop-types/-/airbnb-prop-types-2.11.0.tgz#2f4169a17ef86e227924d61f2b77defead1aa5be"
@ -1529,10 +1610,6 @@ chardet@^0.7.0:
resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.7.0.tgz#90094849f0937f2eedc2425d0d28a9e5f0cbad9e"
integrity sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==
charenc@~0.0.1:
version "0.0.2"
resolved "https://registry.yarnpkg.com/charenc/-/charenc-0.0.2.tgz#c0a1d2f3a7092e03774bfa83f14c0fc5790a8667"
cheerio@^1.0.0-rc.2:
version "1.0.0-rc.2"
resolved "https://registry.yarnpkg.com/cheerio/-/cheerio-1.0.0-rc.2.tgz#4b9f53a81b27e4d5dac31c0ffd0cfa03cc6830db"
@ -1959,10 +2036,6 @@ cross-spawn@5.1.0, cross-spawn@^5.0.1, cross-spawn@^5.1.0:
shebang-command "^1.2.0"
which "^1.2.9"
crypt@~0.0.1:
version "0.0.2"
resolved "https://registry.yarnpkg.com/crypt/-/crypt-0.0.2.tgz#88d7ff7ec0dfb86f713dc87bbb42d044d3e6c41b"
crypto-browserify@^3.11.0:
version "3.12.0"
resolved "https://registry.yarnpkg.com/crypto-browserify/-/crypto-browserify-3.12.0.tgz#396cf9f3137f03e4b8e532c58f698254e00f80ec"
@ -2611,10 +2684,17 @@ es6-map@^0.1.3:
es6-symbol "~3.1.1"
event-emitter "~0.3.5"
es6-promise@^4.0.5:
es6-promise@^4.0.3, es6-promise@^4.0.5:
version "4.2.5"
resolved "https://registry.yarnpkg.com/es6-promise/-/es6-promise-4.2.5.tgz#da6d0d5692efb461e082c14817fe2427d8f5d054"
es6-promisify@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/es6-promisify/-/es6-promisify-5.0.0.tgz#5109d62f3e56ea967c4b63505aef08291c8a5203"
integrity sha1-UQnWLz5W6pZ8S2NQWu8IKRyKUgM=
dependencies:
es6-promise "^4.0.3"
es6-set@~0.1.5:
version "0.1.5"
resolved "https://registry.yarnpkg.com/es6-set/-/es6-set-0.1.5.tgz#d2b3ec5d4d800ced818db538d28974db0a73ccb1"
@ -3875,6 +3955,14 @@ https-browserify@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/https-browserify/-/https-browserify-1.0.0.tgz#ec06c10e0a34c0f2faf199f7fd7fc78fffd03c73"
https-proxy-agent@2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/https-proxy-agent/-/https-proxy-agent-2.2.1.tgz#51552970fa04d723e04c56d04178c3f92592bbc0"
integrity sha512-HPCTS1LW51bcyMYbxUIOO4HEOlQ1/1qRaFWcyxvwaqUS9TY88aoEuHUY33kuAh1YhVVaDQhLZsnPd+XNARWZlQ==
dependencies:
agent-base "^4.1.0"
debug "^3.1.0"
iconv-lite@0.4.19, iconv-lite@^0.4.17:
version "0.4.19"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.19.tgz#f7468f60135f5e5dad3399c0a81be9a1603a082b"
@ -4105,7 +4193,7 @@ is-boolean-object@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/is-boolean-object/-/is-boolean-object-1.0.0.tgz#98f8b28030684219a95f375cfbd88ce3405dff93"
is-buffer@^1.1.5, is-buffer@~1.1.1:
is-buffer@^1.1.5:
version "1.1.6"
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be"
@ -5068,6 +5156,16 @@ lru-cache@^4.0.1:
pseudomap "^1.0.2"
yallist "^2.1.2"
lru_map@0.3.3:
version "0.3.3"
resolved "https://registry.yarnpkg.com/lru_map/-/lru_map-0.3.3.tgz#b5c8351b9464cbd750335a79650a0ec0e56118dd"
integrity sha1-tcg1G5Rky9dQM1p5ZQoOwOVhGN0=
lsmod@1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/lsmod/-/lsmod-1.0.0.tgz#9a00f76dca36eb23fa05350afe1b585d4299e64b"
integrity sha1-mgD3bco26yP6BTUK/htYXUKZ5ks=
make-dir@^1.0.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-1.2.0.tgz#6d6a49eead4aae296c53bbf3a1a008bd6c89469b"
@ -5125,14 +5223,6 @@ md5.js@^1.3.4:
hash-base "^3.0.0"
inherits "^2.0.1"
md5@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/md5/-/md5-2.2.1.tgz#53ab38d5fe3c8891ba465329ea23fac0540126f9"
dependencies:
charenc "~0.0.1"
crypt "~0.0.1"
is-buffer "~1.1.1"
media-typer@0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748"
@ -6800,22 +6890,6 @@ range-parser@^1.0.3, range-parser@~1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.0.tgz#f49be6b487894ddc40dcc94a322f611092e00d5e"
raven-js@^3.27.0:
version "3.27.0"
resolved "https://registry.yarnpkg.com/raven-js/-/raven-js-3.27.0.tgz#9f47c03e17933ce756e189f3669d49c441c1ba6e"
integrity sha512-vChdOL+yzecfnGA+B5EhEZkJ3kY3KlMzxEhShKh6Vdtooyl0yZfYNFQfYzgMf2v4pyQa+OTZ5esTxxgOOZDHqw==
raven@^2.6.4:
version "2.6.4"
resolved "https://registry.yarnpkg.com/raven/-/raven-2.6.4.tgz#458d4a380c8fbb59e0150c655625aaf60c167ea3"
integrity sha512-6PQdfC4+DQSFncowthLf+B6Hr0JpPsFBgTVYTAOq7tCmx/kR4SXbeawtPch20+3QfUcQDoJBLjWW1ybvZ4kXTw==
dependencies:
cookie "0.3.1"
md5 "^2.2.1"
stack-trace "0.0.10"
timed-out "4.0.1"
uuid "3.3.2"
raw-body@2.3.2:
version "2.3.2"
resolved "https://registry.yarnpkg.com/raw-body/-/raw-body-2.3.2.tgz#bcd60c77d3eb93cde0050295c3f379389bc88f89"
@ -8223,7 +8297,7 @@ time-stamp@^2.0.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/time-stamp/-/time-stamp-2.1.0.tgz#6c5c0b2bc835a244616abcfddf81ce13a1975c9f"
timed-out@4.0.1, timed-out@^4.0.0:
timed-out@^4.0.0:
version "4.0.1"
resolved "https://registry.yarnpkg.com/timed-out/-/timed-out-4.0.1.tgz#f32eacac5a175bea25d7fab565ab3ed8741ef56f"
@ -8306,7 +8380,7 @@ trim-right@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/trim-right/-/trim-right-1.0.1.tgz#cb2e1203067e0c8de1f614094b9fe45704ea6003"
tslib@^1.9.0:
tslib@^1.9.0, tslib@^1.9.3:
version "1.9.3"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.9.3.tgz#d7e4dd79245d85428c4d7e4822a79917954ca286"
integrity sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ==
@ -8536,7 +8610,7 @@ utils-merge@1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/utils-merge/-/utils-merge-1.0.1.tgz#9f95710f50a267947b2ccc124741c1028427e713"
uuid@3.3.2, uuid@^3.0.1, uuid@^3.3.2:
uuid@^3.0.1, uuid@^3.3.2:
version "3.3.2"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.3.2.tgz#1b4af4955eb3077c501c23872fc6513811587131"
integrity sha512-yXJmeNaw3DnnKAOKJE51sL/ZaYfWJRl1pK9dr19YFCu0ObS231AB1/LbqTKRAQ5kw8A90rA6fr4riOUpTZvQZA==