llmMonitoringCharts.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import {CHART_PALETTE} from 'sentry/constants/chartPalette';
  2. import {t} from 'sentry/locale';
  3. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  4. import Chart, {ChartType} from 'sentry/views/starfish/components/chart';
  5. import ChartPanel from 'sentry/views/starfish/components/chartPanel';
  6. import {useSpanMetricsSeries} from 'sentry/views/starfish/queries/useDiscoverSeries';
  7. interface TotalTokensUsedChartProps {
  8. groupId?: string;
  9. }
  10. export function TotalTokensUsedChart({groupId}: TotalTokensUsedChartProps) {
  11. const aggregate = 'sum(ai.total_tokens.used)';
  12. let query = 'span.category:"ai"';
  13. if (groupId) {
  14. query = `${query} span.ai.pipeline.group:"${groupId}"`;
  15. }
  16. const {data, isLoading, error} = useSpanMetricsSeries(
  17. {
  18. yAxis: [aggregate],
  19. search: new MutableSearch(query),
  20. },
  21. 'api.ai-pipelines.view'
  22. );
  23. return (
  24. <ChartPanel title={t('Total tokens used')}>
  25. <Chart
  26. height={200}
  27. grid={{
  28. left: '4px',
  29. right: '0',
  30. top: '8px',
  31. bottom: '0',
  32. }}
  33. data={[data[aggregate]]}
  34. loading={isLoading}
  35. error={error}
  36. type={ChartType.LINE}
  37. chartColors={[CHART_PALETTE[2][0]]}
  38. />
  39. </ChartPanel>
  40. );
  41. }
  42. interface NumberOfPipelinesChartProps {
  43. groupId?: string;
  44. }
  45. export function NumberOfPipelinesChart({groupId}: NumberOfPipelinesChartProps) {
  46. const aggregate = 'count()';
  47. let query = 'span.category:"ai.pipeline"';
  48. if (groupId) {
  49. query = `${query} span.group:"${groupId}"`;
  50. }
  51. const {data, isLoading, error} = useSpanMetricsSeries(
  52. {
  53. yAxis: [aggregate],
  54. search: new MutableSearch(query),
  55. },
  56. 'api.ai-pipelines.view'
  57. );
  58. return (
  59. <ChartPanel title={t('Number of AI pipelines')}>
  60. <Chart
  61. height={200}
  62. grid={{
  63. left: '4px',
  64. right: '0',
  65. top: '8px',
  66. bottom: '0',
  67. }}
  68. data={[data[aggregate]]}
  69. loading={isLoading}
  70. error={error}
  71. type={ChartType.LINE}
  72. chartColors={[CHART_PALETTE[2][1]]}
  73. />
  74. </ChartPanel>
  75. );
  76. }
  77. interface PipelineDurationChartProps {
  78. groupId?: string;
  79. }
  80. export function PipelineDurationChart({groupId}: PipelineDurationChartProps) {
  81. const aggregate = 'avg(span.duration)';
  82. let query = 'span.category:"ai.pipeline"';
  83. if (groupId) {
  84. query = `${query} span.group:"${groupId}"`;
  85. }
  86. const {data, isLoading, error} = useSpanMetricsSeries(
  87. {
  88. yAxis: [aggregate],
  89. search: new MutableSearch(query),
  90. },
  91. 'api.ai-pipelines.view'
  92. );
  93. return (
  94. <ChartPanel title={t('Pipeline Duration')}>
  95. <Chart
  96. height={200}
  97. grid={{
  98. left: '4px',
  99. right: '0',
  100. top: '8px',
  101. bottom: '0',
  102. }}
  103. data={[data[aggregate]]}
  104. loading={isLoading}
  105. error={error}
  106. type={ChartType.LINE}
  107. chartColors={[CHART_PALETTE[2][2]]}
  108. />
  109. </ChartPanel>
  110. );
  111. }