1919from sentry_sdk .traces import BAGGAGE_HEADER_NAME , SegmentNameSource , Span
2020from sentry_sdk .tracing_utils import Baggage
2121from sentry_sdk .utils import (
22+ _register_control_flow_exception ,
2223 capture_internal_exceptions ,
2324 event_from_exception ,
2425 parse_version ,
@@ -78,6 +79,7 @@ def setup_once() -> None:
7879 _patch_celery_send_task ()
7980 _patch_worker_exit ()
8081 _patch_producer_publish ()
82+ _register_control_flow_exception (list (CELERY_CONTROL_FLOW_EXCEPTIONS ))
8183
8284 # This logger logs every status of every task that ran on the worker.
8385 # Meaning that every task's breadcrumbs are full of stuff like "Task
@@ -90,25 +92,18 @@ def setup_once() -> None:
9092 ignore_logger_for_events ("celery.redirected" )
9193
9294
93- def _set_status (status : str ) -> None :
94- with capture_internal_exceptions ():
95- span = sentry_sdk .get_current_span ()
96-
97- if span is not None :
98- span .status = "ok" if status == "ok" else "error"
99-
100-
10195def _capture_exception (task : "Any" , exc_info : "ExcInfo" ) -> None :
10296 client = sentry_sdk .get_client ()
10397 if client .get_integration (CeleryIntegration ) is None :
10498 return
10599
106100 if isinstance (exc_info [1 ], CELERY_CONTROL_FLOW_EXCEPTIONS ):
107- # ??? Doesn't map to anything
108- _set_status ("aborted" )
101+ # Expected control flow exits, not errors
109102 return
110103
111- _set_status ("internal_error" )
104+ span = sentry_sdk .get_current_span ()
105+ if span is not None :
106+ span .status = "error"
112107
113108 if hasattr (task , "throws" ) and isinstance (exc_info [1 ], task .throws ):
114109 return
0 commit comments