metrics.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import {useEffect} from 'react';
  2. import * as Sentry from '@sentry/react';
  3. import PageFiltersContainer from 'sentry/components/organizations/pageFilters/container';
  4. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  5. import {t} from 'sentry/locale';
  6. import {trackAnalytics} from 'sentry/utils/analytics';
  7. import {hasCustomMetricsExtractionRules} from 'sentry/utils/metrics/features';
  8. import {VirtualMetricsContextProvider} from 'sentry/utils/metrics/virtualMetricsContext';
  9. import useOrganization from 'sentry/utils/useOrganization';
  10. import {MetricsContextProvider, useMetricsContext} from 'sentry/views/metrics/context';
  11. import {MetricsLayout} from 'sentry/views/metrics/layout';
  12. import {useOptInModal} from 'sentry/views/metrics/optInModal';
  13. function WrappedPageFiltersContainer({children}: {children: React.ReactNode}) {
  14. const {isDefaultQuery} = useMetricsContext();
  15. return (
  16. <PageFiltersContainer disablePersistence={isDefaultQuery}>
  17. {children}
  18. </PageFiltersContainer>
  19. );
  20. }
  21. function Metrics() {
  22. const organization = useOrganization();
  23. useOptInModal();
  24. useEffect(() => {
  25. trackAnalytics('ddm.page-view', {
  26. organization,
  27. });
  28. Sentry.metrics.increment('ddm.visit');
  29. // eslint-disable-next-line react-hooks/exhaustive-deps
  30. }, []);
  31. return (
  32. <SentryDocumentTitle title={t('Metrics')} orgSlug={organization.slug}>
  33. {hasCustomMetricsExtractionRules(organization) ? (
  34. <VirtualMetricsContextProvider>
  35. <MetricsContextProvider>
  36. <WrappedPageFiltersContainer>
  37. <MetricsLayout />
  38. </WrappedPageFiltersContainer>
  39. </MetricsContextProvider>
  40. </VirtualMetricsContextProvider>
  41. ) : (
  42. <MetricsContextProvider>
  43. <WrappedPageFiltersContainer>
  44. <MetricsLayout />
  45. </WrappedPageFiltersContainer>
  46. </MetricsContextProvider>
  47. )}
  48. </SentryDocumentTitle>
  49. );
  50. }
  51. export default Metrics;