Skip to content

Commit 4dda701

Browse files
feat(data_export): add logging for data-export-failure (#112169)
We already have logging for `data-export-success`. That success log includes the user's email, which makes it nice and easy to tell if someone's data export has succeeded (at least this far in code). But there's no equivalent log for failure. Which is what @narsaynorath and I were trying to debug earlier today and having to do all sorts of log/trace query workarounds for. Fixes LOGS-673.
1 parent a85469a commit 4dda701

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/sentry/data_export/models.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,19 @@ def email_failure(self, message: str) -> None:
169169
error_payload=self.payload,
170170
creation_date=self.date_added,
171171
)
172-
if NotificationService.has_access(self.organization, data.source):
172+
has_access = NotificationService.has_access(self.organization, data.source)
173+
logger.info(
174+
"notification.platform.data-export-failure.has_access",
175+
extra={
176+
"organization_id": self.organization.id,
177+
"data_export_id": self.id,
178+
"data_source": data.source,
179+
"has_access": has_access,
180+
"user_email": user.email,
181+
},
182+
)
183+
184+
if has_access:
173185
NotificationService(data=data).notify_async(
174186
targets=[
175187
GenericNotificationTarget(

tests/sentry/data_export/test_models.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,22 @@ def test_email_success_with_notification_platform(self) -> None:
224224
html_content
225225
)
226226

227+
@patch("sentry.data_export.models.logger")
228+
def test_email_failure_logging(self, mock_logger: MagicMock) -> None:
229+
data_export_id = self.data_export.id
230+
with self.tasks():
231+
self.data_export.email_failure("failed to export data!")
232+
mock_logger.info.assert_any_call(
233+
"notification.platform.data-export-failure.has_access",
234+
extra={
235+
"organization_id": self.organization.id,
236+
"data_export_id": data_export_id,
237+
"data_source": "data-export-failure",
238+
"has_access": False,
239+
"user_email": self.user.email,
240+
},
241+
)
242+
227243
@override_options(
228244
{"notifications.platform-rollout.internal-testing": {"data-export-failure": 1.0}}
229245
)

0 commit comments

Comments
 (0)