useHasAnySpanMetrics.tsx 944 B

1234567891011121314151617181920212223242526272829303132333435
  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. }
  8. export const useHasAnySpanMetrics = ({projectId, enabled}: Options) => {
  9. const eventView = EventView.fromSavedQuery({
  10. name: 'Has Any Span Metrics',
  11. query: '',
  12. fields: ['count()'],
  13. projects: projectId && projectId.map(id => parseInt(id, 10)),
  14. dataset: DiscoverDatasets.SPANS_METRICS,
  15. version: 2,
  16. });
  17. eventView.statsPeriod = SAMPLE_STATS_PERIOD;
  18. const result = useSpansQuery({
  19. eventView,
  20. initialData: true,
  21. enabled,
  22. referrer: 'span-metrics',
  23. });
  24. return {
  25. ...result,
  26. hasMetrics: result?.data?.[0]?.count > 0,
  27. };
  28. };
  29. const SAMPLE_STATS_PERIOD = '10d'; // The time period in which to check for any presence of span metrics