llmMonitoringSection.tsx 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import Alert from 'sentry/components/alert';
  2. import {LinkButton} from 'sentry/components/button';
  3. import ButtonBar from 'sentry/components/buttonBar';
  4. import {EventDataSection} from 'sentry/components/events/eventDataSection';
  5. import {IconOpen} from 'sentry/icons';
  6. import {t} from 'sentry/locale';
  7. import type {Event} from 'sentry/types/event';
  8. import type {Organization} from 'sentry/types/organization';
  9. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  10. import * as ModuleLayout from 'sentry/views/insights/common/components/moduleLayout';
  11. import {useSpansIndexed} from 'sentry/views/insights/common/queries/useDiscover';
  12. import {useModuleURL} from 'sentry/views/insights/common/utils/useModuleURL';
  13. import {
  14. NumberOfPipelinesChart,
  15. TotalTokensUsedChart,
  16. } from 'sentry/views/insights/llmMonitoring/components/charts/llmMonitoringCharts';
  17. import {SpanIndexedField, type SpanIndexedResponse} from 'sentry/views/insights/types';
  18. interface Props {
  19. event: Event;
  20. organization: Organization;
  21. }
  22. export default function LLMMonitoringSection({event}: Props) {
  23. const traceId = event.contexts.trace?.trace_id;
  24. const spanId = event.contexts.trace?.span_id;
  25. const {data, error, isLoading} = useSpansIndexed(
  26. {
  27. limit: 1,
  28. fields: [SpanIndexedField.SPAN_AI_PIPELINE_GROUP],
  29. search: new MutableSearch(`trace:${traceId} id:"${spanId}"`),
  30. },
  31. 'api.ai-pipelines.view'
  32. );
  33. const moduleUrl = useModuleURL('ai');
  34. const aiPipelineGroup =
  35. data && (data[0] as SpanIndexedResponse)?.[SpanIndexedField.SPAN_AI_PIPELINE_GROUP];
  36. const actions = (
  37. <ButtonBar gap={1}>
  38. <LinkButton size="xs" icon={<IconOpen />} to={moduleUrl}>
  39. {t('View in LLM Monitoring')}
  40. </LinkButton>
  41. </ButtonBar>
  42. );
  43. return (
  44. <EventDataSection
  45. title={t('LLM monitoring')}
  46. type="llm-monitoring"
  47. help={t('Charts showing how many tokens are being used')}
  48. actions={actions}
  49. >
  50. {error ? (
  51. <Alert type="error" showIcon>
  52. {'' + error}
  53. </Alert>
  54. ) : isLoading ? (
  55. 'loading'
  56. ) : (
  57. <ModuleLayout.Layout>
  58. <ModuleLayout.Half>
  59. <TotalTokensUsedChart groupId={aiPipelineGroup} />
  60. </ModuleLayout.Half>
  61. <ModuleLayout.Half>
  62. <NumberOfPipelinesChart groupId={aiPipelineGroup} />
  63. </ModuleLayout.Half>
  64. </ModuleLayout.Layout>
  65. )}
  66. </EventDataSection>
  67. );
  68. }