samplingSDKClientRateChangeAlert.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import {useEffect} from 'react';
  2. import Alert from 'sentry/components/alert';
  3. import Button from 'sentry/components/button';
  4. import {t} from 'sentry/locale';
  5. import {Organization, Project, SeriesApi} from 'sentry/types';
  6. import {defined} from 'sentry/utils';
  7. import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
  8. import {RecommendedStepsModalProps} from './modals/recommendedStepsModal';
  9. import {getClientSampleRates, SERVER_SIDE_SAMPLING_DOC_LINK} from './utils';
  10. type Props = Pick<RecommendedStepsModalProps, 'onReadDocs'> & {
  11. organization: Organization;
  12. projectId: Project['id'];
  13. projectStats?: SeriesApi;
  14. };
  15. export function SamplingSDKClientRateChangeAlert({
  16. projectStats,
  17. onReadDocs,
  18. organization,
  19. projectId,
  20. }: Props) {
  21. const {diff: clientSamplingDiff} = getClientSampleRates(projectStats);
  22. const recommendChangingClientSdk =
  23. defined(clientSamplingDiff) && clientSamplingDiff >= 50;
  24. useEffect(() => {
  25. if (!recommendChangingClientSdk) {
  26. return;
  27. }
  28. trackAdvancedAnalyticsEvent('sampling.sdk.client.rate.change.alert', {
  29. organization,
  30. project_id: projectId,
  31. });
  32. }, [recommendChangingClientSdk, organization, projectId]);
  33. if (!recommendChangingClientSdk) {
  34. return null;
  35. }
  36. return (
  37. <Alert
  38. type="info"
  39. showIcon
  40. trailingItems={
  41. <Button
  42. href={`${SERVER_SIDE_SAMPLING_DOC_LINK}getting-started/#4-increase-your-sdk-transaction-sample-rate`}
  43. onClick={onReadDocs}
  44. priority="link"
  45. borderless
  46. external
  47. >
  48. {t('Learn More')}
  49. </Button>
  50. }
  51. >
  52. {t(
  53. 'To allow more transactions to be processed, we suggest changing your client(SDK) sample rate.'
  54. )}
  55. </Alert>
  56. );
  57. }