commit 771428c370668824922349b6fa9521f874fa756e
parent 8165cb6de98d23881872077a2cd619b35a630674
Author: Sergej Orlov <wladimirych@gmail.com>
Date: Wed, 11 Dec 2019 21:08:27 +0100
logging: switch to new sentry lib, adapt code, refactor
Diffstat:
15 files changed, 103 insertions(+), 97 deletions(-)
diff --git a/package.json b/package.json
@@ -52,6 +52,7 @@
"webpack-merge": "^4.2.2"
},
"dependencies": {
+ "@sentry/browser": "^5.10.2",
"alertify.js": "^1.0.12",
"blueimp-md5": "^2.12.0",
"browser-filesaver": "^1.1.1",
@@ -63,7 +64,6 @@
"load-script": "^1.0.0",
"mapillary-js": "2.20.0",
"pbf": "^3.0.5",
- "raven-js": "^3.27.0",
"rbush": "^3.0.1",
"regenerator-runtime": "^0.13.3",
"tiny-inflate": "^1.0.2",
diff --git a/src/index.js b/src/index.js
@@ -1,4 +1,4 @@
-import Raven from 'raven-js';
+import * as Sentry from '@sentry/browser';
import './index.css';
import App from './App';
import config from './config';
@@ -21,26 +21,11 @@ function getUid() {
}
if (NODE_ENV === 'production') {
- Raven.config(config.sentryDSN, {release: RELEASE_VER}).install();
+ Sentry.init({
+ dsn: config.sentryDSN,
+ release: RELEASE_VER});
}
-const oldOnunhandledrejection = window.onunhandledrejection;
-
-// Not using addEventListener due to https://github.com/zloirock/core-js/issues/205
-window.onunhandledrejection = (e) => {
- let result = true;
- if (oldOnunhandledrejection) {
- result = oldOnunhandledrejection(e);
- }
- console.error('Uncaught in promise:', e.reason);
- const err = e.reason;
- if (err && err.name) {
- err.name = 'Uncaught in promise: ' + err.name;
- }
- Raven.captureException(err);
- return result;
-};
-
console.log('Version:', RELEASE_VER);
let uid;
@@ -50,13 +35,10 @@ try {
}
console.log('UID:', uid);
-Raven.setUserContext({
- uid: uid,
- cookie: document.cookie
- }
-);
-
-Raven.context(function() {
- App.setUp();
+Sentry.configureScope(function(scope) {
+ scope.setUser({id: uid});
});
+
+App.setUp();
+
diff --git a/src/lib/clipboardCopy/index.js b/src/lib/clipboardCopy/index.js
@@ -36,7 +36,7 @@ function copyToClipboard(s, mouseEvent) {
showNotification('Copied', mouseEvent);
}
} catch (e) {
- logging.captureException(e, {extra: {description: 'clipborad to copy failed'}});
+ logging.captureException(e, 'clipborad to copy failed');
} finally {
document.body.removeChild(ta);
}
diff --git a/src/lib/leaflet.control.elevation-profile/index.js b/src/lib/leaflet.control.elevation-profile/index.js
@@ -242,7 +242,7 @@ const ElevationProfile = L.Class.extend({
}
)
.catch((e) => {
- logging.captureException(e, {extra: {description: 'while getting elevation'}});
+ logging.captureException(e, 'error getting elevation');
notify(`Failed to get elevation data: ${e.message}`);
self._addTo(map);
});
diff --git a/src/lib/leaflet.control.jnx/index.js b/src/lib/leaflet.control.jnx/index.js
@@ -82,7 +82,7 @@ L.Control.JNX = L.Control.extend({
},
makeJnx: function(layer, layerName, zoom) {
- logging.captureBreadcrumbWithUrl({message: 'start making jnx'});
+ logging.captureBreadcrumb('start making jnx');
this.makingJnx(true);
this.downloadProgressDone(0);
@@ -97,7 +97,7 @@ L.Control.JNX = L.Control.extend({
logging.logEvent('jnx end', {eventId, success: true});
})
.catch((e) => {
- logging.captureException(e);
+ logging.captureException(e, 'Failed to create JNX');
logging.logEvent('jnx end', {eventId, success: false, error: e.stack});
notify(`Failed to create JNX: ${e.message}`);
}
diff --git a/src/lib/leaflet.control.layers.configure/index.js b/src/lib/leaflet.control.layers.configure/index.js
@@ -48,7 +48,7 @@ function enableConfig(control, {layers, customLayersOrder}) {
storedLayersEnabled = JSON.parse(serialized);
} catch (e) {
logging.captureMessage('Failed to load enabled layers from localstorage - invalid json',{
- extra: {"localstorage.layersEnabled": serialized.slice(0, 1000)}
+ "localstorage.layersEnabled": serialized.slice(0, 1000)
});
}
}
diff --git a/src/lib/leaflet.control.printPages/control.js b/src/lib/leaflet.control.printPages/control.js
@@ -192,7 +192,7 @@ L.Control.PrintPages = L.Control.extend({
},
savePdf: function() {
- logging.captureBreadcrumbWithUrl({message: 'start save pdf'});
+ logging.captureBreadcrumb('start save pdf');
if (!this._map) {
return;
}
@@ -244,7 +244,7 @@ L.Control.PrintPages = L.Control.extend({
}
}
).catch((e) => {
- logging.captureException(e);
+ logging.captureException(e, 'raster creation failed');
logging.logEvent('print pdf end', {eventId, success: false, error: e.stack});
notify(`Failed to create PDF: ${e.message}`);
}
@@ -252,7 +252,7 @@ L.Control.PrintPages = L.Control.extend({
},
savePageJpg: function(page) {
- logging.captureBreadcrumbWithUrl({message: 'start save page jpg', data: {pageNumber: page.getLabel()}});
+ logging.captureBreadcrumb('start save page jpg', {pageNumber: page.getLabel()});
const pages = [{
latLngBounds: page.getLatLngBounds(),
printSize: page.getPrintSize(),
@@ -296,7 +296,7 @@ L.Control.PrintPages = L.Control.extend({
logging.logEvent('print jpg end', {eventId, success: true});
})
.catch((e) => {
- logging.captureException(e);
+ logging.captureException(e, 'raster creation failed');
logging.logEvent('print jpg end', {eventId, success: false, error: e.stack});
notify(`Failed to create JPEG from page: ${e.message}`);
}
diff --git a/src/lib/leaflet.control.track-list/track-list.js b/src/lib/leaflet.control.track-list/track-list.js
@@ -239,7 +239,7 @@ L.Control.TrackList = L.Control.extend({
},
loadFilesFromDisk: function() {
- logging.captureBreadcrumb({message: 'load track from disk'});
+ logging.captureBreadcrumb('load track from disk');
selectFiles(true).then(this.loadFilesFromFilesObject.bind(this));
},
@@ -251,7 +251,7 @@ L.Control.TrackList = L.Control.extend({
this.readingFiles(this.readingFiles() + 1);
- logging.captureBreadcrumb({message: 'load track from url', data: {url: url}});
+ logging.captureBreadcrumb('load track from url', {trackUrl: url});
loadFromUrl(url)
.then((geodata) => {
this.addTracksFromGeodataArray(geodata);
@@ -317,7 +317,7 @@ L.Control.TrackList = L.Control.extend({
}.bind(this)
);
if (messages.length) {
- logging.captureMessage('errors in loaded tracks', {extra: {message: messages.join('\n'), debugData}});
+ logging.captureMessage('errors in loaded tracks', {message: messages.join('\n'), debugData});
notify(messages.join('\n'));
}
return hasData;
@@ -518,7 +518,7 @@ L.Control.TrackList = L.Control.extend({
message = 'track is too big';
}
logging.captureMessage('Failed to save track to server',
- {extra: {status: e.xhr.status, response: e.xhr.responseText}});
+ {status: e.xhr.status, response: e.xhr.responseText});
notify('Error making link: ' + message);
}
);
diff --git a/src/lib/leaflet.control.track-list/track-list.localstorage.js b/src/lib/leaflet.control.track-list/track-list.localstorage.js
@@ -79,7 +79,7 @@ L.Control.TrackList.include({
s = safeLocalStorage.getItem(key);
safeLocalStorage.removeItem(key);
if (s) {
- logging.captureBreadcrumb({message: 'load track from localStorage'});
+ logging.captureBreadcrumb('load track from localStorage');
s = s.slice(6); // remove "#nktk=" prefix
geodata = parseNktkSequence(s);
this.addTracksFromGeodataArray(geodata, {localStorage: {key, value: s}});
diff --git a/src/lib/leaflet.hashState/leaflet.hashState.js b/src/lib/leaflet.hashState/leaflet.hashState.js
@@ -34,7 +34,7 @@ L.Mixin.HashState = {
_onExternalStateChanged: function(state) {
if (!this.unserializeState(state)) { // state from hash is invalid, update hash from component state
- logging.captureMessageWithUrl(`Invalid state in hash string (key "${this._hashStateKey}")`);
+ logging.captureMessage(`Invalid state in hash string (key "${this._hashStateKey}")`);
hashState.updateState(this._hashStateKey, this.serializeState());
}
}
diff --git a/src/lib/leaflet.layer.geocaching-su/index.js b/src/lib/leaflet.layer.geocaching-su/index.js
@@ -34,14 +34,7 @@ const GeocachingSu = L.Layer.CanvasMarkers.extend({
(xhr) => this._loadMarkers(xhr.response),
(e) => {
this._downloadStarted = false;
- logging.captureException(e, {
- extra: {
- description: 'failed to get geocaching kml',
- url: this.url,
- status: e.xhr.status
- }
- }
- );
+ logging.captureException(e, 'failed to get geocaching kml');
notify('Failed to get geocaching data');
}
);
diff --git a/src/lib/leaflet.layer.geojson-ajax/index.js b/src/lib/leaflet.layer.geojson-ajax/index.js
@@ -26,11 +26,7 @@ L.Layer.GeoJSONAjax = L.GeoJSON.extend({
this.addData(JSON.parse(xhr.response));
},
(e) => {
- logging.captureException(e, {extra: {
- description: 'failed to get geojson',
- url: this.url,
- status: e.xhr.status
- }});
+ logging.captureException(e, 'failed to get geojson');
notify(`Failed to get GeoJSON data from ${this.url}: ${e.message}`);
}
);
diff --git a/src/lib/leaflet.layer.westraPasses/westraPassesMarkers.js b/src/lib/leaflet.layer.westraPasses/westraPassesMarkers.js
@@ -31,14 +31,7 @@ const WestraPassesMarkers = L.Layer.CanvasMarkers.extend({
(xhr) => this._loadMarkers(xhr),
(e) => {
this._downloadStarted = false;
- logging.captureException(e, {
- extra: {
- description: 'failed to get westra passes',
- url: this.url,
- status: e.xhr.status
- }
- }
- );
+ logging.captureException(e, 'failed to get westra passes');
notify('Failed to get Westra passes data');
}
);
diff --git a/src/lib/logging/index.js b/src/lib/logging/index.js
@@ -1,4 +1,4 @@
-import Raven from 'raven-js';
+import * as Sentry from '@sentry/browser';
function randId() {
return Math.random().toString(36).substring(2, 13);
@@ -6,32 +6,30 @@ function randId() {
const sessionId = randId();
-function captureException(e, options) {
- console.log('captureException', e, options);
- Raven.captureException(e, options);
-}
-
-function captureMessage(msg, options) {
- console.log('captureMessage', msg, options);
- Raven.captureMessage(msg, options);
-}
-
-function captureMessageWithUrl(msg) {
- captureMessage(msg, {extra: {url: window.location.toString()}});
-}
-
-function setExtraContext(data) {
- Raven.setExtraContext(data);
+function captureMessage(msg, extra={}) {
+ extra.url = window.location.toString();
+ console.log('captureMessage', msg, extra);
+ Sentry.withScope(function(scope) {
+ scope.setExtras(extra);
+ Sentry.captureMessage(msg);
+ });
}
-function captureBreadcrumb(crumb) {
- Raven.captureBreadcrumb(crumb);
+function captureException(e, description) {
+ console.log('captureException', e, description);
+ Sentry.withScope(function(scope) {
+ if (description) {
+ scope.setTag('description', description);
+ }
+ scope.setExtra('url', window.location.toString());
+ Sentry.captureException(e);
+ });
}
-
-function captureBreadcrumbWithUrl(crumb) {
- const data = Object.assign(crumb.data || {}, {'url': window.location.toString()});
- crumb = Object.assign({}, crumb, {data});
- captureBreadcrumb(crumb);
+function captureBreadcrumb(message, data={}) {
+ data.url = window.location.toString();
+ Sentry.addBreadcrumb({
+ message, data
+ });
}
function logEvent(eventName, extra) {
@@ -55,7 +53,4 @@ function logEvent(eventName, extra) {
}
}
-
-
-export default {captureMessage, captureException, setExtraContext, captureBreadcrumbWithUrl, captureBreadcrumb,
- captureMessageWithUrl, logEvent, randId};
+export default {captureMessage, captureException, captureBreadcrumb, logEvent, randId};
diff --git a/yarn.lock b/yarn.lock
@@ -732,6 +732,58 @@
resolved "https://registry.yarnpkg.com/@nodelib/fs.stat/-/fs.stat-1.1.3.tgz#2b5a3ab3f918cca48a8c754c08168e3f03eba61b"
integrity sha512-shAmDyaQC4H92APFoIaVDHCx5bStIocgvbwQyxPRrbUY20V1EYTbSDchWbuwlMG3V17cprZhA6+78JfB+3DTPw==
+"@sentry/browser@^5.10.2":
+ version "5.10.2"
+ resolved "https://registry.yarnpkg.com/@sentry/browser/-/browser-5.10.2.tgz#0bbb05505c58ea998c833cffec3f922fe4b4fa58"
+ integrity sha512-r3eyBu2ln7odvWtXARCZPzpuGrKsD6U9F3gKTu4xdFkA0swSLUvS7AC2FUksj/1BE23y+eB/zzPT+RYJ58tidA==
+ dependencies:
+ "@sentry/core" "5.10.2"
+ "@sentry/types" "5.10.0"
+ "@sentry/utils" "5.10.2"
+ tslib "^1.9.3"
+
+"@sentry/core@5.10.2":
+ version "5.10.2"
+ resolved "https://registry.yarnpkg.com/@sentry/core/-/core-5.10.2.tgz#1cb64489e6f8363c3249415b49d3f1289814825f"
+ integrity sha512-sKVeFH3v8K8xw2vM5MKMnnyAAwih+JSE3pbNL0CcCCA+/SwX+3jeAo2BhgXev2SAR/TjWW+wmeC9TdIW7KyYbg==
+ dependencies:
+ "@sentry/hub" "5.10.2"
+ "@sentry/minimal" "5.10.2"
+ "@sentry/types" "5.10.0"
+ "@sentry/utils" "5.10.2"
+ tslib "^1.9.3"
+
+"@sentry/hub@5.10.2":
+ version "5.10.2"
+ resolved "https://registry.yarnpkg.com/@sentry/hub/-/hub-5.10.2.tgz#25d9f36b8f7c5cb65cf486737fa61dc9bf69b7e3"
+ integrity sha512-hSlZIiu3hcR/I5yEhlpN9C0nip+U7hiRzRzUQaBiHO4YG4TC58NqnOPR89D/ekiuHIXzFpjW9OQmqtAMRoSUYA==
+ dependencies:
+ "@sentry/types" "5.10.0"
+ "@sentry/utils" "5.10.2"
+ tslib "^1.9.3"
+
+"@sentry/minimal@5.10.2":
+ version "5.10.2"
+ resolved "https://registry.yarnpkg.com/@sentry/minimal/-/minimal-5.10.2.tgz#267c2f3aa6877a0fe7a86971942e83f3ee616580"
+ integrity sha512-GalixiM9sckYfompH5HHTp9XT2BcjawBkcl1DMEKUBEi37+kUq0bivOBmnN1G/I4/wWOUdnAI/kagDWaWpbZPg==
+ dependencies:
+ "@sentry/hub" "5.10.2"
+ "@sentry/types" "5.10.0"
+ tslib "^1.9.3"
+
+"@sentry/types@5.10.0":
+ version "5.10.0"
+ resolved "https://registry.yarnpkg.com/@sentry/types/-/types-5.10.0.tgz#4f0ba31b6e4d5371112c38279f11f66c73b43746"
+ integrity sha512-TW20GzkCWsP6uAxR2JIpIkiitCKyIOfkyDsKBeLqYj4SaZjfvBPnzgNCcYR0L0UsP1/Es6oHooZfIGSkp6GGxQ==
+
+"@sentry/utils@5.10.2":
+ version "5.10.2"
+ resolved "https://registry.yarnpkg.com/@sentry/utils/-/utils-5.10.2.tgz#261f575079d30aaf604e59f5f4de0aa21db22252"
+ integrity sha512-UcbbaFpYrGSV448lQ16Cr+W/MPuKUflQQUdrMCt5vgaf5+M7kpozlcji4GGGZUCXIA7oRP93ABoXj55s1OM9zw==
+ dependencies:
+ "@sentry/types" "5.10.0"
+ tslib "^1.9.3"
+
"@snyk/cli-interface@1.5.0":
version "1.5.0"
resolved "https://registry.yarnpkg.com/@snyk/cli-interface/-/cli-interface-1.5.0.tgz#b9dbe6ebfb86e67ffabf29d4e0d28a52670ac456"
@@ -7376,11 +7428,6 @@ range-parser@^1.2.1, range-parser@~1.2.1:
resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.1.tgz#3cf37023d199e1c24d1a55b84800c2f3e6468031"
integrity sha512-Hrgsx+orqoygnmhFbKaHE6c296J+HTAQXoxEF6gNupROmmGJRoyzfG3ccAveqCBrwr/2yxQ5BVd/GTl5agOwSg==
-raven-js@^3.27.0:
- version "3.27.2"
- resolved "https://registry.yarnpkg.com/raven-js/-/raven-js-3.27.2.tgz#6c33df952026cd73820aa999122b7b7737a66775"
- integrity sha512-mFWQcXnhRFEQe5HeFroPaEghlnqy7F5E2J3Fsab189ondqUzcjwSVi7el7F36cr6PvQYXoZ1P2F5CSF2/azeMQ==
-
raw-body@2.4.0:
version "2.4.0"
resolved "https://registry.yarnpkg.com/raw-body/-/raw-body-2.4.0.tgz#a1ce6fb9c9bc356ca52e89256ab59059e13d0332"