From 2e4c3fed249a03f9c47d014903c002e00ba242c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 26 Jun 2020 18:54:39 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20error=20tracking:=20better?= =?UTF-8?q?=20integration=20with=20UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../templates/errortracking_javascripts.jinja2 | 16 ++++++---------- src/octoprint/static/js/app/helpers.js | 9 +++++++++ src/octoprint/static/js/app/main.js | 18 ++++++++++++++++++ 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/octoprint/plugins/errortracking/templates/errortracking_javascripts.jinja2 b/src/octoprint/plugins/errortracking/templates/errortracking_javascripts.jinja2 index d449fb7fd..776eaf8a5 100644 --- a/src/octoprint/plugins/errortracking/templates/errortracking_javascripts.jinja2 +++ b/src/octoprint/plugins/errortracking/templates/errortracking_javascripts.jinja2 @@ -8,18 +8,14 @@ Sentry.init({ dsn: errortracking_url_coreui, release: VERSION, - whitelistUrls: [ - // only include static assets - "/static/" - ], - blacklistUrls: [ - // exclude third party plugins - "/static/webassets/packed_plugins.js" + allowUrls: [ + // only include errors raise in HTML, packed core & client + {% assets "js_client" %}"{{ ASSET_URL }}",{% endassets %} + {% assets "js_core" %}"{{ ASSET_URL }}",{% endassets %} + {% if g.locale %}"{{ url_for('localeJs', locale=g.locale, domain='messages') }}"{% endif %} ] }); - Sentry.configureScope(function (scope) { - scope.setUser({"id": errortracking_unique_id}); - }); + Sentry.setUser({"id": errortracking_unique_id}); ERRORTRACKING_ENABLED = true; log.info("Initialized error tracking"); }; diff --git a/src/octoprint/static/js/app/helpers.js b/src/octoprint/static/js/app/helpers.js index ac8f13a56..fcc3e4e58 100644 --- a/src/octoprint/static/js/app/helpers.js +++ b/src/octoprint/static/js/app/helpers.js @@ -1259,6 +1259,9 @@ function setOnViewModelIf(viewModel, key, value, condition) { viewModel[key] = value; } catch (exc) { + if (Sentry) { + Sentry.captureException(exc); + } log.error("Error while setting", key, "to", value, "on view model", viewModel.constructor.name, ":", (exc.stack || exc)); } } @@ -1274,6 +1277,9 @@ function callViewModelsIf(allViewModels, method, condition, callback) { try { callViewModelIf(viewModel, method, condition, callback); } catch (exc) { + if (Sentry) { + Sentry.captureException(exc); + } log.error("Error calling", method, "on view model", viewModel.constructor.name, ":", (exc.stack || exc)); } }); @@ -1333,6 +1339,9 @@ function callViewModelIf(viewModel, method, condition, callback, raiseErrors) { callback(viewModel[method], viewModel); } } catch (exc) { + if (Sentry) { + Sentry.captureException(exc); + } if (raiseErrors) { throw exc; } else { diff --git a/src/octoprint/static/js/app/main.js b/src/octoprint/static/js/app/main.js index b1bd29d01..01e339ce1 100644 --- a/src/octoprint/static/js/app/main.js +++ b/src/octoprint/static/js/app/main.js @@ -385,6 +385,9 @@ $(function() { try { viewModelInstance = _createViewModelInstance(viewModel, viewModelMap, optionalDependencyPass); } catch (exc) { + if (Sentry) { + Sentry.captureException(exc); + } log.error("Error instantiating", viewModel.name, ":", (exc.stack || exc)); continue; } @@ -598,6 +601,9 @@ $(function() { _.each(allViewModelData, function (viewModelData) { try { if (!Array.isArray(viewModelData) || viewModelData.length !== 2) { + if (Sentry) { + Sentry.captureException(new Error("View model data for" + viewModelData.constructor.name + "has wrong format, expected 2-tuple (viewModel, targets), got:" + viewModelData)); + } log.error("View model data for", viewModelData.constructor.name, "has wrong format, expected 2-tuple (viewModel, targets), got:", viewModelData); return; } @@ -617,6 +623,9 @@ $(function() { try { callViewModel(viewModel, "onBeforeBinding", undefined, true); } catch (exc) { + if (Sentry) { + Sentry.captureException(exc); + } log.error("Error calling onBeforeBinding on view model", viewModel.constructor.name, ":", (exc.stack || exc)); return; } @@ -639,6 +648,9 @@ $(function() { try { object = $(target); } catch (exc) { + if (Sentry) { + Sentry.captureException(exc); + } log.error("Error while attempting to jquery-fy target", target, "of view model", viewModel.constructor.name, ":", (exc.stack || exc)); return; } @@ -665,6 +677,9 @@ $(function() { log.debug("View model", viewModel.constructor.name, "bound to", target); } catch (exc) { + if (Sentry) { + Sentry.captureException(exc); + } log.error("Could not bind view model", viewModel.constructor.name, "to target", target, ":", (exc.stack || exc)); } }); @@ -702,6 +717,9 @@ $(function() { viewModelMap["uiStateViewModel"].loading(false); } catch (exc) { + if (Sentry) { + Sentry.captureException(exc); + } viewModelMap["uiStateViewModel"].showLoadingError("Application startup failed."); throw(exc); }