samplingModeField.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 {Tooltip} from 'sentry/components/tooltip';
  7. import {t, tct} from 'sentry/locale';
  8. import {space} from 'sentry/styles/space';
  9. import useOrganization from 'sentry/utils/useOrganization';
  10. import {openSamplingModeSwitchModal} from 'sentry/views/settings/dynamicSampling/samplingModeSwitchModal';
  11. import {useHasDynamicSamplingWriteAccess} from 'sentry/views/settings/dynamicSampling/utils/access';
  12. interface Props {
  13. /**
  14. * The initial target rate for the automatic sampling mode.
  15. */
  16. initialTargetRate?: number;
  17. }
  18. export function SamplingModeField({initialTargetRate}: Props) {
  19. const {samplingMode} = useOrganization();
  20. const hasAccess = useHasDynamicSamplingWriteAccess();
  21. const handleSwitchMode = () => {
  22. openSamplingModeSwitchModal({
  23. samplingMode: samplingMode === 'organization' ? 'project' : 'organization',
  24. initialTargetRate,
  25. });
  26. };
  27. return (
  28. <FieldGroup
  29. disabledReason={t('You do not have permission to change this setting.')}
  30. disabled={!hasAccess}
  31. label={t('Sampling Mode')}
  32. help={t('The current operating mode for dynamic sampling.')}
  33. >
  34. <ControlWrapper>
  35. <Tooltip
  36. disabled={hasAccess}
  37. title={t('You do not have permission to change this setting.')}
  38. >
  39. <SegmentedControl
  40. disabled={!hasAccess}
  41. label={t('Sampling mode')}
  42. value={samplingMode}
  43. onChange={handleSwitchMode}
  44. >
  45. <SegmentedControl.Item key="organization" textValue={t('Automatic')}>
  46. <LabelWrapper>
  47. {t('Automatic')}
  48. <QuestionTooltip
  49. isHoverable
  50. size="sm"
  51. title={
  52. hasAccess &&
  53. tct(
  54. '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]',
  55. {
  56. link: (
  57. <ExternalLink href="https://docs.sentry.io/product/performance/retention-priorities/" />
  58. ),
  59. }
  60. )
  61. }
  62. />
  63. </LabelWrapper>
  64. </SegmentedControl.Item>
  65. <SegmentedControl.Item key="project" textValue={t('Manual')}>
  66. <LabelWrapper>
  67. {t('Manual')}
  68. <QuestionTooltip
  69. isHoverable
  70. size="sm"
  71. title={
  72. hasAccess &&
  73. tct(
  74. 'Manual mode allows you to set fixed sample rates for each project. [link:Learn more]',
  75. {
  76. link: (
  77. <ExternalLink href="https://docs.sentry.io/product/performance/retention-priorities/" />
  78. ),
  79. }
  80. )
  81. }
  82. />
  83. </LabelWrapper>
  84. </SegmentedControl.Item>
  85. </SegmentedControl>
  86. </Tooltip>
  87. </ControlWrapper>
  88. </FieldGroup>
  89. );
  90. }
  91. const ControlWrapper = styled('div')`
  92. width: max-content;
  93. `;
  94. const LabelWrapper = styled('div')`
  95. display: flex;
  96. align-items: center;
  97. gap: ${space(1)};
  98. `;