utils.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import type {Location} from 'history';
  2. import type {Organization} from 'sentry/types';
  3. import type EventView from 'sentry/utils/discover/eventView';
  4. import type {
  5. AggregationKeyWithAlias,
  6. QueryFieldValue,
  7. } from 'sentry/utils/discover/fields';
  8. import type {MetricsCardinalityContext} from 'sentry/utils/performance/contexts/metricsCardinality';
  9. import type {MetricsEnhancedPerformanceDataContext} from 'sentry/utils/performance/contexts/metricsEnhancedPerformanceDataContext';
  10. import type {MetricsEnhancedSettingContext} from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
  11. import {canUseMetricsData} from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
  12. import {decodeScalar} from 'sentry/utils/queryString';
  13. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  14. import {getMEPQueryParams} from 'sentry/views/performance/landing/widgets/utils';
  15. export function canUseTransactionMetricsData(
  16. organization: Organization,
  17. mepDataContext: MetricsEnhancedPerformanceDataContext
  18. ) {
  19. const isUsingMetrics = canUseMetricsData(organization);
  20. if (!isUsingMetrics) {
  21. return false;
  22. }
  23. if (mepDataContext.isMetricsData === false) {
  24. return false;
  25. }
  26. return true;
  27. }
  28. export function getTransactionMEPParamsIfApplicable(
  29. mepSetting: MetricsEnhancedSettingContext,
  30. mepCardinality: MetricsCardinalityContext,
  31. organization: Organization
  32. ) {
  33. if (!canUseMetricsData(organization)) {
  34. return undefined;
  35. }
  36. if (mepCardinality.outcome?.forceTransactionsOnly) {
  37. return undefined;
  38. }
  39. return getMEPQueryParams(mepSetting, true);
  40. }
  41. export function getUnfilteredTotalsEventView(
  42. eventView: EventView,
  43. location: Location,
  44. fields: AggregationKeyWithAlias[]
  45. ): EventView {
  46. const totalsColumns: QueryFieldValue[] = fields.map(field => ({
  47. kind: 'function',
  48. function: [field, '', undefined, undefined],
  49. }));
  50. const transactionName = decodeScalar(location.query.transaction);
  51. const conditions = new MutableSearch('');
  52. conditions.setFilterValues('event.type', ['transaction']);
  53. if (transactionName) {
  54. conditions.setFilterValues('transaction', [transactionName]);
  55. }
  56. const unfilteredEventView = eventView.withColumns([...totalsColumns]);
  57. unfilteredEventView.query = conditions.formatString();
  58. return unfilteredEventView;
  59. }