Skip to content

Commit dfafe96

Browse files
feat(insights): Adds create alert buttons to Total tokens used and Pipeline duration charts. Also fix bug with isForLlmMetric prop (#77031)
Adds create alert buttons to Total tokens used and Pipeline duration charts. Also fixes a bug with the `isForLlmMetric` prop not properly picking up aggregates belonging to the LLM Monitoring alert category. Didn't add an alert to the `Number of AI pipelines` chart yet, because that chart uses `count()` on the spans dataset, but `count()` in discover `metrics` points to the transactions dataset. Will update this later.
1 parent fd20719 commit dfafe96

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

static/app/views/alerts/rules/metric/ruleForm.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,10 @@ class RuleFormContainer extends DeprecatedAsyncComponent<Props, State> {
12631263
isEditing={Boolean(ruleId)}
12641264
isErrorMigration={showErrorMigrationWarning}
12651265
isExtrapolatedChartData={isExtrapolatedChartData}
1266-
isForLlmMetric={aggregate.includes(':spans/ai.')}
1266+
isForLlmMetric={[
1267+
'sum(ai.total_tokens.used)',
1268+
'sum(ai.total_cost)',
1269+
].includes(aggregate)}
12671270
isTransactionMigration={isMigration && !showErrorMigrationWarning}
12681271
monitorType={monitorType}
12691272
onComparisonDeltaChange={value =>

static/app/views/alerts/rules/metric/utils/isInsightsMetricAlert.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export const INSIGHTS_METRICS = [
2424
'g:spans/mobile.total_frames@none',
2525
'g:spans/mobile.frozen_frames@none',
2626
'g:spans/mobile.slow_frames@none',
27+
'c:spans/ai.total_tokens.used@none',
28+
'c:spans/ai.total_cost@usd',
2729
];
2830

2931
export const isInsightsMetricAlert = (aggregate: string) => {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type {AlertConfig} from 'sentry/views/insights/common/components/chartPanel';
2+
import {SpanMetricsField} from 'sentry/views/insights/types';
3+
4+
export const ALERTS: Record<string, AlertConfig> = {
5+
spm: {
6+
aggregate: 'spm()',
7+
},
8+
duration: {
9+
aggregate: 'avg(d:spans/duration@millisecond)',
10+
},
11+
tokensUsed: {
12+
aggregate: `sum(c:spans/${SpanMetricsField.AI_TOTAL_TOKENS_USED}@none)`,
13+
},
14+
};

static/app/views/insights/llmMonitoring/components/charts/llmMonitoringCharts.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {MutableSearch} from 'sentry/utils/tokenizeSearch';
44
import Chart, {ChartType} from 'sentry/views/insights/common/components/chart';
55
import ChartPanel from 'sentry/views/insights/common/components/chartPanel';
66
import {useSpanMetricsSeries} from 'sentry/views/insights/common/queries/useDiscoverSeries';
7+
import {ALERTS} from 'sentry/views/insights/llmMonitoring/alerts';
78

89
interface TotalTokensUsedChartProps {
910
groupId?: string;
@@ -25,7 +26,10 @@ export function TotalTokensUsedChart({groupId}: TotalTokensUsedChartProps) {
2526
);
2627

2728
return (
28-
<ChartPanel title={t('Total tokens used')}>
29+
<ChartPanel
30+
title={t('Total tokens used')}
31+
alertConfigs={[{...ALERTS.tokensUsed, query}]}
32+
>
2933
<Chart
3034
height={200}
3135
grid={{
@@ -100,7 +104,10 @@ export function PipelineDurationChart({groupId}: PipelineDurationChartProps) {
100104
);
101105

102106
return (
103-
<ChartPanel title={t('Pipeline Duration')}>
107+
<ChartPanel
108+
title={t('Pipeline Duration')}
109+
alertConfigs={[{...ALERTS.duration, query}]}
110+
>
104111
<Chart
105112
height={200}
106113
grid={{

0 commit comments

Comments
 (0)