`
+ * ``throttled``: Whether to track throttle events detected on the underlying system
+
+.. _sec-bundledplugins-tracking-sourcecode:
+
+Source Code
+-----------
+
+The source of the Anonymous Usage Tracking plugin is bundled with OctoPrint and can be
+found in its source repository under ``src/octoprint/plugins/tracking``.
diff --git a/src/octoprint/plugins/errortracking/__init__.py b/src/octoprint/plugins/errortracking/__init__.py
index e9f19107f..9203ad6d2 100644
--- a/src/octoprint/plugins/errortracking/__init__.py
+++ b/src/octoprint/plugins/errortracking/__init__.py
@@ -9,6 +9,9 @@ import logging
from octoprint.util.version import get_octoprint_version_string, is_released_octoprint_version
+from flask import jsonify
+from flask_babel import gettext
+
SENTRY_URL_SERVER = "https://827d1f11ccda4b31b924f29aaacab493@sentry.io/1373987"
SENTRY_URL_COREUI = "https://30bdc39d2248444c8bc01484f38c9444@sentry.io/1374096"
@@ -21,10 +24,15 @@ SETTINGS_DEFAULTS = dict(enabled=False,
class ErrorTrackingPlugin(octoprint.plugin.SettingsPlugin,
octoprint.plugin.AssetPlugin,
- octoprint.plugin.TemplatePlugin):
+ octoprint.plugin.TemplatePlugin,
+ octoprint.plugin.SimpleApiPlugin):
def get_template_configs(self):
return [
+ dict(type="settings",
+ name=gettext("Error Tracking"),
+ template="errortracking_settings.jinja2",
+ custom_bindings=False),
dict(type="generic", template="errortracking_javascripts.jinja2")
]
@@ -32,22 +40,42 @@ class ErrorTrackingPlugin(octoprint.plugin.SettingsPlugin,
enabled = self._settings.get_boolean(["enabled"])
enabled_unreleased = self._settings.get_boolean(["enabled_unreleased"])
- return dict(enabled=enabled and (enabled_unreleased or is_released_octoprint_version()),
+ return dict(enabled=_is_enabled(enabled, enabled_unreleased),
unique_id=self._settings.get(["unique_id"]),
url_coreui=self._settings.get(["url_coreui"]))
def get_assets(self):
- return dict(js=["js/sentry.min.js",])
+ return dict(js=["js/sentry.min.js", "js/errortracking.js"])
def get_settings_defaults(self):
return SETTINGS_DEFAULTS
+ def on_settings_save(self, data):
+ old_enabled = _is_enabled(self._settings.get_boolean(["enabled"]),
+ self._settings.get_boolean(["enabled_unreleased"]))
-def __plugin_enable__():
+ octoprint.plugin.SettingsPlugin.on_settings_save(self, data)
+
+ enabled = _is_enabled(self._settings.get_boolean(["enabled"]),
+ self._settings.get_boolean(["enabled_unreleased"]))
+
+ if old_enabled != enabled:
+ _enable_errortracking()
+
+ def on_api_get(self, request):
+ return jsonify(**self.get_template_vars())
+
+
+_enabled = False
+def _enable_errortracking():
# this is a bit hackish, but we want to enable error tracking as early in the platform lifecycle as possible
# and hence can't wait until our implementation is initialized and injected with settings
from octoprint.settings import settings
+ global _enabled
+
+ if _enabled:
+ return
version = get_octoprint_version_string()
@@ -64,7 +92,7 @@ def __plugin_enable__():
s.set(["plugins", "errortracking", "unique_id"], unique_id, defaults=plugin_defaults)
s.save()
- if enabled and (enabled_unreleased or is_released_octoprint_version()):
+ if _is_enabled(enabled, enabled_unreleased):
import sentry_sdk
sentry_sdk.init(url_server,
release=version)
@@ -73,6 +101,16 @@ def __plugin_enable__():
scope.user = dict(id=unique_id)
logging.getLogger("octoprint.plugin.errortracking").info("Initialized error tracking")
+ _enabled = True
+
+
+def _is_enabled(enabled, enabled_unreleased):
+ return enabled and (enabled_unreleased or is_released_octoprint_version())
+
+
+def __plugin_enable__():
+ _enable_errortracking()
+
__plugin_name__ = "Error Tracking"
__plugin_author__ = "Gina Häußge"
diff --git a/src/octoprint/plugins/errortracking/static/js/errortracking.js b/src/octoprint/plugins/errortracking/static/js/errortracking.js
new file mode 100644
index 000000000..32ed05e0b
--- /dev/null
+++ b/src/octoprint/plugins/errortracking/static/js/errortracking.js
@@ -0,0 +1,103 @@
+$(function() {
+ function ErrorTrackingViewModel(parameters) {
+ var self = this;
+
+ self.settings = parameters[0];
+ self.loginState = parameters[1];
+
+ var notification = undefined;
+ var performCheck = function() {
+ if (!self.loginState.isAdmin()) return;
+
+ // already enabled?
+ if (self.settings.settings.plugins.errortracking.enabled()) return;
+
+ // RC release channel?
+ var releaseChannel = self.settings.settings.plugins.softwareupdate.octoprint_release_channel();
+ if (releaseChannel === "rc/maintenance" || releaseChannel === "rc/devel") {
+ if (notification !== undefined) return;
+
+ // ignored?
+ try {
+ var ignoredString = localStorage["plugin.errortracking.notification_ignored"];
+ var ignored = false;
+
+ if (ignoredString) {
+ ignored = JSON.parse(ignoredString);
+ }
+
+ if (ignored) return;
+ } catch (ex) {
+ log.error("Error while reading plugin.errortracking.notification_ignored from local storage");
+ }
+
+ // show notification
+ notification = new PNotify({
+ title: gettext("Enable error reporting?"),
+ text: gettext("It looks like you are tracking an OctoPrint RC release channel. It " +
+ "would be great if you would enable error reporting so that any kind of errors that occur " +
+ "with an RC can be looked into more easily. Thank you!
" +
+ "You can find more information on error reporting " +
+ "under Settings > Error Tracking
"),
+ hide: false,
+ confirm: {
+ confirm: true,
+ buttons: [{
+ text: gettext("Ignore"),
+ click: function() {
+ notification.remove();
+ notification = undefined;
+ new PNotify({
+ text: gettext("You can still enable error tracking via \"Settings\" > \"Error Tracking\"")
+ });
+
+ if (Modernizr.localstorage) {
+ localStorage["plugin.errortracking.notification_ignored"] = JSON.stringify(true);
+ }
+ }
+ }, {
+ text: gettext("Enable"),
+ addClass: "btn-primary",
+ click: function() {
+ self.settings.saveData({
+ plugins: {
+ errortracking: {
+ enabled: true
+ }
+ }
+ }).done(function() {
+ notification.remove();
+ notification = undefined;
+ location.reload(true);
+ });
+ }
+ }]
+ },
+ buttons: {
+ closer: false,
+ sticker: false
+ }
+ });
+
+ // not an RC release channel, close notification
+ } else if (notification !== undefined) {
+ notification.remove();
+ notification = undefined;
+ }
+ };
+
+ var subbed = false;
+ self.onStartup = self.onUserLoggedIn = self.onUserLoggedOut = function() {
+ performCheck();
+ if (self.settings && self.settings.settings && self.settings.settings.plugins && self.settings.settings.plugins.softwareupdate && !subbed) {
+ subbed = true;
+ self.settings.settings.plugins.softwareupdate.octoprint_release_channel.subscribe(performCheck);
+ }
+ };
+ }
+
+ OCTOPRINT_VIEWMODELS.push({
+ construct: ErrorTrackingViewModel,
+ dependencies: ["settingsViewModel", "loginStateViewModel"]
+ });
+});
diff --git a/src/octoprint/plugins/errortracking/templates/errortracking_javascripts.jinja2 b/src/octoprint/plugins/errortracking/templates/errortracking_javascripts.jinja2
index e11b8f9bb..e953144dc 100644
--- a/src/octoprint/plugins/errortracking/templates/errortracking_javascripts.jinja2
+++ b/src/octoprint/plugins/errortracking/templates/errortracking_javascripts.jinja2
@@ -1,21 +1,24 @@
diff --git a/src/octoprint/plugins/errortracking/templates/errortracking_settings.jinja2 b/src/octoprint/plugins/errortracking/templates/errortracking_settings.jinja2
new file mode 100644
index 000000000..e5adefa92
--- /dev/null
+++ b/src/octoprint/plugins/errortracking/templates/errortracking_settings.jinja2
@@ -0,0 +1,42 @@
+{{ _('Error Tracking') }}
+
+{% trans %}
+
+ Error tracking will cause any logged exceptions in the server and the browser interface to be sent
+ to OctoPrint's Sentry instance.
+
+
+ By enabling it you help to gather detailed information on the cause of bugs or other issues. This is especially valuable
+ on release candidates, which is why this plugin will also prompt you to enable error tracking if it detects that
+ you are subscribed to an RC release channel.
+
+
+ Please enable this if you are running a release candidate, or are prompted to do so while debugging an issue that you reported.
+
+{% endtrans %}
+
+
+
+{% trans %}
+
+ The Error Tracking plugin is using a Sentry instance kindly provided by
+ sentry.io. For information on their service
+ please refer to their Security & Compliance documentation
+ and their Privacy Policy.
+
+{% endtrans %}
diff --git a/src/octoprint/server/views.py b/src/octoprint/server/views.py
index 8006ad5b6..8cc5f7174 100644
--- a/src/octoprint/server/views.py
+++ b/src/octoprint/server/views.py
@@ -196,7 +196,7 @@ def index():
default_additional_etag = [enable_accesscontrol,
enable_gcodeviewer,
- enable_timelapse]
+ enable_timelapse] + sorted(["{}:{}".format(k, v) for k, v in _plugin_vars.items()])
def get_preemptively_cached_view(key, view, data=None, additional_request_data=None, additional_unless=None):
if (data is None and additional_request_data is None) or g.locale is None:
diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py
index d97c6d171..f9e644974 100644
--- a/src/octoprint/settings.py
+++ b/src/octoprint/settings.py
@@ -298,7 +298,8 @@ default_settings = {
"section_printer", "serial", "printerprofiles", "temperatures", "terminalfilters", "gcodescripts",
"section_features", "features", "webcam", "accesscontrol", "gcodevisualizer", "api", "plugin_appkeys",
"section_octoprint", "server", "folders", "appearance", "plugin_logging", "plugin_pluginmanager",
- "plugin_softwareupdate", "plugin_announcements", "plugin_backup", "plugin_tracking", "plugin_pi_support"
+ "plugin_softwareupdate", "plugin_announcements", "plugin_backup", "plugin_tracking", "plugin_errortracking",
+ "plugin_pi_support"
],
"usersettings": ["access", "interface"],
"wizard": ["access"],