|
4 | 4 | import random |
5 | 5 | from datetime import UTC, datetime |
6 | 6 | from enum import Enum |
7 | | -from typing import Any, TypedDict |
| 7 | +from typing import Any |
8 | 8 | from uuid import uuid4 |
9 | 9 |
|
10 | 10 | import jsonschema |
11 | 11 |
|
12 | 12 | from sentry import features, options |
13 | 13 | from sentry.constants import DataCategory |
14 | 14 | from sentry.eventstore.models import Event, GroupEvent |
| 15 | +from sentry.feedback.lib.types import UserReportDict |
15 | 16 | from sentry.feedback.usecases.spam_detection import is_spam, spam_detection_enabled |
16 | 17 | from sentry.issues.grouptype import FeedbackGroup |
17 | 18 | from sentry.issues.issue_occurrence import IssueEvidence, IssueOccurrence |
@@ -100,8 +101,10 @@ def fix_for_issue_platform(event_data: dict[str, Any]) -> dict[str, Any]: |
100 | 101 | """ |
101 | 102 | The issue platform has slightly different requirements than ingest for event schema, |
102 | 103 | so we need to massage the data a bit. |
| 104 | + * event["timestamp"] is converted to a UTC ISO string. |
103 | 105 | * event["tags"] is coerced to a dict. |
104 | | - * If event["user"]["email"] is missing we try to set using the feedback context. |
| 106 | + * If user or replay context is missing we try to set it using the feedback context. |
| 107 | + * level defaults to "info" and environment defaults to "production". |
105 | 108 |
|
106 | 109 | Returns: |
107 | 110 | A dict[str, Any] conforming to sentry.issues.json_schemas.EVENT_PAYLOAD_SCHEMA. |
@@ -135,22 +138,19 @@ def fix_for_issue_platform(event_data: dict[str, Any]) -> dict[str, Any]: |
135 | 138 | ret_event["request"] = event_data.get("request", {}) |
136 | 139 |
|
137 | 140 | ret_event["user"] = event_data.get("user", {}) |
| 141 | + if "name" in ret_event["user"]: |
| 142 | + del ret_event["user"]["name"] |
138 | 143 |
|
139 | | - if event_data.get("dist") is not None: |
140 | | - del event_data["dist"] |
141 | | - if event_data.get("user", {}).get("name") is not None: |
142 | | - del event_data["user"]["name"] |
143 | | - if event_data.get("user", {}).get("isStaff") is not None: |
144 | | - del event_data["user"]["isStaff"] |
| 144 | + if "isStaff" in ret_event["user"]: |
| 145 | + del ret_event["user"]["isStaff"] |
145 | 146 |
|
146 | | - if event_data.get("user", {}).get("id") is not None: |
147 | | - event_data["user"]["id"] = str(event_data["user"]["id"]) |
| 147 | + if "id" in ret_event["user"]: |
| 148 | + ret_event["user"]["id"] = str(ret_event["user"]["id"]) |
148 | 149 |
|
149 | 150 | # If no user email was provided specify the contact-email as the user-email. |
150 | 151 | feedback_obj = event_data.get("contexts", {}).get("feedback", {}) |
151 | | - contact_email = feedback_obj.get("contact_email") |
152 | | - if not ret_event["user"].get("email", ""): |
153 | | - ret_event["user"]["email"] = contact_email |
| 152 | + if "email" not in ret_event["user"]: |
| 153 | + ret_event["user"]["email"] = feedback_obj.get("contact_email", "") |
154 | 154 |
|
155 | 155 | # Force `tags` to be a dict if it's initially a list, |
156 | 156 | # since we can't guarantee its type here. |
@@ -451,16 +451,8 @@ def auto_ignore_spam_feedbacks(project, issue_fingerprint): |
451 | 451 | ########### |
452 | 452 |
|
453 | 453 |
|
454 | | -class UserReportShimDict(TypedDict): |
455 | | - name: str |
456 | | - email: str |
457 | | - comments: str |
458 | | - event_id: str |
459 | | - level: str |
460 | | - |
461 | | - |
462 | 454 | def shim_to_feedback( |
463 | | - report: UserReportShimDict, |
| 455 | + report: UserReportDict, |
464 | 456 | event: Event | GroupEvent, |
465 | 457 | project: Project, |
466 | 458 | source: FeedbackCreationSource, |
@@ -491,7 +483,7 @@ def shim_to_feedback( |
491 | 483 | "contexts": { |
492 | 484 | "feedback": { |
493 | 485 | "name": report.get("name", ""), |
494 | | - "contact_email": report["email"], |
| 486 | + "contact_email": report.get("email", ""), |
495 | 487 | "message": report["comments"], |
496 | 488 | }, |
497 | 489 | }, |
|
0 commit comments