useProjectSpanMetricsCounts.tsx 902 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import EventView from 'sentry/utils/discover/eventView';
  2. import {DiscoverDatasets} from 'sentry/utils/discover/types';
  3. import {useSpansQuery} from 'sentry/views/starfish/utils/useSpansQuery';
  4. interface Options {
  5. enabled?: boolean;
  6. projectId?: string[];
  7. query?: string;
  8. statsPeriod?: string;
  9. }
  10. export const useProjectSpanMetricCounts = ({
  11. projectId,
  12. enabled,
  13. query,
  14. statsPeriod,
  15. }: Options) => {
  16. const eventView = EventView.fromSavedQuery({
  17. name: 'Has Any Span Metrics',
  18. query,
  19. fields: ['project.id', 'count()'],
  20. projects: projectId && projectId.map(id => parseInt(id, 10)),
  21. dataset: DiscoverDatasets.SPANS_METRICS,
  22. version: 2,
  23. });
  24. eventView.statsPeriod = statsPeriod;
  25. const result = useSpansQuery<{'count()': number; 'project.id': number}[]>({
  26. eventView,
  27. initialData: [],
  28. enabled,
  29. referrer: 'span-metrics',
  30. });
  31. return result;
  32. };