-
Notifications
You must be signed in to change notification settings - Fork 616
feat(huey): Migrate Huey integration to spans-first tracing #6399
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: py-2426-fix-group-and-chord-handling
Are you sure you want to change the base?
Changes from all commits
857ba47
f815ea4
e1e73be
60abc3b
7d33b81
97fb86c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,11 +7,13 @@ | |
| from sentry_sdk.consts import OP, SPANSTATUS | ||
| from sentry_sdk.integrations import DidNotEnable, Integration | ||
| from sentry_sdk.scope import should_send_default_pii | ||
| from sentry_sdk.traces import SegmentSource, SpanStatus, StreamedSpan | ||
| from sentry_sdk.tracing import ( | ||
| BAGGAGE_HEADER_NAME, | ||
| SENTRY_TRACE_HEADER_NAME, | ||
| TransactionSource, | ||
| ) | ||
| from sentry_sdk.tracing_utils import has_span_streaming_enabled | ||
| from sentry_sdk.utils import ( | ||
| SENSITIVE_DATA_SUBSTITUTE, | ||
| capture_internal_exceptions, | ||
|
|
@@ -60,7 +62,7 @@ def patch_enqueue() -> None: | |
|
|
||
| @ensure_integration_enabled(HueyIntegration, old_enqueue) | ||
| def _sentry_enqueue( | ||
| self: "Huey", item: "Union[Task, HueyGroup, HueyChord]" | ||
| self: "Huey", item: "Any" | ||
| ) -> "Optional[Union[Result, ResultGroup]]": | ||
| if HueyChord is not None and isinstance(item, HueyChord): | ||
| span_name = "Huey Chord" | ||
|
|
@@ -69,16 +71,31 @@ def _sentry_enqueue( | |
| else: | ||
| span_name = item.name | ||
|
|
||
| with sentry_sdk.start_span( | ||
| op=OP.QUEUE_SUBMIT_HUEY, | ||
| name=span_name, | ||
| origin=HueyIntegration.origin, | ||
| ): | ||
| if ( | ||
| not isinstance(item, PeriodicTask) | ||
| and not (HueyGroup is not None and isinstance(item, HueyGroup)) | ||
| and not (HueyChord is not None and isinstance(item, HueyChord)) | ||
| ): | ||
| is_span_streaming_enabled = has_span_streaming_enabled( | ||
| sentry_sdk.get_client().options | ||
| ) | ||
|
|
||
| span_ctx = None | ||
| if is_span_streaming_enabled: | ||
| span_ctx = sentry_sdk.traces.start_span( | ||
| name=span_name, | ||
| attributes={ | ||
| "sentry.op": OP.QUEUE_SUBMIT_HUEY, | ||
| "sentry.origin": HueyIntegration.origin, | ||
| }, | ||
| ) | ||
| else: | ||
| span_ctx = sentry_sdk.start_span( | ||
| op=OP.QUEUE_SUBMIT_HUEY, | ||
| name=span_name, | ||
| origin=HueyIntegration.origin, | ||
| ) | ||
|
|
||
| no_headers_types = (PeriodicTask,) + tuple( | ||
| t for t in [HueyGroup, HueyChord] if t is not None | ||
| ) | ||
| with span_ctx: | ||
| if not isinstance(item, no_headers_types): | ||
| # Attach trace propagation data to task kwargs. We do | ||
| # not do this for periodic tasks, as these don't | ||
| # really have an originating transaction. | ||
|
|
@@ -124,12 +141,22 @@ def event_processor(event: "Event", hint: "Hint") -> "Optional[Event]": | |
|
|
||
| def _capture_exception(exc_info: "ExcInfo") -> None: | ||
| scope = sentry_sdk.get_current_scope() | ||
| is_span_streaming_enabled = has_span_streaming_enabled( | ||
| sentry_sdk.get_client().options | ||
| ) | ||
|
|
||
| if exc_info[0] in HUEY_CONTROL_FLOW_EXCEPTIONS: | ||
| scope.transaction.set_status(SPANSTATUS.ABORTED) | ||
| if not is_span_streaming_enabled: | ||
| scope.transaction.set_status(SPANSTATUS.ABORTED) | ||
| elif type(scope._span) is StreamedSpan: | ||
| scope._span._segment.status = SpanStatus.OK | ||
| return | ||
|
|
||
| scope.transaction.set_status(SPANSTATUS.INTERNAL_ERROR) | ||
| if not is_span_streaming_enabled: | ||
| scope.transaction.set_status(SPANSTATUS.INTERNAL_ERROR) | ||
| elif type(scope._span) is StreamedSpan: | ||
| scope._span._segment.status = SpanStatus.ERROR | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Subclass control-flow misclassifiedMedium Severity This commit adds Huey control-flow handling in Reviewed by Cursor Bugbot for commit 97fb86c. Configure here. |
||
|
|
||
| event, hint = event_from_exception( | ||
| exc_info, | ||
| client_options=sentry_sdk.get_client().options, | ||
|
|
@@ -167,21 +194,42 @@ def _sentry_execute( | |
| 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=TransactionSource.TASK, | ||
| origin=HueyIntegration.origin, | ||
| is_span_streaming_enabled = has_span_streaming_enabled( | ||
| sentry_sdk.get_client().options | ||
| ) | ||
| transaction.set_status(SPANSTATUS.OK) | ||
|
|
||
| if is_span_streaming_enabled: | ||
| headers = sentry_headers or {} | ||
| sentry_sdk.traces.continue_trace(headers) | ||
| span_ctx = sentry_sdk.traces.start_span( | ||
| name=task.name, | ||
| attributes={ | ||
| "sentry.op": OP.QUEUE_TASK_HUEY, | ||
| "sentry.origin": HueyIntegration.origin, | ||
| "sentry.span.source": SegmentSource.TASK, | ||
| "messaging.message.id": task.id, | ||
| "messaging.message.system": "huey", | ||
| "messaging.message.retry.count": (task.default_retries or 0) | ||
| - task.retries, | ||
| }, | ||
| parent_span=None, | ||
| ) | ||
|
ericapisani marked this conversation as resolved.
|
||
| else: | ||
| transaction = continue_trace( | ||
| sentry_headers or {}, | ||
| name=task.name, | ||
| op=OP.QUEUE_TASK_HUEY, | ||
| source=TransactionSource.TASK, | ||
| origin=HueyIntegration.origin, | ||
| ) | ||
| transaction.set_status(SPANSTATUS.OK) | ||
| span_ctx = sentry_sdk.start_transaction(transaction) | ||
|
|
||
| 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): | ||
| with span_ctx: | ||
| return old_execute(self, task, timestamp) | ||
|
|
||
| Huey._execute = _sentry_execute | ||


Uh oh!
There was an error while loading. Please reload this page.