metrics.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. function WrappedPageFiltersContainer({children}: {children: React.ReactNode}) {
  13. const {isDefaultQuery} = useMetricsContext();
  14. return (
  15. <PageFiltersContainer disablePersistence={isDefaultQuery}>
  16. {children}
  17. </PageFiltersContainer>
  18. );
  19. }
  20. function Metrics() {
  21. const organization = useOrganization();
  22. useEffect(() => {
  23. trackAnalytics('ddm.page-view', {
  24. organization,
  25. });
  26. Sentry.metrics.increment('ddm.visit');
  27. // eslint-disable-next-line react-hooks/exhaustive-deps
  28. }, []);
  29. return (
  30. <SentryDocumentTitle title={t('Metrics')} orgSlug={organization.slug}>
  31. {hasCustomMetricsExtractionRules(organization) ? (
  32. <VirtualMetricsContextProvider>
  33. <MetricsContextProvider>
  34. <WrappedPageFiltersContainer>
  35. <MetricsLayout />
  36. </WrappedPageFiltersContainer>
  37. </MetricsContextProvider>
  38. </VirtualMetricsContextProvider>
  39. ) : (
  40. <MetricsContextProvider>
  41. <WrappedPageFiltersContainer>
  42. <MetricsLayout />
  43. </WrappedPageFiltersContainer>
  44. </MetricsContextProvider>
  45. )}
  46. </SentryDocumentTitle>
  47. );
  48. }
  49. export default Metrics;