getFormattedSpanMetric.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. import {t} from 'sentry/locale';
  2. import type {MetricsExtractionRule} from 'sentry/types/metrics';
  3. import {DEFAULT_SPAN_METRIC_ALERT_FIELD, parseField} from 'sentry/utils/metrics/mri';
  4. export function getFormattedSpanMetricField(
  5. field: string,
  6. metricExtractionRules: MetricsExtractionRule[] | null | undefined
  7. ): string {
  8. let formattedAggregate =
  9. field === DEFAULT_SPAN_METRIC_ALERT_FIELD ? t('Select a metrics to continue') : '...';
  10. const parsedField = parseField(field);
  11. if (metricExtractionRules && parsedField) {
  12. const matchedRule = metricExtractionRules.find(extractionRule =>
  13. extractionRule.conditions.some(condition =>
  14. condition.mris.includes(parsedField.mri)
  15. )
  16. );
  17. if (matchedRule) {
  18. const aggregationToDisplay =
  19. // Internally we use `sum` for counter metrics but expose `count` to the user
  20. parsedField.aggregation === 'sum' ? 'count' : parsedField.aggregation;
  21. formattedAggregate = `${aggregationToDisplay}(${matchedRule.spanAttribute})`;
  22. } else {
  23. t('Deleted metric');
  24. }
  25. }
  26. return formattedAggregate;
  27. }