123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245 |
- import {CHART_PALETTE} from 'sentry/constants/chartPalette';
- import {t} from 'sentry/locale';
- import {DiscoverDatasets} from 'sentry/utils/discover/types';
- import {MutableSearch} from 'sentry/utils/tokenizeSearch';
- import Chart, {ChartType} from 'sentry/views/insights/common/components/chart';
- import ChartPanel from 'sentry/views/insights/common/components/chartPanel';
- import {
- useSpanIndexedSeries,
- useSpanMetricsSeries,
- } from 'sentry/views/insights/common/queries/useDiscoverSeries';
- import {ALERTS} from 'sentry/views/insights/llmMonitoring/alerts';
- interface TotalTokensUsedChartProps {
- groupId?: string;
- }
- export function EAPTotalTokensUsedChart({groupId}: TotalTokensUsedChartProps) {
- const aggregate = 'sum(ai.total_tokens.used)';
- let query = 'span.category:"ai"';
- if (groupId) {
- query = `${query} span.ai.pipeline.group:"${groupId}"`;
- }
- const {data, isPending, error} = useSpanIndexedSeries(
- {
- yAxis: [aggregate],
- search: new MutableSearch(query),
- },
- 'api.ai-pipelines.view',
- DiscoverDatasets.SPANS_EAP
- );
- return (
- <ChartPanel
- title={t('Total tokens used')}
- alertConfigs={[{...ALERTS.tokensUsed, query}]}
- >
- <Chart
- height={200}
- grid={{
- left: '4px',
- right: '0',
- top: '8px',
- bottom: '0',
- }}
- data={[data[aggregate]]}
- loading={isPending}
- error={error}
- type={ChartType.LINE}
- chartColors={[CHART_PALETTE[2][0]]}
- />
- </ChartPanel>
- );
- }
- export function TotalTokensUsedChart({groupId}: TotalTokensUsedChartProps) {
- const aggregate = 'sum(ai.total_tokens.used)';
- let query = 'span.category:"ai"';
- if (groupId) {
- query = `${query} span.ai.pipeline.group:"${groupId}"`;
- }
- const {data, isPending, error} = useSpanMetricsSeries(
- {
- yAxis: [aggregate],
- search: new MutableSearch(query),
- },
- 'api.ai-pipelines.view'
- );
- return (
- <ChartPanel
- title={t('Total tokens used')}
- alertConfigs={[{...ALERTS.tokensUsed, query}]}
- >
- <Chart
- height={200}
- grid={{
- left: '4px',
- right: '0',
- top: '8px',
- bottom: '0',
- }}
- data={[data[aggregate]]}
- loading={isPending}
- error={error}
- type={ChartType.LINE}
- chartColors={[CHART_PALETTE[2][0]]}
- />
- </ChartPanel>
- );
- }
- interface NumberOfPipelinesChartProps {
- groupId?: string;
- }
- export function EAPNumberOfPipelinesChart({groupId}: NumberOfPipelinesChartProps) {
- const aggregate = 'count()';
- let query = 'span.category:"ai.pipeline"';
- if (groupId) {
- query = `${query} span.group:"${groupId}"`;
- }
- const {data, isPending, error} = useSpanIndexedSeries(
- {
- yAxis: [aggregate],
- search: new MutableSearch(query),
- },
- 'api.ai-pipelines-eap.view',
- DiscoverDatasets.SPANS_EAP
- );
- return (
- <ChartPanel title={t('Number of AI pipelines')}>
- <Chart
- height={200}
- grid={{
- left: '4px',
- right: '0',
- top: '8px',
- bottom: '0',
- }}
- data={[data[aggregate]]}
- loading={isPending}
- error={error}
- type={ChartType.LINE}
- chartColors={[CHART_PALETTE[2][1]]}
- />
- </ChartPanel>
- );
- }
- export function NumberOfPipelinesChart({groupId}: NumberOfPipelinesChartProps) {
- const aggregate = 'count()';
- let query = 'span.category:"ai.pipeline"';
- if (groupId) {
- query = `${query} span.group:"${groupId}"`;
- }
- const {data, isPending, error} = useSpanMetricsSeries(
- {
- yAxis: [aggregate],
- search: new MutableSearch(query),
- },
- 'api.ai-pipelines.view'
- );
- return (
- <ChartPanel title={t('Number of AI pipelines')}>
- <Chart
- height={200}
- grid={{
- left: '4px',
- right: '0',
- top: '8px',
- bottom: '0',
- }}
- data={[data[aggregate]]}
- loading={isPending}
- error={error}
- type={ChartType.LINE}
- chartColors={[CHART_PALETTE[2][1]]}
- />
- </ChartPanel>
- );
- }
- interface PipelineDurationChartProps {
- groupId?: string;
- }
- export function EAPPipelineDurationChart({groupId}: PipelineDurationChartProps) {
- const aggregate = 'avg(span.duration)';
- let query = 'span.category:"ai.pipeline"';
- if (groupId) {
- query = `${query} span.group:"${groupId}"`;
- }
- const {data, isPending, error} = useSpanIndexedSeries(
- {
- yAxis: [aggregate],
- search: new MutableSearch(query),
- },
- 'api.ai-pipelines-eap.view',
- DiscoverDatasets.SPANS_EAP
- );
- return (
- <ChartPanel
- title={t('Pipeline Duration')}
- alertConfigs={[{...ALERTS.duration, query}]}
- >
- <Chart
- height={200}
- grid={{
- left: '4px',
- right: '0',
- top: '8px',
- bottom: '0',
- }}
- data={[data[aggregate]]}
- loading={isPending}
- error={error}
- type={ChartType.LINE}
- chartColors={[CHART_PALETTE[2][2]]}
- />
- </ChartPanel>
- );
- }
- export function PipelineDurationChart({groupId}: PipelineDurationChartProps) {
- const aggregate = 'avg(span.duration)';
- let query = 'span.category:"ai.pipeline"';
- if (groupId) {
- query = `${query} span.group:"${groupId}"`;
- }
- const {data, isPending, error} = useSpanMetricsSeries(
- {
- yAxis: [aggregate],
- search: new MutableSearch(query),
- },
- 'api.ai-pipelines.view'
- );
- return (
- <ChartPanel
- title={t('Pipeline Duration')}
- alertConfigs={[{...ALERTS.duration, query}]}
- >
- <Chart
- height={200}
- grid={{
- left: '4px',
- right: '0',
- top: '8px',
- bottom: '0',
- }}
- data={[data[aggregate]]}
- loading={isPending}
- error={error}
- type={ChartType.LINE}
- chartColors={[CHART_PALETTE[2][2]]}
- />
- </ChartPanel>
- );
- }
|