Skip to content

feat(huey): Migrate Huey integration to spans-first tracing#6399

Open
ericapisani wants to merge 12 commits into
masterfrom
py-2331-huey-span-first
Open

feat(huey): Migrate Huey integration to spans-first tracing#6399
ericapisani wants to merge 12 commits into
masterfrom
py-2331-huey-span-first

Conversation

@ericapisani
Copy link
Copy Markdown
Member

@ericapisani ericapisani commented May 25, 2026

Builds on a bug fix (PY-2426/ #6392 )

Migrates the Huey integration to support the new spans-first tracing lifecycle (trace_lifecycle: "stream"), while keeping full backwards compatibility with the existing transaction-based path.

Fixes PY-2331 and #6029

The Huey integration was not properly handling task groups and chords
when enqueuing. When a group/chord is enqueued, we would attempt to access the `name`
attribute of the group/chord object for the span. They don't have one,
causing an AttributeError.

Fixes PY-2426
Fixes #6310
Groups and chords weren't introduced until Huey 3.0,
so handle that gracefully.
…s set correctly on segments in _capture_exception method
@linear-code
Copy link
Copy Markdown

linear-code Bot commented May 25, 2026

PY-2331

@ericapisani ericapisani changed the base branch from master to py-2426-fix-group-and-chord-handling May 25, 2026 15:19
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 25, 2026

Codecov Results 📊

282 passed | Total: 282 | Pass Rate: 100% | Execution Time: 43.96s

All tests are passing successfully.

❌ Patch coverage is 20.00%. Project has 14790 uncovered lines.

Files with missing lines (2)
File Patch % Lines
utils.py 53.76% ⚠️ 436 Missing and 88 partials
huey.py 14.41% ⚠️ 95 Missing

Generated by Codecov Action

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ericapisani
Copy link
Copy Markdown
Member Author

bugbot run
@sentry review

Comment thread sentry_sdk/integrations/huey.py
Comment thread tests/integrations/huey/test_huey.py
@ericapisani ericapisani marked this pull request as ready for review May 25, 2026 16:17
@ericapisani ericapisani requested a review from a team as a code owner May 25, 2026 16:17
Comment thread sentry_sdk/integrations/huey.py
…to test order of spans generated since that's stable
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 97fb86c. Configure here.

Comment thread sentry_sdk/integrations/huey.py
Comment thread sentry_sdk/utils.py
Comment on lines +2004 to +2008
# Huey also has exceptions that are raised for control flow reasons, not
# because there's an actual error. This check, similar to the aiohttp one above,
# is to prevent accidentally overwriting a status of "ok" with "error"
if HueyControlFlowExceptions and isinstance(value, HueyControlFlowExceptions):
return False
Copy link
Copy Markdown
Contributor

@alexander-alderman-webb alexander-alderman-webb May 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you break out handling of HueyControlFlowExceptions into it's own PR?

Span first changes look good and it'd be worth reviewing the other changes separately.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related issue: #6408 (comment)

Base automatically changed from py-2426-fix-group-and-chord-handling to master May 26, 2026 12:14
Comment on lines +278 to +282
assert event["transaction"] == "maybe_locked_task"
assert event["tags"]["huey_task_id"] == result.task.id
assert (
event["contexts"]["trace"]["status"] == "aborted"
if should_be_locked
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vacuous assert for unlocked status due to operator precedence in ternary expression

The assertion event["contexts"]["trace"]["status"] == "aborted" if should_be_locked else "ok" is parsed as (event[...]["status"] == "aborted") if should_be_locked else "ok". When should_be_locked=False, it asserts the string literal "ok", which is always truthy — the test never actually checks that the trace status equals "ok" for the unlocked case.

Evidence
  • Python parses X == Y if C else Z as (X == Y) if C else Z, not X == (Y if C else Z).
  • When should_be_locked=False, the ternary resolves to the string "ok", so assert "ok" is trivially true.
  • The lock_name=="lock.b" / should_be_locked=False parametrize branch therefore passes even if the integration returns the wrong status (e.g. "aborted").
  • The correct form is event[...]["status"] == ("aborted" if should_be_locked else "ok").

Identified by Warden find-bugs · YVJ-ZBD

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix attempt detected (commit 2814292)

The after code still has the same operator precedence bug: assert event[...]['status'] == 'aborted' if should_be_locked else 'ok' parses identically to the buggy version, missing the required parentheses around the ternary.

The original issue appears unresolved. Please review and try again.

Evaluated by Warden

…t huey has in earlier versions that results in more events being emitted than a later version)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants