-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
chore(aci): add alert creation + success analytics #104403
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,12 +1,31 @@ | ||
| import type {MetricRule} from 'sentry/views/alerts/rules/metric/types'; | ||
| import type {UptimeMonitorMode} from 'sentry/views/alerts/rules/uptime/types'; | ||
| import type {MonitorConfig} from 'sentry/views/insights/crons/types'; | ||
|
|
||
| export type AlertsEventParameters = { | ||
| 'anomaly-detection.feedback-submitted': { | ||
| choice_selected: boolean; | ||
| incident_id: string; | ||
| }; | ||
| 'cron_monitor.created': { | ||
| cron_schedule_type: MonitorConfig['schedule_type']; | ||
| }; | ||
| 'issue_alert_rule.created': Record<string, unknown>; | ||
| 'metric_alert_rule.created': { | ||
| aggregate: MetricRule['aggregate']; | ||
| dataset: MetricRule['dataset']; | ||
| }; | ||
| 'uptime_monitor.created': { | ||
| uptime_mode: UptimeMonitorMode; | ||
| }; | ||
| }; | ||
|
|
||
| type AlertsEventKey = keyof AlertsEventParameters; | ||
|
|
||
| export const alertsEventMap: Record<AlertsEventKey, string | null> = { | ||
| 'anomaly-detection.feedback-submitted': 'Anomaly Detection Feedback Submitted', | ||
| 'issue_alert_rule.created': 'Issue Alert Rule Created', | ||
| 'metric_alert_rule.created': 'Metric Alert Rule Created', | ||
| 'cron_monitor.created': 'Cron Monitor Created', | ||
| 'uptime_monitor.created': 'Uptime Monitor Created', | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,7 @@ import {t} from 'sentry/locale'; | |
| import type { | ||
| BaseDetectorUpdatePayload, | ||
| Detector, | ||
| DetectorType, | ||
| } from 'sentry/types/workflowEngine/detectors'; | ||
| import {trackAnalytics} from 'sentry/utils/analytics'; | ||
| import {useNavigate} from 'sentry/utils/useNavigate'; | ||
|
|
@@ -15,6 +16,10 @@ import {useCreateDetector} from 'sentry/views/detectors/hooks'; | |
| import {makeMonitorDetailsPathname} from 'sentry/views/detectors/pathnames'; | ||
|
|
||
| interface UseCreateDetectorFormSubmitOptions<TFormData, TUpdatePayload> { | ||
| /** | ||
| * Detector type for analytics tracking when validation fails | ||
| */ | ||
| detectorType: DetectorType; | ||
| /** | ||
| * Function to transform form data to API payload | ||
| */ | ||
|
|
@@ -27,6 +32,7 @@ export function useCreateDetectorFormSubmit< | |
| TFormData extends Data, | ||
| TUpdatePayload extends BaseDetectorUpdatePayload, | ||
| >({ | ||
| detectorType, | ||
| formDataToEndpointPayload, | ||
| onError, | ||
| onSuccess, | ||
|
|
@@ -39,16 +45,23 @@ export function useCreateDetectorFormSubmit< | |
| async (data, onSubmitSuccess, onSubmitError, _, formModel) => { | ||
| const isValid = formModel.validateForm(); | ||
| if (!isValid) { | ||
| trackAnalytics('monitor.created', { | ||
| organization, | ||
| detector_type: detectorType, | ||
| success: false, | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| const payload = formDataToEndpointPayload(data as TFormData); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Payload creation moved outside try-catch loses error handlingThe |
||
|
|
||
| try { | ||
| const payload = formDataToEndpointPayload(data as TFormData); | ||
| const resultDetector = await createDetector(payload); | ||
|
|
||
| trackAnalytics('monitor.created', { | ||
| organization, | ||
| ...getDetectorAnalyticsPayload(resultDetector), | ||
| success: true, | ||
| }); | ||
|
|
||
| addSuccessMessage(t('Monitor created successfully')); | ||
|
|
@@ -61,6 +74,12 @@ export function useCreateDetectorFormSubmit< | |
|
|
||
| onSubmitSuccess?.(resultDetector); | ||
| } catch (error) { | ||
| trackAnalytics('monitor.created', { | ||
| organization, | ||
| detector_type: payload.type, | ||
| success: false, | ||
| }); | ||
|
|
||
| addErrorMessage(t('Unable to create monitor')); | ||
|
|
||
| if (onError) { | ||
|
|
@@ -71,6 +90,7 @@ export function useCreateDetectorFormSubmit< | |
| } | ||
| }, | ||
| [ | ||
| detectorType, | ||
| formDataToEndpointPayload, | ||
| createDetector, | ||
| organization, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't figure out another typing solution for
issue_alert_rule.createdwhere there aren't additional parametersThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think this should be the correct way