28
28
import os
29
29
import traceback
30
30
import platform
31
+ import distro
32
+ import sentry_sdk
31
33
32
34
from classes import info
33
- from classes .logger import log
34
35
35
36
36
- def ExceptionHandler (exeception_type , exeception_value , exeception_traceback ):
37
- """Callback for any unhandled exceptions"""
38
- from classes .metrics import track_exception_stacktrace
37
+ def init_sentry_tracing ():
38
+ """Init all Sentry tracing"""
39
39
40
- log .error (
41
- 'Unhandled Exception' ,
42
- exc_info = (exeception_type , exeception_value , exeception_traceback ))
40
+ # Determine sample rate for exceptions
41
+ traces_sample_rate = 0.1
42
+ environment = "production"
43
+ if "-dev" in info .VERSION :
44
+ # Dev mode, trace all exceptions
45
+ traces_sample_rate = 1.0
46
+ environment = "development"
43
47
44
- # Build string of stack trace
45
- stacktrace = "Python %s" % "" .join (
46
- traceback .format_exception (
47
- exeception_type , exeception_value , exeception_traceback ))
48
+ # Initialize sentry exception tracing
49
+ sentry_sdk .init (
50
+ "https://[email protected] /5795985" ,
51
+ traces_sample_rate = traces_sample_rate ,
52
+ release = f"openshot@{ info .VERSION } " ,
53
+ environment = environment
54
+ )
55
+ sentry_sdk .set_tag ("system" , platform .system ())
56
+ sentry_sdk .set_tag ("machine" , platform .machine ())
57
+ sentry_sdk .set_tag ("processor" , platform .processor ())
58
+ sentry_sdk .set_tag ("platform" , platform .platform ())
59
+ sentry_sdk .set_tag ("distro" , " " .join (distro .linux_distribution ()))
48
60
49
- # Report traceback to webservice (if enabled)
50
- track_exception_stacktrace (stacktrace , "openshot-qt" )
61
+
62
+ def disable_sentry_tracing ():
63
+ """Disable all Sentry tracing requests"""
64
+ sentry_sdk .init ()
51
65
52
66
53
67
def tail_file (f , n , offset = None ):
@@ -72,7 +86,7 @@ def tail_file(f, n, offset=None):
72
86
73
87
def libopenshot_crash_recovery ():
74
88
"""Walk libopenshot.log for the last line before this launch"""
75
- from classes .metrics import track_exception_stacktrace , track_metric_error
89
+ from classes .metrics import track_metric_error
76
90
77
91
log_path = os .path .join (info .USER_PATH , "libopenshot.log" )
78
92
last_log_line = ""
@@ -84,7 +98,8 @@ def libopenshot_crash_recovery():
84
98
with open (log_path , "rb" ) as f :
85
99
# Read from bottom up
86
100
for raw_line in reversed (tail_file (f , 500 )):
87
- line = str (raw_line , 'utf-8' )
101
+ # Format and remove extra spaces from line
102
+ line = " " .join (str (raw_line , 'utf-8' ).split ()) + "\n "
88
103
# Detect stack trace
89
104
if "End of Stack Trace" in line :
90
105
found_stack = True
@@ -113,10 +128,13 @@ def libopenshot_crash_recovery():
113
128
# Split last stack trace (if any)
114
129
if last_stack_trace :
115
130
# Get top line of stack trace (for metrics)
116
- last_log_line = last_stack_trace .split ("\n " )[0 ].strip ()
131
+ exception_lines = last_stack_trace .split ("\n " )
132
+ last_log_line = exception_lines [0 ].strip ()
117
133
118
- # Send stacktrace for debugging (if send metrics is enabled)
119
- track_exception_stacktrace (last_stack_trace , "libopenshot" )
134
+ # Format and add exception log to Sentry context
135
+ # Split list of lines into smaller lists (so we don't exceed Sentry limits)
136
+ sentry_sdk .set_context ("libopenshot" , {"stack-trace" : exception_lines })
137
+ sentry_sdk .set_tag ("component" , "libopenshot" )
120
138
121
139
# Clear / normalize log line (so we can roll them up in the analytics)
122
140
if last_log_line :
@@ -142,3 +160,5 @@ def libopenshot_crash_recovery():
142
160
143
161
# Report exception (with last libopenshot line... if found)
144
162
track_metric_error ("unhandled-crash%s" % last_log_line , True )
163
+
164
+ return last_log_line
0 commit comments