Skip to content

Conversation

@cathteng
Copy link
Member

@cathteng cathteng commented Nov 7, 2025

This begins decoupling having the detector be prop drilled from action.trigger all the way down to metric alert charts.

First we add an optional project_id field to the trigger_action task that we will populate in the next PR, and also remove the need for detector in action.trigger

@cathteng cathteng requested review from a team as code owners November 7, 2025 23:02
@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Nov 7, 2025

project_id = detector.project_id
if project_id is None:
project_id = detector.project_id
Copy link
Member Author

@cathteng cathteng Nov 7, 2025

Choose a reason for hiding this comment

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

The other use for detector here is to fetch the project id and to get logs using detector.type. We can replace these with get_detector_by_event and passing in project_id to the task

Copy link
Member

Choose a reason for hiding this comment

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

Do you need to check that detector exists since it's optional now?

Copy link
Member Author

Choose a reason for hiding this comment

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

We're still passing in detector_id to the task in this PR, but yeah can check if one of them exists

@codecov
Copy link

codecov bot commented Nov 7, 2025

Codecov Report

❌ Patch coverage is 85.00000% with 3 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/sentry/workflow_engine/tasks/actions.py 75.00% 2 Missing ⚠️
src/sentry/api/endpoints/project_rule_actions.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #103000      +/-   ##
===========================================
+ Coverage   79.62%    80.66%   +1.03%     
===========================================
  Files        9137      9141       +4     
  Lines      392777    392887     +110     
  Branches    24966     24966              
===========================================
+ Hits       312768    316934    +4166     
+ Misses      79608     75552    -4056     
  Partials      401       401              

raise ValueError("Exactly one of event_id or activity_id must be provided")

if detector is None:
detector = get_detector_by_event(event_data)
Copy link
Contributor

Choose a reason for hiding this comment

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

Bug: Event type mismatch breaks activity processing.

When activity_id is provided with project_id but without detector_id, the code calls get_detector_by_event with an Activity event, but get_detector_by_event only accepts GroupEvent and will raise a TypeError. The fallback to get_detector_by_event at line 128-129 assumes the event is always a GroupEvent, but when processing activities (line 117-119), the event_data contains an Activity object instead.

Fix in Cursor Fix in Web

Copy link
Member Author

Choose a reason for hiding this comment

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

fire action shouldn't work anyway, so I think this is fine? Not sure of the status of activity notifications

Copy link
Contributor

@saponifi3d saponifi3d left a comment

Choose a reason for hiding this comment

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

overall looking good, wonder if we can remove the project_id as well, and just have everything based off of the group info.

has_reappeared: bool,
has_escalated: bool,
detector_id: int | None = None,
project_id: int | None = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

🤔 could we just get the project_id from the group? https://github.com/getsentry/sentry/blob/master/src/sentry/models/group.py#L619

That would allow us to simplify this signature / decouple another model as well. My thought process here is "we want to notify about an issue" -- so i'm just trying to pare it down to the fewest dependencies needed for that. if the action needs additional data from other areas, it can look up that information as needed per action.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes

# Set up a timeout grouping context because we want to make sure any Sentry timeout reporting
# in this scope is grouped properly.
with timeout_grouping_context(action.type):
action.trigger(event_data, detector)
Copy link
Contributor

Choose a reason for hiding this comment

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

😍

Copy link
Contributor

@saponifi3d saponifi3d left a comment

Choose a reason for hiding this comment

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

🎉

has_reappeared: bool,
has_escalated: bool,
start_timestamp_seconds: float | None = None,
project_id: int | None = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

looks like we could omit this here now too 🎉 --dependencies;

Copy link
Member Author

Choose a reason for hiding this comment

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

in the next PR!

@cathteng cathteng enabled auto-merge (squash) November 10, 2025 18:43
Copy link
Contributor

@mifu67 mifu67 left a comment

Choose a reason for hiding this comment

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

Wanted to confirm that there are currently no required changes to the charts?

@cathteng
Copy link
Member Author

@mifu67 no changes

@cathteng cathteng merged commit bfaacc5 into master Nov 10, 2025
65 checks passed
@cathteng cathteng deleted the cathy/aci/remove-detector-action-trigger branch November 10, 2025 18:52
@sentry
Copy link

sentry bot commented Nov 10, 2025

Issues attributed to commits in this pull request

This pull request was merged and Sentry observed the following issues:

@cathteng cathteng added the Trigger: Revert Add to a merged PR to revert it (skips CI) label Nov 10, 2025
@getsentry-bot
Copy link
Contributor

PR reverted: a1e05e7

getsentry-bot added a commit that referenced this pull request Nov 10, 2025
…)"

This reverts commit bfaacc5.

Co-authored-by: cathteng <70817427+cathteng@users.noreply.github.com>
Jesse-Box pushed a commit that referenced this pull request Nov 12, 2025
…)"

This reverts commit bfaacc5.

Co-authored-by: cathteng <70817427+cathteng@users.noreply.github.com>
andrewshie-sentry pushed a commit that referenced this pull request Nov 13, 2025
…)"

This reverts commit bfaacc5.

Co-authored-by: cathteng <70817427+cathteng@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components Trigger: Revert Add to a merged PR to revert it (skips CI)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants