index.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. import round from 'lodash/round';
  2. import {t} from 'sentry/locale';
  3. import {SamplingInnerName, SamplingRule, SamplingRuleType} from 'sentry/types/sampling';
  4. import {defined} from 'sentry/utils';
  5. // TODO: Update this link as soon as we have one for sampling
  6. export const SERVER_SIDE_SAMPLING_DOC_LINK =
  7. 'https://docs.sentry.io/product/data-management-settings/filtering/';
  8. export function getInnerNameLabel(name: SamplingInnerName | string) {
  9. switch (name) {
  10. case SamplingInnerName.TRACE_ENVIRONMENT:
  11. return t('Environment');
  12. case SamplingInnerName.TRACE_RELEASE:
  13. return t('Release');
  14. case SamplingInnerName.TRACE_USER_SEGMENT:
  15. return t('User Segment');
  16. default:
  17. return '';
  18. }
  19. }
  20. export const quantityField = 'sum(quantity)';
  21. export function isUniformRule(rule?: SamplingRule) {
  22. if (!rule) {
  23. return false;
  24. }
  25. return rule.type === SamplingRuleType.TRACE && rule.condition.inner.length === 0;
  26. }
  27. export function isValidSampleRate(sampleRate: number | undefined) {
  28. if (!defined(sampleRate)) {
  29. return false;
  30. }
  31. return !isNaN(sampleRate) && sampleRate <= 100 && sampleRate >= 0;
  32. }
  33. export function rateToPercentage(rate: number | undefined, decimalPlaces: number = 2) {
  34. if (!defined(rate)) {
  35. return rate;
  36. }
  37. return round(rate * 100, decimalPlaces);
  38. }
  39. export function percentageToRate(rate: number | undefined, decimalPlaces: number = 4) {
  40. if (!defined(rate)) {
  41. return rate;
  42. }
  43. return round(rate / 100, decimalPlaces);
  44. }