Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sentrivana committed Mar 22, 2024
1 parent 6ca86b7 commit d08dbe1
Showing 1 changed file with 24 additions and 26 deletions.
50 changes: 24 additions & 26 deletions sentry_sdk/integrations/huey.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,10 @@ def _capture_exception(exc_info):

def _wrap_task_execute(func):
# type: (F) -> F

@ensure_integration_enabled(HueyIntegration, func)
def _sentry_execute(*args, **kwargs):
# type: (*Any, **Any) -> Any
if sentry_sdk.get_client().get_integration(HueyIntegration) is None:
return func(*args, **kwargs)

try:
result = func(*args, **kwargs)
except Exception:
Expand All @@ -142,28 +141,27 @@ def patch_execute():
@ensure_integration_enabled(HueyIntegration, old_execute)
def _sentry_execute(self, task, timestamp=None):
# type: (Huey, Task, Optional[datetime]) -> Any
scope = Scope.get_isolation_scope()

with capture_internal_exceptions():
scope._name = "huey"
scope.clear_breadcrumbs()
scope.add_event_processor(_make_event_processor(task))

sentry_headers = task.kwargs.pop("sentry_headers", None)

transaction = continue_trace(
sentry_headers or {},
name=task.name,
op=OP.QUEUE_TASK_HUEY,
source=TRANSACTION_SOURCE_TASK,
)
transaction.set_status("ok")

if not getattr(task, "_sentry_is_patched", False):
task.execute = _wrap_task_execute(task.execute)
task._sentry_is_patched = True

with sentry_sdk.start_transaction(transaction):
return old_execute(self, task, timestamp)
with sentry_sdk.isolation_scope() as scope:
with capture_internal_exceptions():
scope._name = "huey"
scope.clear_breadcrumbs()
scope.add_event_processor(_make_event_processor(task))

sentry_headers = task.kwargs.pop("sentry_headers", None)

transaction = continue_trace(
sentry_headers or {},
name=task.name,
op=OP.QUEUE_TASK_HUEY,
source=TRANSACTION_SOURCE_TASK,
)
transaction.set_status("ok")

if not getattr(task, "_sentry_is_patched", False):
task.execute = _wrap_task_execute(task.execute)
task._sentry_is_patched = True

with sentry_sdk.start_transaction(transaction):
return old_execute(self, task, timestamp)

Huey._execute = _sentry_execute

0 comments on commit d08dbe1

Please sign in to comment.