utils.tsx 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import {Location} from 'history';
  2. import {Organization} from 'sentry/types';
  3. import EventView from 'sentry/utils/discover/eventView';
  4. import {AggregationKeyWithAlias, QueryFieldValue} from 'sentry/utils/discover/fields';
  5. import {
  6. canUseMetricsData,
  7. MetricsEnhancedSettingContext,
  8. } from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
  9. import {decodeScalar} from 'sentry/utils/queryString';
  10. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  11. import {getMEPQueryParams} from 'sentry/views/performance/landing/widgets/utils';
  12. export function canUseTransactionMetricsData(organization, location) {
  13. const isUsingMetrics = canUseMetricsData(organization);
  14. if (!isUsingMetrics) {
  15. return false;
  16. }
  17. // span op breakdown filters aren't compatible with metrics
  18. const breakdown = decodeScalar(location.query.breakdown, '');
  19. if (breakdown) {
  20. return false;
  21. }
  22. // in the short term, using any filter will force indexed event search
  23. const query = decodeScalar(location.query.query, '');
  24. if (query) {
  25. return false;
  26. }
  27. return true;
  28. }
  29. export function getTransactionMEPParamsIfApplicable(
  30. mepContext: MetricsEnhancedSettingContext,
  31. organization: Organization,
  32. location: Location
  33. ) {
  34. if (!organization.features.includes('performance-metrics-backed-transaction-summary')) {
  35. return undefined;
  36. }
  37. if (!canUseTransactionMetricsData(organization, location)) {
  38. return undefined;
  39. }
  40. return getMEPQueryParams(mepContext);
  41. }
  42. export function getTransactionTotalsMEPParamsIfApplicable(
  43. mepContext: MetricsEnhancedSettingContext,
  44. organization: Organization
  45. ) {
  46. if (!organization.features.includes('performance-metrics-backed-transaction-summary')) {
  47. return undefined;
  48. }
  49. if (!canUseMetricsData(organization)) {
  50. return undefined;
  51. }
  52. return getMEPQueryParams(mepContext);
  53. }
  54. export function getUnfilteredTotalsEventView(
  55. eventView: EventView,
  56. location: Location,
  57. fields: AggregationKeyWithAlias[]
  58. ): EventView {
  59. const totalsColumns: QueryFieldValue[] = fields.map(field => ({
  60. kind: 'function',
  61. function: [field, '', undefined, undefined],
  62. }));
  63. const transactionName = decodeScalar(location.query.transaction);
  64. const conditions = new MutableSearch('');
  65. conditions.setFilterValues('event.type', ['transaction']);
  66. if (transactionName) {
  67. conditions.setFilterValues('transaction', [transactionName]);
  68. }
  69. const unfilteredEventView = eventView.withColumns([...totalsColumns]);
  70. unfilteredEventView.query = conditions.formatString();
  71. return unfilteredEventView;
  72. }