errorsAndTransactions.tsx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  1. import * as Sentry from '@sentry/react';
  2. import trimStart from 'lodash/trimStart';
  3. import {doEventsRequest} from 'sentry/actionCreators/events';
  4. import type {Client, ResponseMeta} from 'sentry/api';
  5. import {isMultiSeriesStats} from 'sentry/components/charts/utils';
  6. import Link from 'sentry/components/links/link';
  7. import {Tooltip} from 'sentry/components/tooltip';
  8. import {t} from 'sentry/locale';
  9. import type {
  10. EventsStats,
  11. MultiSeriesEventsStats,
  12. Organization,
  13. PageFilters,
  14. SelectValue,
  15. TagCollection,
  16. } from 'sentry/types';
  17. import type {Series} from 'sentry/types/echarts';
  18. import {defined} from 'sentry/utils';
  19. import type {CustomMeasurementCollection} from 'sentry/utils/customMeasurements/customMeasurements';
  20. import type {EventsTableData, TableData} from 'sentry/utils/discover/discoverQuery';
  21. import type {MetaType} from 'sentry/utils/discover/eventView';
  22. import type {RenderFunctionBaggage} from 'sentry/utils/discover/fieldRenderers';
  23. import {getFieldRenderer} from 'sentry/utils/discover/fieldRenderers';
  24. import type {AggregationOutputType, QueryFieldValue} from 'sentry/utils/discover/fields';
  25. import {
  26. errorsAndTransactionsAggregateFunctionOutputType,
  27. getAggregateAlias,
  28. isEquation,
  29. isEquationAlias,
  30. isLegalYAxisType,
  31. SPAN_OP_BREAKDOWN_FIELDS,
  32. stripEquationPrefix,
  33. } from 'sentry/utils/discover/fields';
  34. import type {
  35. DiscoverQueryExtras,
  36. DiscoverQueryRequestParams,
  37. } from 'sentry/utils/discover/genericDiscoverQuery';
  38. import {doDiscoverQuery} from 'sentry/utils/discover/genericDiscoverQuery';
  39. import {Container} from 'sentry/utils/discover/styles';
  40. import {TOP_N} from 'sentry/utils/discover/types';
  41. import {
  42. eventDetailsRouteWithEventView,
  43. generateEventSlug,
  44. } from 'sentry/utils/discover/urls';
  45. import {getShortEventId} from 'sentry/utils/events';
  46. import {FieldKey} from 'sentry/utils/fields';
  47. import {getMeasurements} from 'sentry/utils/measurements/measurements';
  48. import {MEPState} from 'sentry/utils/performance/contexts/metricsEnhancedSetting';
  49. import type {OnDemandControlContext} from 'sentry/utils/performance/contexts/onDemandControl';
  50. import {shouldUseOnDemandMetrics} from 'sentry/utils/performance/contexts/onDemandControl';
  51. import type {FieldValueOption} from 'sentry/views/discover/table/queryField';
  52. import type {FieldValue} from 'sentry/views/discover/table/types';
  53. import {FieldValueKind} from 'sentry/views/discover/table/types';
  54. import {generateFieldOptions} from 'sentry/views/discover/utils';
  55. import {getTraceDetailsUrl} from 'sentry/views/performance/traceDetails/utils';
  56. import {
  57. createUnnamedTransactionsDiscoverTarget,
  58. DiscoverQueryPageSource,
  59. UNPARAMETERIZED_TRANSACTION,
  60. } from 'sentry/views/performance/utils';
  61. import type {Widget, WidgetQuery} from '../types';
  62. import {DisplayType} from '../types';
  63. import {
  64. eventViewFromWidget,
  65. getDashboardsMEPQueryParams,
  66. getNumEquations,
  67. getWidgetInterval,
  68. } from '../utils';
  69. import {EventsSearchBar} from '../widgetBuilder/buildSteps/filterResultsStep/eventsSearchBar';
  70. import {CUSTOM_EQUATION_VALUE} from '../widgetBuilder/buildSteps/sortByStep';
  71. import {
  72. flattenMultiSeriesDataWithGrouping,
  73. transformSeries,
  74. } from '../widgetCard/widgetQueries';
  75. import type {DatasetConfig} from './base';
  76. import {handleOrderByReset} from './base';
  77. const DEFAULT_WIDGET_QUERY: WidgetQuery = {
  78. name: '',
  79. fields: ['count()'],
  80. columns: [],
  81. fieldAliases: [],
  82. aggregates: ['count()'],
  83. conditions: '',
  84. orderby: '-count()',
  85. };
  86. export type SeriesWithOrdering = [order: number, series: Series];
  87. export const ErrorsAndTransactionsConfig: DatasetConfig<
  88. EventsStats | MultiSeriesEventsStats,
  89. TableData | EventsTableData
  90. > = {
  91. defaultWidgetQuery: DEFAULT_WIDGET_QUERY,
  92. enableEquations: true,
  93. getCustomFieldRenderer: getCustomEventsFieldRenderer,
  94. SearchBar: EventsSearchBar,
  95. filterSeriesSortOptions,
  96. filterYAxisAggregateParams,
  97. filterYAxisOptions,
  98. getTableFieldOptions: getEventsTableFieldOptions,
  99. getTimeseriesSortOptions,
  100. getTableSortOptions,
  101. getGroupByFieldOptions: getEventsTableFieldOptions,
  102. handleOrderByReset,
  103. supportedDisplayTypes: [
  104. DisplayType.AREA,
  105. DisplayType.BAR,
  106. DisplayType.BIG_NUMBER,
  107. DisplayType.LINE,
  108. DisplayType.TABLE,
  109. DisplayType.TOP_N,
  110. ],
  111. getTableRequest: (
  112. api: Client,
  113. widget: Widget,
  114. query: WidgetQuery,
  115. organization: Organization,
  116. pageFilters: PageFilters,
  117. onDemandControlContext?: OnDemandControlContext,
  118. limit?: number,
  119. cursor?: string,
  120. referrer?: string,
  121. mepSetting?: MEPState | null
  122. ) => {
  123. const url = `/organizations/${organization.slug}/events/`;
  124. const useOnDemandMetrics = shouldUseOnDemandMetrics(
  125. organization,
  126. widget,
  127. onDemandControlContext
  128. );
  129. const queryExtras = {
  130. useOnDemandMetrics,
  131. ...getQueryExtraForSplittingDiscover(widget, organization, !!useOnDemandMetrics),
  132. onDemandType: 'dynamic_query',
  133. };
  134. return getEventsRequest(
  135. url,
  136. api,
  137. query,
  138. organization,
  139. pageFilters,
  140. limit,
  141. cursor,
  142. referrer,
  143. mepSetting,
  144. queryExtras
  145. );
  146. },
  147. getSeriesRequest: getEventsSeriesRequest,
  148. transformSeries: transformEventsResponseToSeries,
  149. transformTable: transformEventsResponseToTable,
  150. filterAggregateParams,
  151. getSeriesResultType,
  152. };
  153. function getTableSortOptions(_organization: Organization, widgetQuery: WidgetQuery) {
  154. const {columns, aggregates} = widgetQuery;
  155. const options: SelectValue<string>[] = [];
  156. let equations = 0;
  157. [...aggregates, ...columns]
  158. .filter(field => !!field)
  159. .forEach(field => {
  160. let alias;
  161. const label = stripEquationPrefix(field);
  162. // Equations are referenced via a standard alias following this pattern
  163. if (isEquation(field)) {
  164. alias = `equation[${equations}]`;
  165. equations += 1;
  166. }
  167. options.push({label, value: alias ?? field});
  168. });
  169. return options;
  170. }
  171. function filterSeriesSortOptions(columns: Set<string>) {
  172. return (option: FieldValueOption) => {
  173. if (
  174. option.value.kind === FieldValueKind.FUNCTION ||
  175. option.value.kind === FieldValueKind.EQUATION
  176. ) {
  177. return true;
  178. }
  179. return (
  180. columns.has(option.value.meta.name) ||
  181. option.value.meta.name === CUSTOM_EQUATION_VALUE
  182. );
  183. };
  184. }
  185. function getTimeseriesSortOptions(
  186. organization: Organization,
  187. widgetQuery: WidgetQuery,
  188. tags?: TagCollection
  189. ) {
  190. const options: Record<string, SelectValue<FieldValue>> = {};
  191. options[`field:${CUSTOM_EQUATION_VALUE}`] = {
  192. label: 'Custom Equation',
  193. value: {
  194. kind: FieldValueKind.EQUATION,
  195. meta: {name: CUSTOM_EQUATION_VALUE},
  196. },
  197. };
  198. let equations = 0;
  199. [...widgetQuery.aggregates, ...widgetQuery.columns]
  200. .filter(field => !!field)
  201. .forEach(field => {
  202. let alias;
  203. const label = stripEquationPrefix(field);
  204. // Equations are referenced via a standard alias following this pattern
  205. if (isEquation(field)) {
  206. alias = `equation[${equations}]`;
  207. equations += 1;
  208. options[`equation:${alias}`] = {
  209. label,
  210. value: {
  211. kind: FieldValueKind.EQUATION,
  212. meta: {
  213. name: alias ?? field,
  214. },
  215. },
  216. };
  217. }
  218. });
  219. const fieldOptions = getEventsTableFieldOptions(organization, tags);
  220. return {...options, ...fieldOptions};
  221. }
  222. function getEventsTableFieldOptions(
  223. organization: Organization,
  224. tags?: TagCollection,
  225. customMeasurements?: CustomMeasurementCollection
  226. ) {
  227. const measurements = getMeasurements();
  228. return generateFieldOptions({
  229. organization,
  230. tagKeys: Object.values(tags ?? {}).map(({key}) => key),
  231. measurementKeys: Object.values(measurements).map(({key}) => key),
  232. spanOperationBreakdownKeys: SPAN_OP_BREAKDOWN_FIELDS,
  233. customMeasurements: Object.values(customMeasurements ?? {}).map(
  234. ({key, functions}) => ({
  235. key,
  236. functions,
  237. })
  238. ),
  239. });
  240. }
  241. function transformEventsResponseToTable(
  242. data: TableData | EventsTableData,
  243. _widgetQuery: WidgetQuery
  244. ): TableData {
  245. let tableData = data;
  246. // events api uses a different response format so we need to construct tableData differently
  247. const {fields, ...otherMeta} = (data as EventsTableData).meta ?? {};
  248. tableData = {
  249. ...data,
  250. meta: {...fields, ...otherMeta},
  251. } as TableData;
  252. return tableData as TableData;
  253. }
  254. function filterYAxisAggregateParams(
  255. fieldValue: QueryFieldValue,
  256. displayType: DisplayType
  257. ) {
  258. return (option: FieldValueOption) => {
  259. // Only validate function parameters for timeseries widgets and
  260. // world map widgets.
  261. if (displayType === DisplayType.BIG_NUMBER) {
  262. return true;
  263. }
  264. if (fieldValue.kind !== FieldValueKind.FUNCTION) {
  265. return true;
  266. }
  267. const functionName = fieldValue.function[0];
  268. const primaryOutput = errorsAndTransactionsAggregateFunctionOutputType(
  269. functionName as string,
  270. option.value.meta.name
  271. );
  272. if (primaryOutput) {
  273. return isLegalYAxisType(primaryOutput);
  274. }
  275. if (
  276. option.value.kind === FieldValueKind.FUNCTION ||
  277. option.value.kind === FieldValueKind.EQUATION
  278. ) {
  279. // Functions and equations are not legal options as an aggregate/function parameter.
  280. return false;
  281. }
  282. return isLegalYAxisType(option.value.meta.dataType);
  283. };
  284. }
  285. function filterYAxisOptions(displayType: DisplayType) {
  286. return (option: FieldValueOption) => {
  287. // Only validate function names for timeseries widgets and
  288. // world map widgets.
  289. if (
  290. !(displayType === DisplayType.BIG_NUMBER) &&
  291. option.value.kind === FieldValueKind.FUNCTION
  292. ) {
  293. const primaryOutput = errorsAndTransactionsAggregateFunctionOutputType(
  294. option.value.meta.name,
  295. undefined
  296. );
  297. if (primaryOutput) {
  298. // If a function returns a specific type, then validate it.
  299. return isLegalYAxisType(primaryOutput);
  300. }
  301. }
  302. return option.value.kind === FieldValueKind.FUNCTION;
  303. };
  304. }
  305. function transformEventsResponseToSeries(
  306. data: EventsStats | MultiSeriesEventsStats,
  307. widgetQuery: WidgetQuery
  308. ): Series[] {
  309. let output: Series[] = [];
  310. const queryAlias = widgetQuery.name;
  311. if (isMultiSeriesStats(data)) {
  312. let seriesWithOrdering: SeriesWithOrdering[] = [];
  313. const isMultiSeriesDataWithGrouping =
  314. widgetQuery.aggregates.length > 1 && widgetQuery.columns.length;
  315. // Convert multi-series results into chartable series. Multi series results
  316. // are created when multiple yAxis are used. Convert the timeseries
  317. // data into a multi-series data set. As the server will have
  318. // replied with a map like: {[titleString: string]: EventsStats}
  319. if (isMultiSeriesDataWithGrouping) {
  320. seriesWithOrdering = flattenMultiSeriesDataWithGrouping(data, queryAlias);
  321. } else {
  322. seriesWithOrdering = Object.keys(data).map((seriesName: string) => {
  323. const prefixedName = queryAlias ? `${queryAlias} : ${seriesName}` : seriesName;
  324. const seriesData: EventsStats = data[seriesName];
  325. return [
  326. seriesData.order || 0,
  327. transformSeries(seriesData, prefixedName, seriesName),
  328. ];
  329. });
  330. }
  331. output = [
  332. ...seriesWithOrdering
  333. .sort((itemA, itemB) => itemA[0] - itemB[0])
  334. .map(item => item[1]),
  335. ];
  336. } else {
  337. const field = widgetQuery.aggregates[0];
  338. const prefixedName = queryAlias ? `${queryAlias} : ${field}` : field;
  339. const transformed = transformSeries(data, prefixedName, field);
  340. output.push(transformed);
  341. }
  342. return output;
  343. }
  344. // Get the series result type from the EventsStats meta
  345. function getSeriesResultType(
  346. data: EventsStats | MultiSeriesEventsStats,
  347. widgetQuery: WidgetQuery
  348. ): Record<string, AggregationOutputType> {
  349. const field = widgetQuery.aggregates[0];
  350. const resultTypes = {};
  351. // Need to use getAggregateAlias since events-stats still uses aggregate alias format
  352. if (isMultiSeriesStats(data)) {
  353. Object.keys(data).forEach(
  354. key => (resultTypes[key] = data[key].meta?.fields[getAggregateAlias(key)])
  355. );
  356. } else {
  357. resultTypes[field] = data.meta?.fields[getAggregateAlias(field)];
  358. }
  359. return resultTypes;
  360. }
  361. function renderEventIdAsLinkable(data, {eventView, organization}: RenderFunctionBaggage) {
  362. const id: string | unknown = data?.id;
  363. if (!eventView || typeof id !== 'string') {
  364. return null;
  365. }
  366. const eventSlug = generateEventSlug(data);
  367. const target = eventDetailsRouteWithEventView({
  368. orgSlug: organization.slug,
  369. eventSlug,
  370. eventView,
  371. });
  372. return (
  373. <Tooltip title={t('View Event')}>
  374. <Link data-test-id="view-event" to={target}>
  375. <Container>{getShortEventId(id)}</Container>
  376. </Link>
  377. </Tooltip>
  378. );
  379. }
  380. function renderTraceAsLinkable(
  381. data,
  382. {eventView, organization, location}: RenderFunctionBaggage
  383. ) {
  384. const id: string | unknown = data?.trace;
  385. if (!eventView || typeof id !== 'string') {
  386. return null;
  387. }
  388. const dateSelection = eventView.normalizeDateSelection(location);
  389. const target = getTraceDetailsUrl(
  390. organization,
  391. String(data.trace),
  392. dateSelection,
  393. {},
  394. data.timestamp,
  395. data.id || data.eventID
  396. );
  397. return (
  398. <Tooltip title={t('View Trace')}>
  399. <Link data-test-id="view-trace" to={target}>
  400. <Container>{getShortEventId(id)}</Container>
  401. </Link>
  402. </Tooltip>
  403. );
  404. }
  405. export function getCustomEventsFieldRenderer(field: string, meta: MetaType) {
  406. if (field === 'id') {
  407. return renderEventIdAsLinkable;
  408. }
  409. if (field === 'trace') {
  410. return renderTraceAsLinkable;
  411. }
  412. // When title or transaction are << unparameterized >>, link out to discover showing unparameterized transactions
  413. if (['title', 'transaction'].includes(field)) {
  414. return function (data, baggage) {
  415. if (data[field] === UNPARAMETERIZED_TRANSACTION) {
  416. return (
  417. <Container>
  418. <Link
  419. to={createUnnamedTransactionsDiscoverTarget({
  420. location: baggage.location,
  421. organization: baggage.organization,
  422. source: DiscoverQueryPageSource.DISCOVER,
  423. })}
  424. >
  425. {data[field]}
  426. </Link>
  427. </Container>
  428. );
  429. }
  430. return getFieldRenderer(field, meta, false)(data, baggage);
  431. };
  432. }
  433. return getFieldRenderer(field, meta, false);
  434. }
  435. function getEventsRequest(
  436. url: string,
  437. api: Client,
  438. query: WidgetQuery,
  439. _organization: Organization,
  440. pageFilters: PageFilters,
  441. limit?: number,
  442. cursor?: string,
  443. referrer?: string,
  444. mepSetting?: MEPState | null,
  445. queryExtras?: DiscoverQueryExtras
  446. ) {
  447. const isMEPEnabled = defined(mepSetting) && mepSetting !== MEPState.TRANSACTIONS_ONLY;
  448. const eventView = eventViewFromWidget('', query, pageFilters);
  449. const params: DiscoverQueryRequestParams = {
  450. per_page: limit,
  451. cursor,
  452. referrer,
  453. ...getDashboardsMEPQueryParams(isMEPEnabled),
  454. ...queryExtras,
  455. };
  456. if (query.orderby) {
  457. params.sort = typeof query.orderby === 'string' ? [query.orderby] : query.orderby;
  458. }
  459. // TODO: eventually need to replace this with just EventsTableData as we deprecate eventsv2
  460. return doDiscoverQuery<TableData | EventsTableData>(
  461. api,
  462. url,
  463. {
  464. ...eventView.generateQueryStringObject(),
  465. ...params,
  466. },
  467. // Tries events request up to 3 times on rate limit
  468. {
  469. retry: {
  470. statusCodes: [429],
  471. tries: 3,
  472. },
  473. }
  474. );
  475. }
  476. function getEventsSeriesRequest(
  477. api: Client,
  478. widget: Widget,
  479. queryIndex: number,
  480. organization: Organization,
  481. pageFilters: PageFilters,
  482. onDemandControlContext?: OnDemandControlContext,
  483. referrer?: string,
  484. mepSetting?: MEPState | null
  485. ) {
  486. const widgetQuery = widget.queries[queryIndex];
  487. const {displayType, limit} = widget;
  488. const {environments, projects} = pageFilters;
  489. const {start, end, period: statsPeriod} = pageFilters.datetime;
  490. const interval = getWidgetInterval(
  491. displayType,
  492. {start, end, period: statsPeriod},
  493. '1m'
  494. );
  495. const isMEPEnabled = defined(mepSetting) && mepSetting !== MEPState.TRANSACTIONS_ONLY;
  496. let requestData;
  497. if (displayType === DisplayType.TOP_N) {
  498. requestData = {
  499. organization,
  500. interval,
  501. start,
  502. end,
  503. project: projects,
  504. environment: environments,
  505. period: statsPeriod,
  506. query: widgetQuery.conditions,
  507. yAxis: widgetQuery.aggregates[widgetQuery.aggregates.length - 1],
  508. includePrevious: false,
  509. referrer,
  510. partial: true,
  511. field: [...widgetQuery.columns, ...widgetQuery.aggregates],
  512. queryExtras: getDashboardsMEPQueryParams(isMEPEnabled),
  513. includeAllArgs: true,
  514. topEvents: TOP_N,
  515. };
  516. if (widgetQuery.orderby) {
  517. requestData.orderby = widgetQuery.orderby;
  518. }
  519. } else {
  520. requestData = {
  521. organization,
  522. interval,
  523. start,
  524. end,
  525. project: projects,
  526. environment: environments,
  527. period: statsPeriod,
  528. query: widgetQuery.conditions,
  529. yAxis: widgetQuery.aggregates,
  530. orderby: widgetQuery.orderby,
  531. includePrevious: false,
  532. referrer,
  533. partial: true,
  534. queryExtras: getDashboardsMEPQueryParams(isMEPEnabled),
  535. includeAllArgs: true,
  536. };
  537. if (widgetQuery.columns?.length !== 0) {
  538. requestData.topEvents = limit ?? TOP_N;
  539. requestData.field = [...widgetQuery.columns, ...widgetQuery.aggregates];
  540. // Compare field and orderby as aliases to ensure requestData has
  541. // the orderby selected
  542. // If the orderby is an equation alias, do not inject it
  543. const orderby = trimStart(widgetQuery.orderby, '-');
  544. if (
  545. widgetQuery.orderby &&
  546. !isEquationAlias(orderby) &&
  547. !requestData.field.includes(orderby)
  548. ) {
  549. requestData.field.push(orderby);
  550. }
  551. // The "Other" series is only included when there is one
  552. // y-axis and one widgetQuery
  553. requestData.excludeOther =
  554. widgetQuery.aggregates.length !== 1 || widget.queries.length !== 1;
  555. if (isEquation(trimStart(widgetQuery.orderby, '-'))) {
  556. const nextEquationIndex = getNumEquations(widgetQuery.aggregates);
  557. const isDescending = widgetQuery.orderby.startsWith('-');
  558. const prefix = isDescending ? '-' : '';
  559. // Construct the alias form of the equation and inject it into the request
  560. requestData.orderby = `${prefix}equation[${nextEquationIndex}]`;
  561. requestData.field = [
  562. ...widgetQuery.columns,
  563. ...widgetQuery.aggregates,
  564. trimStart(widgetQuery.orderby, '-'),
  565. ];
  566. }
  567. }
  568. }
  569. if (shouldUseOnDemandMetrics(organization, widget, onDemandControlContext)) {
  570. requestData.queryExtras = {
  571. ...requestData.queryExtras,
  572. ...getQueryExtraForSplittingDiscover(widget, organization, true),
  573. };
  574. return doOnDemandMetricsRequest(api, requestData);
  575. }
  576. return doEventsRequest<true>(api, requestData);
  577. }
  578. async function doOnDemandMetricsRequest(
  579. api,
  580. requestData
  581. ): Promise<
  582. [EventsStats | MultiSeriesEventsStats, string | undefined, ResponseMeta | undefined]
  583. > {
  584. try {
  585. const isEditing = location.pathname.endsWith('/edit/');
  586. const fetchEstimatedStats = () =>
  587. `/organizations/${requestData.organization.slug}/metrics-estimation-stats/`;
  588. const response = await doEventsRequest<false>(api, {
  589. ...requestData,
  590. queryExtras: {
  591. ...requestData.queryExtras,
  592. useOnDemandMetrics: true,
  593. onDemandType: 'dynamic_query',
  594. },
  595. dataset: 'metricsEnhanced',
  596. generatePathname: isEditing ? fetchEstimatedStats : undefined,
  597. });
  598. response[0] = {...response[0]};
  599. return [response[0], response[1], response[2]];
  600. } catch (err) {
  601. Sentry.captureMessage('Failed to fetch metrics estimation stats', {extra: err});
  602. return doEventsRequest<true>(api, requestData);
  603. }
  604. }
  605. // Checks fieldValue to see what function is being used and only allow supported custom measurements
  606. function filterAggregateParams(option: FieldValueOption, fieldValue?: QueryFieldValue) {
  607. if (
  608. (option.value.kind === FieldValueKind.CUSTOM_MEASUREMENT &&
  609. fieldValue?.kind === 'function' &&
  610. fieldValue?.function &&
  611. !option.value.meta.functions.includes(fieldValue.function[0])) ||
  612. option.value.meta.name === FieldKey.TOTAL_COUNT
  613. ) {
  614. return false;
  615. }
  616. return true;
  617. }
  618. const shouldSendWidgetForSplittingDiscover = (organization: Organization) => {
  619. return organization.features.includes('performance-discover-widget-split-ui');
  620. };
  621. const getQueryExtraForSplittingDiscover = (
  622. widget: Widget,
  623. organization: Organization,
  624. useOnDemandMetrics: boolean
  625. ) => {
  626. if (!useOnDemandMetrics || !shouldSendWidgetForSplittingDiscover(organization)) {
  627. return {};
  628. }
  629. if (widget.id) {
  630. return {dashboardWidgetId: widget.id};
  631. }
  632. return {};
  633. };