samplingModeField.tsx 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import styled from '@emotion/styled';
  2. import FieldGroup from 'sentry/components/forms/fieldGroup';
  3. import ExternalLink from 'sentry/components/links/externalLink';
  4. import QuestionTooltip from 'sentry/components/questionTooltip';
  5. import {SegmentedControl} from 'sentry/components/segmentedControl';
  6. import {t, tct} from 'sentry/locale';
  7. import {space} from 'sentry/styles/space';
  8. import useOrganization from 'sentry/utils/useOrganization';
  9. import {openSamplingModeSwitchModal} from 'sentry/views/settings/dynamicSampling/samplingModeSwitchModal';
  10. import {useHasDynamicSamplingWriteAccess} from 'sentry/views/settings/dynamicSampling/utils/access';
  11. interface Props {
  12. /**
  13. * The initial target rate for the automatic sampling mode.
  14. */
  15. initialTargetRate?: number;
  16. }
  17. export function SamplingModeField({initialTargetRate}: Props) {
  18. const {samplingMode} = useOrganization();
  19. const hasAccess = useHasDynamicSamplingWriteAccess();
  20. const handleSwitchMode = () => {
  21. openSamplingModeSwitchModal({
  22. samplingMode: samplingMode === 'organization' ? 'project' : 'organization',
  23. initialTargetRate,
  24. });
  25. };
  26. return (
  27. <FieldGroup
  28. disabled={!hasAccess}
  29. label={t('Sampling Mode')}
  30. help={t('The current operating mode for dynamic sampling.')}
  31. >
  32. <ControlWrapper>
  33. <SegmentedControl
  34. disabled={!hasAccess}
  35. label={t('Sampling mode')}
  36. value={samplingMode}
  37. onChange={handleSwitchMode}
  38. >
  39. <SegmentedControl.Item key="organization" textValue={t('Automatic')}>
  40. <LabelWrapper>
  41. {t('Automatic')}
  42. <QuestionTooltip
  43. isHoverable
  44. size="sm"
  45. title={tct(
  46. 'Automatic mode allows you to set a target sample rate for your organization. Sentry automatically adjusts individual project rates to boost small projects and ensure equal visibility. [link:Learn more]',
  47. {
  48. link: (
  49. <ExternalLink href="https://docs.sentry.io/product/performance/retention-priorities/" />
  50. ),
  51. }
  52. )}
  53. />
  54. </LabelWrapper>
  55. </SegmentedControl.Item>
  56. <SegmentedControl.Item key="project" textValue={t('Manual')}>
  57. <LabelWrapper>
  58. {t('Manual')}
  59. <QuestionTooltip
  60. isHoverable
  61. size="sm"
  62. title={tct(
  63. 'Manual mode allows you to set fixed sample rates for each project. [link:Learn more]',
  64. {
  65. link: (
  66. <ExternalLink href="https://docs.sentry.io/product/performance/retention-priorities/" />
  67. ),
  68. }
  69. )}
  70. />
  71. </LabelWrapper>
  72. </SegmentedControl.Item>
  73. </SegmentedControl>
  74. </ControlWrapper>
  75. </FieldGroup>
  76. );
  77. }
  78. const ControlWrapper = styled('div')`
  79. width: max-content;
  80. `;
  81. const LabelWrapper = styled('div')`
  82. display: flex;
  83. align-items: center;
  84. gap: ${space(1)};
  85. `;