Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

feat: added exception based alerts (#1752)

Amol Umbark33d34af2a6f9
diff --git a/frontend/public/locales/en-GB/alerts.json b/frontend/public/locales/en-GB/alerts.json
index fa2d9516fe..b5c769a021 100644
--- a/frontend/public/locales/en-GB/alerts.json
+++ b/frontend/public/locales/en-GB/alerts.json
@@ -102,9 +102,11 @@
"user_tooltip_more_help": "More details on how to create alerts",
"choose_alert_type": "Choose a type for the alert:",
"metric_based_alert": "Metric based Alert",
- "metric_based_alert_desc": "Send a notification when a condition occurs in metric data",
+ "metric_based_alert_desc": "Send a notification when a condition occurs in the metric data",
"log_based_alert": "Log-based Alert",
- "log_based_alert_desc": "Send a notification when a condition occurs in logs data.",
+ "log_based_alert_desc": "Send a notification when a condition occurs in the logs data.",
"traces_based_alert": "Trace-based Alert",
- "traces_based_alert_desc": "Send a notification when a condition occurs in traces data."
+ "traces_based_alert_desc": "Send a notification when a condition occurs in the traces data.",
+ "exceptions_based_alert": "Exceptions-based Alert",
+ "exceptions_based_alert_desc": "Send a notification when a condition occurs in the exceptions data."
}
\ No newline at end of file
diff --git a/frontend/public/locales/en/alerts.json b/frontend/public/locales/en/alerts.json
index fa2d9516fe..b5c769a021 100644
--- a/frontend/public/locales/en/alerts.json
+++ b/frontend/public/locales/en/alerts.json
@@ -102,9 +102,11 @@
"user_tooltip_more_help": "More details on how to create alerts",
"choose_alert_type": "Choose a type for the alert:",
"metric_based_alert": "Metric based Alert",
- "metric_based_alert_desc": "Send a notification when a condition occurs in metric data",
+ "metric_based_alert_desc": "Send a notification when a condition occurs in the metric data",
"log_based_alert": "Log-based Alert",
- "log_based_alert_desc": "Send a notification when a condition occurs in logs data.",
+ "log_based_alert_desc": "Send a notification when a condition occurs in the logs data.",
"traces_based_alert": "Trace-based Alert",
- "traces_based_alert_desc": "Send a notification when a condition occurs in traces data."
+ "traces_based_alert_desc": "Send a notification when a condition occurs in the traces data.",
+ "exceptions_based_alert": "Exceptions-based Alert",
+ "exceptions_based_alert_desc": "Send a notification when a condition occurs in the exceptions data."
}
\ No newline at end of file
diff --git a/frontend/src/container/CreateAlertRule/SelectAlertType/index.tsx b/frontend/src/container/CreateAlertRule/SelectAlertType/index.tsx
index e892f3ac22..cc2da48727 100644
--- a/frontend/src/container/CreateAlertRule/SelectAlertType/index.tsx
+++ b/frontend/src/container/CreateAlertRule/SelectAlertType/index.tsx
@@ -1,8 +1,9 @@
+import { Row } from 'antd';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { AlertTypes } from 'types/api/alerts/alertTypes';
-import { AlertTypeCard, AlertTypeCards, SelectTypeContainer } from './styles';
+import { AlertTypeCard, SelectTypeContainer } from './styles';
interface OptionType {
title: string;
@@ -30,6 +31,11 @@ function SelectAlertType({ onSelect }: SelectAlertTypeProps): JSX.Element {
selection: AlertTypes.TRACES_BASED_ALERT,
description: t('traces_based_alert_desc'),
},
+ {
+ title: t('exceptions_based_alert'),
+ selection: AlertTypes.EXCEPTIONS_BASED_ALERT,
+ description: t('exceptions_based_alert_desc'),
+ },
];
return (
<>
@@ -50,7 +56,7 @@ function SelectAlertType({ onSelect }: SelectAlertTypeProps): JSX.Element {
return (
<SelectTypeContainer>
<h3> {t('choose_alert_type')} </h3>
- <AlertTypeCards>{renderOptions()}</AlertTypeCards>
+ <Row>{renderOptions()}</Row>
</SelectTypeContainer>
);
}
diff --git a/frontend/src/container/CreateAlertRule/SelectAlertType/styles.ts b/frontend/src/container/CreateAlertRule/SelectAlertType/styles.ts
index 9cbde02b5f..9c3323aea3 100644
--- a/frontend/src/container/CreateAlertRule/SelectAlertType/styles.ts
+++ b/frontend/src/container/CreateAlertRule/SelectAlertType/styles.ts
@@ -1,4 +1,4 @@
-import { Card, Row } from 'antd';
+import { Card } from 'antd';
import styled from 'styled-components';
export const SelectTypeContainer = styled.div`
@@ -7,12 +7,6 @@ export const SelectTypeContainer = styled.div`
}
`;
-export const AlertTypeCards = styled(Row)`
- &&& {
- flex-wrap: nowrap;
- }
-`;
-
export const AlertTypeCard = styled(Card)`
&&& {
margin: 5px;
diff --git a/frontend/src/container/CreateAlertRule/defaults.ts b/frontend/src/container/CreateAlertRule/defaults.ts
index 0172fcdff2..645d1ff454 100644
--- a/frontend/src/container/CreateAlertRule/defaults.ts
+++ b/frontend/src/container/CreateAlertRule/defaults.ts
@@ -117,8 +117,8 @@ export const traceAlertDefaults: AlertDef = {
chQueries: {
A: {
name: 'A',
- rawQuery: `SELECT \n\tcount() as value,\n\ttoStartOfInterval(timestamp, toIntervalMinute(1)) AS interval,\n\tserviceName\nFROM signoz_traces.signoz_error_index_v2\nWHERE exceptionType !='OSError'\nAND timestamp BETWEEN {{.start_datetime}} AND {{.end_datetime}}\nGROUP BY serviceName, interval;\n\n-- available variables:\n-- \t{{.start_datetime}}\n-- \t{{.end_datetime}}\n\n-- required column alias:\n-- \tvalue\n-- \tinterval`,
- query: `SELECT \n\tcount() as value,\n\ttoStartOfInterval(timestamp, toIntervalMinute(1)) AS interval,\n\tserviceName\nFROM signoz_traces.signoz_error_index_v2\nWHERE exceptionType !='OSError'\nAND timestamp BETWEEN {{.start_datetime}} AND {{.end_datetime}}\nGROUP BY serviceName, interval;\n\n-- available variables:\n-- \t{{.start_datetime}}\n-- \t{{.end_datetime}}\n\n-- required column alias:\n-- \tvalue\n-- \tinterval`,
+ rawQuery: `SELECT \n\ttoStartOfInterval(timestamp, INTERVAL 1 MINUTE) AS interval, \n\ttagMap['peer.service'] AS op_name, \n\ttoFloat64(avg(durationNano)) AS value \nFROM signoz_traces.signoz_index_v2 \nWHERE tagMap['peer.service']!='' \nAND timestamp BETWEEN {{.start_datetime}} AND {{.end_datetime}} \nGROUP BY (op_name, interval);\n\n-- available variables:\n-- \t{{.start_datetime}}\n-- \t{{.end_datetime}}\n\n-- required column alias:\n-- \tvalue\n-- \tinterval`,
+ query: `SELECT \n\ttoStartOfInterval(timestamp, INTERVAL 1 MINUTE) AS interval, \n\ttagMap['peer.service'] AS op_name, \n\ttoFloat64(avg(durationNano)) AS value \nFROM signoz_traces.signoz_index_v2 \nWHERE tagMap['peer.service']!='' \nAND timestamp BETWEEN {{.start_datetime}} AND {{.end_datetime}} \nGROUP BY (op_name, interval);\n\n-- available variables:\n-- \t{{.start_datetime}}\n-- \t{{.end_datetime}}\n\n-- required column alias:\n-- \tvalue\n-- \tinterval`,
legend: '',
disabled: false,
},
@@ -137,3 +137,50 @@ export const traceAlertDefaults: AlertDef = {
},
evalWindow: defaultEvalWindow,
};
+
+export const exceptionAlertDefaults: AlertDef = {
+ alertType: AlertTypes.EXCEPTIONS_BASED_ALERT,
+ condition: {
+ compositeMetricQuery: {
+ builderQueries: {
+ A: {
+ queryName: 'A',
+ name: 'A',
+ formulaOnly: false,
+ metricName: '',
+ tagFilters: {
+ op: 'AND',
+ items: [],
+ },
+ groupBy: [],
+ aggregateOperator: 1,
+ expression: 'A',
+ disabled: false,
+ toggleDisable: false,
+ toggleDelete: false,
+ },
+ },
+ promQueries: {},
+ chQueries: {
+ A: {
+ name: 'A',
+ rawQuery: `SELECT \n\tcount() as value,\n\ttoStartOfInterval(timestamp, toIntervalMinute(1)) AS interval,\n\tserviceName\nFROM signoz_traces.signoz_error_index_v2\nWHERE exceptionType !='OSError'\nAND timestamp BETWEEN {{.start_datetime}} AND {{.end_datetime}}\nGROUP BY serviceName, interval;\n\n-- available variables:\n-- \t{{.start_datetime}}\n-- \t{{.end_datetime}}\n\n-- required column alias:\n-- \tvalue\n-- \tinterval`,
+ query: `SELECT \n\tcount() as value,\n\ttoStartOfInterval(timestamp, toIntervalMinute(1)) AS interval,\n\tserviceName\nFROM signoz_traces.signoz_error_index_v2\nWHERE exceptionType !='OSError'\nAND timestamp BETWEEN {{.start_datetime}} AND {{.end_datetime}}\nGROUP BY serviceName, interval;\n\n-- available variables:\n-- \t{{.start_datetime}}\n-- \t{{.end_datetime}}\n\n-- required column alias:\n-- \tvalue\n-- \tinterval`,
+ legend: '',
+ disabled: false,
+ },
+ },
+ queryType: 2,
+ },
+ op: defaultCompareOp,
+ matchType: '4',
+ },
+ labels: {
+ severity: 'warning',
+ details: `${window.location.protocol}//${window.location.host}/exceptions`,
+ },
+ annotations: {
+ description: 'A new exceptions-based alert',
+ },
+ evalWindow: defaultEvalWindow,
+};
diff --git a/frontend/src/container/CreateAlertRule/index.tsx b/frontend/src/container/CreateAlertRule/index.tsx
index 101b0cae1b..ae3d21897e 100644
--- a/frontend/src/container/CreateAlertRule/index.tsx
+++ b/frontend/src/container/CreateAlertRule/index.tsx
@@ -5,6 +5,7 @@ import { AlertTypes } from 'types/api/alerts/alertTypes';
import {
alertDefaults,
+ exceptionAlertDefaults,
logAlertDefaults,
traceAlertDefaults,
} from './defaults';
@@ -27,6 +28,9 @@ function CreateRules(): JSX.Element {
case AlertTypes.TRACES_BASED_ALERT:
setInitValues(traceAlertDefaults);
break;
+ case AlertTypes.EXCEPTIONS_BASED_ALERT:
+ setInitValues(exceptionAlertDefaults);
+ break;
default:
setInitValues(alertDefaults);
}
diff --git a/frontend/src/container/FormAlertRules/QuerySection.tsx b/frontend/src/container/FormAlertRules/QuerySection.tsx
index c7b4053c6e..b5cf9574bd 100644
--- a/frontend/src/container/FormAlertRules/QuerySection.tsx
+++ b/frontend/src/container/FormAlertRules/QuerySection.tsx
@@ -292,6 +292,7 @@ function QuerySection({
switch (typ) {
case AlertTypes.TRACES_BASED_ALERT:
case AlertTypes.LOGS_BASED_ALERT:
+ case AlertTypes.EXCEPTIONS_BASED_ALERT:
return (
<Tabs
type="card"
diff --git a/frontend/src/container/FormAlertRules/utils.ts b/frontend/src/container/FormAlertRules/utils.ts
index 5c6bce3c10..9e6ec66d07 100644
--- a/frontend/src/container/FormAlertRules/utils.ts
+++ b/frontend/src/container/FormAlertRules/utils.ts
@@ -108,7 +108,6 @@ export const prepareStagedQuery = (
// convert map[string]IChQuery to IChQuery[]
if (c) {
Object.keys(c).forEach((key) => {
- console.log('c:', c[key]);
chQueryList.push({ ...c[key], name: key, rawQuery: c[key].query });
});
}
diff --git a/frontend/src/types/api/alerts/alertTypes.ts b/frontend/src/types/api/alerts/alertTypes.ts
index ed80bb5168..b8ec9f38ef 100644
--- a/frontend/src/types/api/alerts/alertTypes.ts
+++ b/frontend/src/types/api/alerts/alertTypes.ts
@@ -4,4 +4,5 @@ export enum AlertTypes {
METRICS_BASED_ALERT = 'METRIC_BASED_ALERT',
LOGS_BASED_ALERT = 'LOGS_BASED_ALERT',
TRACES_BASED_ALERT = 'TRACES_BASED_ALERT',
+ EXCEPTIONS_BASED_ALERT = 'EXCEPTIONS_BASED_ALERT',
}