projectMetrics.tsx 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import {Fragment} from 'react';
  2. import type {RouteComponentProps} from 'react-router';
  3. import * as Sentry from '@sentry/react';
  4. import {Button} from 'sentry/components/button';
  5. import ExternalLink from 'sentry/components/links/externalLink';
  6. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  7. import {t, tct} from 'sentry/locale';
  8. import type {Organization} from 'sentry/types/organization';
  9. import type {Project} from 'sentry/types/project';
  10. import {METRICS_DOCS_URL} from 'sentry/utils/metrics/constants';
  11. import {
  12. hasCustomMetricsExtractionRules,
  13. hasMetricsExtrapolationFeature,
  14. } from 'sentry/utils/metrics/features';
  15. import routeTitleGen from 'sentry/utils/routeTitle';
  16. import useOrganization from 'sentry/utils/useOrganization';
  17. import {useMetricsOnboardingSidebar} from 'sentry/views/metrics/ddmOnboarding/useMetricsOnboardingSidebar';
  18. import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader';
  19. import TextBlock from 'sentry/views/settings/components/text/textBlock';
  20. import PermissionAlert from 'sentry/views/settings/project/permissionAlert';
  21. import {CustomMetricsTable} from 'sentry/views/settings/projectMetrics/customMetricsTable';
  22. import {ExtrapolationField} from 'sentry/views/settings/projectMetrics/extrapolationField';
  23. import {MetricsExtractionRulesTable} from 'sentry/views/settings/projectMetrics/metricsExtractionRulesTable';
  24. type Props = {
  25. organization: Organization;
  26. project: Project;
  27. } & RouteComponentProps<{projectId: string}, {}>;
  28. function ProjectMetrics({project}: Props) {
  29. const organization = useOrganization();
  30. const hasExtractionRules = hasCustomMetricsExtractionRules(organization);
  31. const {activateSidebar} = useMetricsOnboardingSidebar();
  32. return (
  33. <Fragment>
  34. <SentryDocumentTitle title={routeTitleGen(t('Metrics'), project.slug, false)} />
  35. <SettingsPageHeader
  36. title={t('Metrics')}
  37. action={
  38. !hasExtractionRules && (
  39. <Button
  40. priority="primary"
  41. onClick={() => {
  42. Sentry.metrics.increment('ddm.add_custom_metric', 1, {
  43. tags: {
  44. referrer: 'settings',
  45. },
  46. });
  47. activateSidebar();
  48. }}
  49. size="sm"
  50. >
  51. {t('Add Metric')}
  52. </Button>
  53. )
  54. }
  55. />
  56. <TextBlock>
  57. {tct(
  58. `Metrics are numerical values extracted from span attributes that can help you track anything about your environment over time. To learn more about metrics, [link:read the docs].`,
  59. {
  60. link: <ExternalLink href={METRICS_DOCS_URL} />,
  61. }
  62. )}
  63. </TextBlock>
  64. {hasExtractionRules ? null : <PermissionAlert project={project} />}
  65. {hasExtractionRules && hasMetricsExtrapolationFeature(organization) ? (
  66. <ExtrapolationField project={project} />
  67. ) : null}
  68. {hasExtractionRules ? <MetricsExtractionRulesTable project={project} /> : null}
  69. {!hasExtractionRules || project.hasCustomMetrics ? (
  70. <CustomMetricsTable project={project} />
  71. ) : null}
  72. </Fragment>
  73. );
  74. }
  75. export default ProjectMetrics;