Skip to content

Commit 132c2e9

Browse files
authored
Track UserExceptions in Python (#1937)
1 parent f172f91 commit 132c2e9

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

pkg/cortex/serve/cortex_internal/lib/api/predictor.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ def initialize_impl(
243243
Initialize predictor class as provided by the user.
244244
245245
job_spec is a dictionary when the "kind" of the API is set to "BatchAPI". Otherwise, it's None.
246+
247+
Can raise UserRuntimeException/UserException/CortexException.
246248
"""
247249

248250
# build args
@@ -306,6 +308,7 @@ def initialize_impl(
306308
return initialized_impl
307309

308310
def class_impl(self, project_dir):
311+
"""Can only raise UserException/CortexException exceptions"""
309312
if self.type in [TensorFlowPredictorType, TensorFlowNeuronPredictorType]:
310313
target_class_name = "TensorFlowPredictor"
311314
validations = TENSORFLOW_CLASS_VALIDATION
@@ -322,20 +325,21 @@ def class_impl(self, project_dir):
322325
predictor_class = self._get_class_impl(
323326
"cortex_predictor", os.path.join(project_dir, self.path), target_class_name
324327
)
325-
except (UserException, Exception) as e:
328+
except Exception as e:
326329
e.wrap("error in " + self.path)
327330
raise
328331

329332
try:
330333
validate_class_impl(predictor_class, validations)
331334
if self.type == PythonPredictorType:
332335
validate_python_predictor_with_models(predictor_class, self.api_spec)
333-
except (UserException, Exception) as e:
336+
except Exception as e:
334337
e.wrap("error in " + self.path)
335338
raise
336339
return predictor_class
337340

338341
def _get_class_impl(self, module_name, impl_path, target_class_name):
342+
"""Can only raise UserException exception"""
339343
if impl_path.endswith(".pickle"):
340344
try:
341345
with open(impl_path, "rb") as pickle_file:

pkg/cortex/serve/cortex_internal/lib/telemetry.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def init_sentry(
7373
dsn=dsn,
7474
environment=environment,
7575
release=release,
76-
ignore_errors=[cexp.UserException, cexp.UserRuntimeException],
76+
ignore_errors=[cexp.UserRuntimeException],
7777
attach_stacktrace=True,
7878
integrations=[
7979
LoggingIntegration(event_level=None, level=None),

pkg/cortex/serve/cortex_internal/serve/serve.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ def check_if_crons_have_failed():
333333
predict_route = "/predict"
334334
local_cache["predict_route"] = predict_route
335335

336-
except (UserRuntimeException, Exception) as err:
336+
except Exception as err:
337337
if not isinstance(err, UserRuntimeException):
338338
capture_exception(err)
339339
logger.exception("failed to start api")

pkg/cortex/serve/start/batch.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def handle_batch_message(message):
227227
api.post_metrics(
228228
[success_counter_metric(), time_per_batch_metric(time.time() - start_time)]
229229
)
230-
except (UserRuntimeException, Exception) as err:
230+
except Exception as err:
231231
if not isinstance(err, UserRuntimeException):
232232
capture_exception(err)
233233

@@ -285,7 +285,7 @@ def handle_on_job_complete(message):
285285
break
286286
should_run_on_job_complete = True
287287
time.sleep(10) # verify that the queue is empty one more time
288-
except (UserRuntimeException, Exception) as err:
288+
except Exception as err:
289289
raise type(err)("failed to handle on_job_complete") from err
290290
finally:
291291
with receipt_handle_mutex:
@@ -339,7 +339,7 @@ def start():
339339
metrics_client=metrics_client,
340340
job_spec=job_spec,
341341
)
342-
except (UserException, UserRuntimeException) as err:
342+
except UserRuntimeException as err:
343343
err.wrap(f"failed to start job {job_spec['job_id']}")
344344
logger.error(str(err), exc_info=True)
345345
sys.exit(1)

0 commit comments

Comments
 (0)