Skip to content

Commit 10ba47f

Browse files
authored
fix(issues): add first-seen time from group to event (#95805)
This is part of a larger project to fix the Issues search page's sorting by issue age. Currently, the issues page searches by Events — which means that sorting by issue age is actually sorting by which events occurred earliest _within the selected time range_. This looks a bit silly, since we display the actual age in the UI. First step here is adding the group's first-seen time to the events. After this, we'll expose the column to Snuba and then hook it into the search strategy.
1 parent fc69657 commit 10ba47f

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/sentry/eventstream/snuba.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ def insert(
175175
{
176176
"group_id": event.group_id,
177177
"group_ids": [group.id for group in getattr(event, "groups", [])],
178+
"group_first_seen": (
179+
json.datetime_to_str(event.group.first_seen)
180+
if event.group is not None
181+
else None
182+
),
178183
"event_id": event.event_id,
179184
"organization_id": project.organization_id,
180185
"project_id": event.project_id,

src/sentry/snuba/events.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,3 +863,12 @@ class Columns(Enum):
863863
issue_platform_name=None,
864864
alias="timestamp_ms",
865865
)
866+
867+
GROUP_FIRST_SEEN = Column(
868+
group_name="events.group_first_seen",
869+
event_name="group_first_seen",
870+
transaction_name=None,
871+
discover_name=None,
872+
issue_platform_name="group_first_seen",
873+
alias="group_first_seen",
874+
)

tests/sentry/eventstream/test_eventstream.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,10 +253,15 @@ def test_groupevent_occurrence_passed(self, mock_eventstream_insert: MagicMock)
253253
assert payload1["occurrence_id"] == occurrence_data["id"]
254254
assert payload1["occurrence_data"] == occurrence_data_no_evidence
255255
assert payload1["group_id"] == self.group.id
256+
assert payload1["group_first_seen"] == json.datetime_to_str(self.group.first_seen)
256257

257258
query = Query(
258259
match=Entity(EntityKey.IssuePlatform.value),
259-
select=[Column("event_id"), Column("group_id"), Column("occurrence_id")],
260+
select=[
261+
Column("event_id"),
262+
Column("group_id"),
263+
Column("occurrence_id"),
264+
],
260265
where=[
261266
Condition(Column("timestamp"), Op.GTE, now - timedelta(days=1)),
262267
Condition(Column("timestamp"), Op.LT, now + timedelta(days=1)),

0 commit comments

Comments
 (0)