Skip to content

Commit e790740

Browse files
authored
[cuegui] Add optional sentry support (#1460)
If `sentry.dsn` is set on cuegui.yaml, sentry_sdk becomes active and will capture exceptions.
1 parent 0ac78f8 commit e790740

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

cuegui/cuegui/Constants.py

+2
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ def __packaged_version():
155155

156156
ALLOWED_TAGS = tuple(__config.get('allowed_tags'))
157157

158+
SENTRY_DSN = __config.get('sentry.dsn')
159+
158160
DARK_STYLE_SHEET = os.path.join(CONFIG_PATH, __config.get('style.style_sheet'))
159161
COLOR_THEME = __config.get('style.color_theme')
160162
__bg_colors = __config.get('style.colors.background')

cuegui/cuegui/Main.py

+20
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from __future__ import print_function
2121
from __future__ import division
2222

23+
import getpass
2324
import signal
2425

2526
from qtpy import QtGui
@@ -72,6 +73,8 @@ def startup(app_name, app_version, argv):
7273
settings = cuegui.Layout.startup(app_name)
7374
app.settings = settings
7475

76+
__setup_sentry()
77+
7578
cuegui.Style.init()
7679

7780
mainWindow = cuegui.MainWindow.MainWindow(app_name, app_version, None)
@@ -92,6 +95,23 @@ def startup(app_name, app_version, argv):
9295
app.aboutToQuit.connect(closingTime) # pylint: disable=no-member
9396
app.exec_()
9497

98+
99+
def __setup_sentry():
100+
"""Setup sentry if cuegui.Constants.SENTRY_DSN is defined, nop otherwise"""
101+
if not cuegui.Constants.SENTRY_DSN:
102+
return
103+
104+
try:
105+
# pylint: disable=import-outside-toplevel
106+
# Avoid importing sentry on the top level to make this dependency optional
107+
import sentry_sdk
108+
sentry_sdk.init(cuegui.Constants.SENTRY_DSN)
109+
sentry_sdk.set_user({
110+
'username': getpass.getuser()
111+
})
112+
except ImportError:
113+
logger.warning('Failed to import Sentry')
114+
95115
def closingTime():
96116
"""Window close callback."""
97117
logger.info("Closing all threads...")

cuegui/cuegui/config/cuegui.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ editor.windows: 'notepad'
6464
editor.mac: 'open -t'
6565
editor.linux: 'gview -R -m -M -U {config_path}/gvimrc +'
6666

67+
# Url to the sentry application dsn
68+
# comment out to disable sentry
69+
# sentry.dsn: 'https://[email protected]/10'
70+
6771
resources:
6872
# The max cores and max memory based on the available hardware.
6973
# These values are used by:

0 commit comments

Comments
 (0)