hvoss-techfak commited on
Commit
54810a9
·
1 Parent(s): 6c28396

Still not sentry logging. Adding monkey patch

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py CHANGED
@@ -33,6 +33,24 @@ else:
33
 
34
  sentry_sdk.capture_message("🎉 Sentry is wired up!")
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
  import gradio as gr
38
  import pandas as pd
@@ -107,6 +125,15 @@ def rgba_to_hex(col: str) -> str:
107
  r, g, b = (int(float(x)) for x in m.groups()[:3])
108
  return "#{:02X}{:02X}{:02X}".format(r, g, b)
109
 
 
 
 
 
 
 
 
 
 
110
 
111
  # --- Helper Functions ---
112
  def get_script_args_info(exclude_args=None):
 
33
 
34
  sentry_sdk.capture_message("🎉 Sentry is wired up!")
35
 
36
+ import gradio, functools
37
+ from sentry_sdk import capture_exception, flush
38
+
39
+ orig_run_sync = gradio.utils.run_sync # Gradio 4.x helper
40
+
41
+ def sentry_run_sync(fn):
42
+ @functools.wraps(fn)
43
+ def _wrapped(*args, **kwargs):
44
+ try:
45
+ return fn(*args, **kwargs)
46
+ except Exception as exc:
47
+ capture_exception(exc)
48
+ flush(timeout=2)
49
+ raise
50
+ return _wrapped
51
+
52
+ gradio.utils.run_sync = sentry_run_sync # global patch
53
+
54
 
55
  import gradio as gr
56
  import pandas as pd
 
125
  r, g, b = (int(float(x)) for x in m.groups()[:3])
126
  return "#{:02X}{:02X}{:02X}".format(r, g, b)
127
 
128
+ def sentry_wrap(fn):
129
+ def _inner(*args, **kwargs):
130
+ try:
131
+ return fn(*args, **kwargs)
132
+ except Exception as exc:
133
+ capture_exception(exc) # send to Sentry
134
+ flush(timeout=2) # make sure the event is really sent
135
+ raise # let Gradio show its own error dialog
136
+ return _inner
137
 
138
  # --- Helper Functions ---
139
  def get_script_args_info(exclude_args=None):