Browse Source

feat(issue-platform): add custom metadata for feedback issue types (#57512)

In our Feedback index page, we want to be able to quickly list all of
the feedback messages / contact emails. In order to facilitate this, we
want to add these two fields to our Issue metadata. It would be annoying
to have to query the issue, and then the event, to display the relevant
information on index listing.

It seems like the "right" way to do this is to create a new event type,
and define at `extract_metadata` function in `src/sentry/eventtypes`.

It seems like we'd have to go around in _a lot_ of different places to
update logic that currently checks for "generic" events, as there are
lots of places where we'll try and do error processing if the event type
isn't recognized.

We'd also have to update our kafka schemas in order to allow a new event
type enum.

In order to unblock prototyping, I'm suggesting to add this line which
will populate our metadata based on the GroupType of the occurrence.

The other long-term alternative is to define an `extract_metadata`
function on each GroupType and call that here, where the base is the
default generic event metadata extraction. This would allow us to have
the events still be generic, but define the metadata per grouptype.

For now, i've just added a line with a comment.


ref: https://github.com/getsentry/team-replay/issues/226
Josh Ferge 1 year ago
parent
commit
5fef8b7b6e
2 changed files with 27 additions and 1 deletions
  1. 8 1
      src/sentry/issues/ingest.py
  2. 19 0
      tests/sentry/issues/test_ingest.py

+ 8 - 1
src/sentry/issues/ingest.py

@@ -21,7 +21,7 @@ from sentry.event_manager import (
     get_event_type,
 )
 from sentry.eventstore.models import Event, GroupEvent, augment_message_with_occurrence
-from sentry.issues.grouptype import should_create_group
+from sentry.issues.grouptype import FeedbackGroup, should_create_group
 from sentry.issues.issue_occurrence import IssueOccurrence, IssueOccurrenceData
 from sentry.models.grouphash import GroupHash
 from sentry.models.release import Release
@@ -131,6 +131,13 @@ def materialize_metadata(occurrence: IssueOccurrence, event: Event) -> Occurrenc
     event_metadata["title"] = occurrence.issue_title
     event_metadata["value"] = occurrence.subtitle
 
+    if occurrence.type == FeedbackGroup:
+        # TODO: Should feedbacks be their own event type, so above call to event.get_event_medata
+        # could populate this instead?
+        # Or potentially, could add a method to GroupType called get_metadata
+        event_metadata["contact_email"] = occurrence.evidence_data.get("contact_email")
+        event_metadata["message"] = occurrence.evidence_data.get("message")
+
     return {
         "type": event_type.key,
         "title": occurrence.issue_title,

+ 19 - 0
tests/sentry/issues/test_ingest.py

@@ -7,6 +7,7 @@ from unittest.mock import patch
 from sentry.constants import LOG_LEVELS_MAP
 from sentry.issues.grouptype import (
     ErrorGroupType,
+    FeedbackGroup,
     GroupCategory,
     GroupType,
     GroupTypeRegistry,
@@ -323,6 +324,24 @@ class MaterializeMetadataTest(OccurrenceTestMixin, TestCase):
             "dogs": "are great",
         }
 
+    def test_populates_feedback_metadata(self) -> None:
+        occurrence = self.build_occurrence(
+            type=FeedbackGroup.type_id,
+            evidence_data={"contact_email": "test@test.com", "message": "test"},
+        )
+        event = self.store_event(data={}, project_id=self.project.id)
+        event.data.setdefault("metadata", {})
+        event.data["metadata"]["dogs"] = "are great"  # should not get clobbered
+
+        materialized = materialize_metadata(occurrence, event)
+        assert materialized["metadata"] == {
+            "title": occurrence.issue_title,
+            "value": occurrence.subtitle,
+            "dogs": "are great",
+            "contact_email": "test@test.com",
+            "message": "test",
+        }
+
 
 @region_silo_test
 class SaveIssueOccurrenceToEventstreamTest(OccurrenceTestMixin, TestCase):