data.tsx 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825
  1. import type {Location} from 'history';
  2. import {COL_WIDTH_UNDEFINED} from 'sentry/components/gridEditable';
  3. import ExternalLink from 'sentry/components/links/externalLink';
  4. import {wrapQueryInWildcards} from 'sentry/components/performance/searchBar';
  5. import {ALL_ACCESS_PROJECTS} from 'sentry/constants/pageFilters';
  6. import {t, tct} from 'sentry/locale';
  7. import type {SelectValue} from 'sentry/types/core';
  8. import type {NewQuery, Organization} from 'sentry/types/organization';
  9. import type {Project} from 'sentry/types/project';
  10. import EventView from 'sentry/utils/discover/eventView';
  11. import {WEB_VITAL_DETAILS} from 'sentry/utils/performance/vitals/constants';
  12. import {decodeScalar} from 'sentry/utils/queryString';
  13. import {MutableSearch} from 'sentry/utils/tokenizeSearch';
  14. import {getCurrentTrendParameter} from 'sentry/views/performance/trends/utils';
  15. import {getCurrentLandingDisplay, LandingDisplayField} from './landing/utils';
  16. import {
  17. getVitalDetailTableMehStatusFunction,
  18. getVitalDetailTablePoorStatusFunction,
  19. vitalNameFromLocation,
  20. } from './vitalDetail/utils';
  21. export const DEFAULT_STATS_PERIOD = '7d';
  22. export const DEFAULT_PROJECT_THRESHOLD_METRIC = 'duration';
  23. export const DEFAULT_PROJECT_THRESHOLD = 300;
  24. export const COLUMN_TITLES = [
  25. 'transaction',
  26. 'project',
  27. 'tpm',
  28. 'p50',
  29. 'p95',
  30. 'failure rate',
  31. 'apdex',
  32. 'users',
  33. 'user misery',
  34. ];
  35. export const USER_MISERY_TOOLTIP = tct(
  36. 'A configurable score telling you how frequently users are frustrated by your application performance. [link:Learn more.]',
  37. {
  38. link: (
  39. <ExternalLink href="https://docs.sentry.io/product/performance/metrics/#user-misery" />
  40. ),
  41. }
  42. );
  43. const TOKEN_KEYS_SUPPORTED_IN_LIMITED_SEARCH = ['transaction'];
  44. export const getDefaultStatsPeriod = (organization: Organization) => {
  45. if (organization.features.includes('performance-landing-page-stats-period')) {
  46. return '14d';
  47. }
  48. return DEFAULT_STATS_PERIOD;
  49. };
  50. export enum PerformanceTerm {
  51. TPM = 'tpm',
  52. THROUGHPUT = 'throughput',
  53. FAILURE_RATE = 'failureRate',
  54. P50 = 'p50',
  55. P75 = 'p75',
  56. P95 = 'p95',
  57. P99 = 'p99',
  58. LCP = 'lcp',
  59. FCP = 'fcp',
  60. FID = 'fid',
  61. CLS = 'cls',
  62. STATUS_BREAKDOWN = 'statusBreakdown',
  63. DURATION_DISTRIBUTION = 'durationDistribution',
  64. USER_MISERY = 'userMisery',
  65. APDEX = 'apdex',
  66. APP_START_COLD = 'appStartCold',
  67. APP_START_WARM = 'appStartWarm',
  68. SLOW_FRAMES = 'slowFrames',
  69. FROZEN_FRAMES = 'frozenFrames',
  70. STALL_PERCENTAGE = 'stallPercentage',
  71. MOST_ISSUES = 'mostIssues',
  72. MOST_ERRORS = 'mostErrors',
  73. SLOW_HTTP_SPANS = 'slowHTTPSpans',
  74. TIME_TO_FULL_DISPLAY = 'timeToFullDisplay',
  75. TIME_TO_INITIAL_DISPLAY = 'timeToInitialDisplay',
  76. MOST_TIME_SPENT_DB_QUERIES = 'mostTimeSpentDbQueries',
  77. MOST_TIME_CONSUMING_RESOURCES = 'mostTimeConsumingResources',
  78. MOST_TIME_CONSUMING_DOMAINS = 'mostTimeConsumingDomains',
  79. HIGHEST_CACHE_MISS_RATE_TRANSACTIONS = 'highestCacheMissRateTransactions',
  80. }
  81. export type TooltipOption = SelectValue<string> & {
  82. tooltip: string;
  83. };
  84. export function getAxisOptions(organization: Organization): TooltipOption[] {
  85. return [
  86. {
  87. tooltip: getTermHelp(organization, PerformanceTerm.APDEX),
  88. value: 'apdex()',
  89. label: t('Apdex'),
  90. },
  91. {
  92. tooltip: getTermHelp(organization, PerformanceTerm.TPM),
  93. value: 'tpm()',
  94. label: t('Transactions Per Minute'),
  95. },
  96. {
  97. tooltip: getTermHelp(organization, PerformanceTerm.FAILURE_RATE),
  98. value: 'failure_rate()',
  99. label: t('Failure Rate'),
  100. },
  101. {
  102. tooltip: getTermHelp(organization, PerformanceTerm.P50),
  103. value: 'p50()',
  104. label: t('p50 Duration'),
  105. },
  106. {
  107. tooltip: getTermHelp(organization, PerformanceTerm.P95),
  108. value: 'p95()',
  109. label: t('p95 Duration'),
  110. },
  111. {
  112. tooltip: getTermHelp(organization, PerformanceTerm.P99),
  113. value: 'p99()',
  114. label: t('p99 Duration'),
  115. },
  116. ];
  117. }
  118. export type AxisOption = TooltipOption & {
  119. field: string;
  120. label: string;
  121. backupOption?: AxisOption;
  122. isDistribution?: boolean;
  123. isLeftDefault?: boolean;
  124. isRightDefault?: boolean;
  125. };
  126. export function getFrontendAxisOptions(organization: Organization): AxisOption[] {
  127. return [
  128. {
  129. tooltip: getTermHelp(organization, PerformanceTerm.LCP),
  130. value: `p75(lcp)`,
  131. label: t('LCP p75'),
  132. field: 'p75(measurements.lcp)',
  133. isLeftDefault: true,
  134. backupOption: {
  135. tooltip: getTermHelp(organization, PerformanceTerm.FCP),
  136. value: `p75(fcp)`,
  137. label: t('FCP p75'),
  138. field: 'p75(measurements.fcp)',
  139. },
  140. },
  141. {
  142. tooltip: getTermHelp(organization, PerformanceTerm.DURATION_DISTRIBUTION),
  143. value: 'lcp_distribution',
  144. label: t('LCP Distribution'),
  145. field: 'measurements.lcp',
  146. isDistribution: true,
  147. isRightDefault: true,
  148. backupOption: {
  149. tooltip: getTermHelp(organization, PerformanceTerm.DURATION_DISTRIBUTION),
  150. value: 'fcp_distribution',
  151. label: t('FCP Distribution'),
  152. field: 'measurements.fcp',
  153. isDistribution: true,
  154. },
  155. },
  156. {
  157. tooltip: getTermHelp(organization, PerformanceTerm.TPM),
  158. value: 'tpm()',
  159. label: t('Transactions Per Minute'),
  160. field: 'tpm()',
  161. },
  162. ];
  163. }
  164. export function getFrontendOtherAxisOptions(organization: Organization): AxisOption[] {
  165. return [
  166. {
  167. tooltip: getTermHelp(organization, PerformanceTerm.P50),
  168. value: `p50()`,
  169. label: t('Duration p50'),
  170. field: 'p50(transaction.duration)',
  171. },
  172. {
  173. tooltip: getTermHelp(organization, PerformanceTerm.P75),
  174. value: `p75()`,
  175. label: t('Duration p75'),
  176. field: 'p75(transaction.duration)',
  177. isLeftDefault: true,
  178. },
  179. {
  180. tooltip: getTermHelp(organization, PerformanceTerm.P95),
  181. value: `p95()`,
  182. label: t('Duration p95'),
  183. field: 'p95(transaction.duration)',
  184. },
  185. {
  186. tooltip: getTermHelp(organization, PerformanceTerm.DURATION_DISTRIBUTION),
  187. value: 'duration_distribution',
  188. label: t('Duration Distribution'),
  189. field: 'transaction.duration',
  190. isDistribution: true,
  191. isRightDefault: true,
  192. },
  193. ];
  194. }
  195. export function getBackendAxisOptions(organization: Organization): AxisOption[] {
  196. return [
  197. {
  198. tooltip: getTermHelp(organization, PerformanceTerm.P50),
  199. value: `p50()`,
  200. label: t('Duration p50'),
  201. field: 'p50(transaction.duration)',
  202. },
  203. {
  204. tooltip: getTermHelp(organization, PerformanceTerm.P75),
  205. value: `p75()`,
  206. label: t('Duration p75'),
  207. field: 'p75(transaction.duration)',
  208. isLeftDefault: true,
  209. },
  210. {
  211. tooltip: getTermHelp(organization, PerformanceTerm.P95),
  212. value: `p95()`,
  213. label: t('Duration p95'),
  214. field: 'p95(transaction.duration)',
  215. },
  216. {
  217. tooltip: getTermHelp(organization, PerformanceTerm.P99),
  218. value: `p99()`,
  219. label: t('Duration p99'),
  220. field: 'p99(transaction.duration)',
  221. },
  222. {
  223. tooltip: getTermHelp(organization, PerformanceTerm.TPM),
  224. value: 'tpm()',
  225. label: t('Transactions Per Minute'),
  226. field: 'tpm()',
  227. },
  228. {
  229. tooltip: getTermHelp(organization, PerformanceTerm.FAILURE_RATE),
  230. value: 'failure_rate()',
  231. label: t('Failure Rate'),
  232. field: 'failure_rate()',
  233. },
  234. {
  235. tooltip: getTermHelp(organization, PerformanceTerm.DURATION_DISTRIBUTION),
  236. value: 'duration_distribution',
  237. label: t('Duration Distribution'),
  238. field: 'transaction.duration',
  239. isDistribution: true,
  240. isRightDefault: true,
  241. },
  242. {
  243. tooltip: getTermHelp(organization, PerformanceTerm.APDEX),
  244. value: 'apdex()',
  245. label: t('Apdex'),
  246. field: 'apdex()',
  247. },
  248. ];
  249. }
  250. export function getMobileAxisOptions(organization: Organization): AxisOption[] {
  251. return [
  252. {
  253. tooltip: getTermHelp(organization, PerformanceTerm.APP_START_COLD),
  254. value: `p50(measurements.app_start_cold)`,
  255. label: t('Cold Start Duration p50'),
  256. field: 'p50(measurements.app_start_cold)',
  257. },
  258. {
  259. tooltip: getTermHelp(organization, PerformanceTerm.APP_START_COLD),
  260. value: `p75(measurements.app_start_cold)`,
  261. label: t('Cold Start Duration p75'),
  262. field: 'p75(measurements.app_start_cold)',
  263. isLeftDefault: true,
  264. },
  265. {
  266. tooltip: getTermHelp(organization, PerformanceTerm.APP_START_COLD),
  267. value: `p95(measurements.app_start_cold)`,
  268. label: t('Cold Start Duration p95'),
  269. field: 'p95(measurements.app_start_cold)',
  270. },
  271. {
  272. tooltip: getTermHelp(organization, PerformanceTerm.APP_START_COLD),
  273. value: `p99(measurements.app_start_cold)`,
  274. label: t('Cold Start Duration p99'),
  275. field: 'p99(measurements.app_start_cold)',
  276. },
  277. {
  278. tooltip: getTermHelp(organization, PerformanceTerm.DURATION_DISTRIBUTION),
  279. value: 'app_start_cold_distribution',
  280. label: t('Cold Start Distribution'),
  281. field: 'measurements.app_start_cold',
  282. isDistribution: true,
  283. isRightDefault: true,
  284. },
  285. {
  286. tooltip: getTermHelp(organization, PerformanceTerm.APP_START_WARM),
  287. value: `p50(measurements.app_start_warm)`,
  288. label: t('Warm Start Duration p50'),
  289. field: 'p50(measurements.app_start_warm)',
  290. },
  291. {
  292. tooltip: getTermHelp(organization, PerformanceTerm.APP_START_WARM),
  293. value: `p75(measurements.app_start_warm)`,
  294. label: t('Warm Start Duration p75'),
  295. field: 'p75(measurements.app_start_warm)',
  296. },
  297. {
  298. tooltip: getTermHelp(organization, PerformanceTerm.APP_START_WARM),
  299. value: `p95(measurements.app_start_warm)`,
  300. label: t('Warm Start Duration p95'),
  301. field: 'p95(measurements.app_start_warm)',
  302. },
  303. {
  304. tooltip: getTermHelp(organization, PerformanceTerm.APP_START_WARM),
  305. value: `p99(measurements.app_start_warm)`,
  306. label: t('Warm Start Duration p99'),
  307. field: 'p99(measurements.app_start_warm)',
  308. },
  309. {
  310. tooltip: getTermHelp(organization, PerformanceTerm.DURATION_DISTRIBUTION),
  311. value: 'app_start_warm_distribution',
  312. label: t('Warm Start Distribution'),
  313. field: 'measurements.app_start_warm',
  314. isDistribution: true,
  315. },
  316. {
  317. tooltip: getTermHelp(organization, PerformanceTerm.TPM),
  318. value: 'tpm()',
  319. label: t('Transactions Per Minute'),
  320. field: 'tpm()',
  321. },
  322. {
  323. tooltip: getTermHelp(organization, PerformanceTerm.FAILURE_RATE),
  324. value: 'failure_rate()',
  325. label: t('Failure Rate'),
  326. field: 'failure_rate()',
  327. },
  328. ];
  329. }
  330. type TermFormatter = (organization: Organization) => string;
  331. export const PERFORMANCE_TERMS: Record<PerformanceTerm, TermFormatter> = {
  332. tpm: () => t('TPM is the number of recorded transaction events per minute.'),
  333. throughput: () =>
  334. t('Throughput is the number of recorded transaction events per minute.'),
  335. failureRate: () =>
  336. t(
  337. 'Failure rate is the percentage of recorded transactions that had a known and unsuccessful status.'
  338. ),
  339. p50: () => t('p50 indicates the duration that 50% of transactions are faster than.'),
  340. p75: () => t('p75 indicates the duration that 75% of transactions are faster than.'),
  341. p95: () => t('p95 indicates the duration that 95% of transactions are faster than.'),
  342. p99: () => t('p99 indicates the duration that 99% of transactions are faster than.'),
  343. lcp: () =>
  344. t('Largest contentful paint (LCP) is a web vital meant to represent user load times'),
  345. fcp: () =>
  346. t('First contentful paint (FCP) is a web vital meant to represent user load times'),
  347. fid: () =>
  348. t(
  349. 'First input delay (FID) is a web vital representing load for the first user interaction on a page.'
  350. ),
  351. cls: () =>
  352. t(
  353. 'Cumulative layout shift (CLS) is a web vital measuring unexpected visual shifting a user experiences.'
  354. ),
  355. statusBreakdown: () =>
  356. t(
  357. 'The breakdown of transaction statuses. This may indicate what type of failure it is.'
  358. ),
  359. durationDistribution: () =>
  360. t(
  361. 'Distribution buckets counts of transactions at specifics times for your current date range'
  362. ),
  363. userMisery: () =>
  364. t(
  365. "User Misery is a score that represents the number of unique users who have experienced load times 4x the project's configured threshold. Adjust project threshold in project performance settings."
  366. ),
  367. apdex: () =>
  368. t(
  369. 'Apdex is the ratio of both satisfactory and tolerable response times to all response times. To adjust the tolerable threshold, go to project performance settings.'
  370. ),
  371. appStartCold: () =>
  372. t('Cold start is a measure of the application start up time from scratch.'),
  373. appStartWarm: () =>
  374. t('Warm start is a measure of the application start up time while still in memory.'),
  375. slowFrames: () => t('The count of the number of slow frames in the transaction.'),
  376. frozenFrames: () => t('The count of the number of frozen frames in the transaction.'),
  377. mostErrors: () => t('Transactions with the most associated errors.'),
  378. mostIssues: () => t('The most instances of an issue for a related transaction.'),
  379. mostTimeSpentDbQueries: () =>
  380. t('Database spans on which the application spent most of its total time.'),
  381. mostTimeConsumingResources: () =>
  382. t('Render blocking resources on which the application spent most of its total time.'),
  383. mostTimeConsumingDomains: () =>
  384. t('Outgoing HTTP domains on which the application spent most of its total time.'),
  385. highestCacheMissRateTransactions: () =>
  386. t('Transactions with the highest cache miss rate.'),
  387. slowHTTPSpans: () => t('The transactions with the slowest spans of a certain type.'),
  388. stallPercentage: () =>
  389. t(
  390. 'The percentage of the transaction duration in which the application is in a stalled state.'
  391. ),
  392. timeToFullDisplay: () =>
  393. t(
  394. 'The time between application launch and complete display of all resources and views'
  395. ),
  396. timeToInitialDisplay: () =>
  397. t('The time it takes for an application to produce its first frame'),
  398. };
  399. export function getTermHelp(
  400. organization: Organization,
  401. term: keyof typeof PERFORMANCE_TERMS
  402. ): string {
  403. if (!PERFORMANCE_TERMS.hasOwnProperty(term)) {
  404. return '';
  405. }
  406. return PERFORMANCE_TERMS[term](organization);
  407. }
  408. export function prepareQueryForLandingPage(searchQuery: any, withStaticFilters: any) {
  409. const conditions = new MutableSearch(searchQuery);
  410. // If there is a bare text search, we want to treat it as a search
  411. // on the transaction name.
  412. if (conditions.freeText.length > 0) {
  413. const parsedFreeText = conditions.freeText.join(' ');
  414. // the query here is a user entered condition, no need to escape it
  415. conditions.setFilterValues(
  416. 'transaction',
  417. [wrapQueryInWildcards(parsedFreeText)],
  418. false
  419. );
  420. conditions.freeText = [];
  421. }
  422. if (withStaticFilters) {
  423. conditions.tokens = conditions.tokens.filter(
  424. token => token.key && TOKEN_KEYS_SUPPORTED_IN_LIMITED_SEARCH.includes(token.key)
  425. );
  426. }
  427. return conditions.formatString();
  428. }
  429. export function generateGenericPerformanceEventView(
  430. location: Location,
  431. withStaticFilters: boolean,
  432. organization: Organization
  433. ): EventView {
  434. const {query} = location;
  435. const fields = [
  436. 'team_key_transaction',
  437. 'transaction',
  438. 'project',
  439. 'tpm()',
  440. 'p50()',
  441. 'p95()',
  442. 'failure_rate()',
  443. 'apdex()',
  444. 'count_unique(user)',
  445. 'count_miserable(user)',
  446. 'user_misery()',
  447. ];
  448. const hasStartAndEnd = query.start && query.end;
  449. const savedQuery: NewQuery = {
  450. id: undefined,
  451. name: t('Performance'),
  452. query: 'event.type:transaction',
  453. projects: [],
  454. fields,
  455. version: 2,
  456. };
  457. const widths = Array(savedQuery.fields.length).fill(COL_WIDTH_UNDEFINED);
  458. widths[savedQuery.fields.length - 1] = '110';
  459. savedQuery.widths = widths;
  460. if (!query.statsPeriod && !hasStartAndEnd) {
  461. savedQuery.range = getDefaultStatsPeriod(organization);
  462. }
  463. savedQuery.orderby = decodeScalar(query.sort, '-tpm');
  464. const searchQuery = decodeScalar(query.query, '');
  465. savedQuery.query = prepareQueryForLandingPage(searchQuery, withStaticFilters);
  466. const eventView = EventView.fromNewQueryWithLocation(savedQuery, location);
  467. eventView.additionalConditions.addFilterValues('event.type', ['transaction']);
  468. if (query.trendParameter) {
  469. // projects and projectIds are not necessary here since trendParameter will always
  470. // be present in location and will not be determined based on the project type
  471. const trendParameter = getCurrentTrendParameter(location, [], []);
  472. if (
  473. // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
  474. WEB_VITAL_DETAILS[trendParameter.column] &&
  475. !organization.features.includes('performance-new-trends')
  476. ) {
  477. eventView.additionalConditions.addFilterValues('has', [trendParameter.column]);
  478. }
  479. }
  480. return eventView;
  481. }
  482. export function generateBackendPerformanceEventView(
  483. location: Location,
  484. withStaticFilters: boolean,
  485. organization: Organization
  486. ): EventView {
  487. const {query} = location;
  488. const fields = [
  489. 'team_key_transaction',
  490. 'http.method',
  491. 'transaction',
  492. 'transaction.op',
  493. 'project',
  494. 'tpm()',
  495. 'p50()',
  496. 'p95()',
  497. 'failure_rate()',
  498. 'apdex()',
  499. 'count_unique(user)',
  500. 'count_miserable(user)',
  501. 'user_misery()',
  502. ];
  503. const hasStartAndEnd = query.start && query.end;
  504. const savedQuery: NewQuery = {
  505. id: undefined,
  506. name: t('Performance'),
  507. query: 'event.type:transaction',
  508. projects: [],
  509. fields,
  510. version: 2,
  511. };
  512. const widths = Array(savedQuery.fields.length).fill(COL_WIDTH_UNDEFINED);
  513. widths[savedQuery.fields.length - 1] = '110';
  514. savedQuery.widths = widths;
  515. if (!query.statsPeriod && !hasStartAndEnd) {
  516. savedQuery.range = getDefaultStatsPeriod(organization);
  517. }
  518. savedQuery.orderby = decodeScalar(query.sort, '-tpm');
  519. const searchQuery = decodeScalar(query.query, '');
  520. savedQuery.query = prepareQueryForLandingPage(searchQuery, withStaticFilters);
  521. const eventView = EventView.fromNewQueryWithLocation(savedQuery, location);
  522. eventView.additionalConditions.addFilterValues('event.type', ['transaction']);
  523. return eventView;
  524. }
  525. export function generateMobilePerformanceEventView(
  526. location: Location,
  527. projects: Project[],
  528. genericEventView: EventView,
  529. withStaticFilters: boolean,
  530. organization: Organization
  531. ): EventView {
  532. const {query} = location;
  533. const fields = [
  534. 'team_key_transaction',
  535. 'transaction',
  536. 'transaction.op',
  537. 'project',
  538. 'tpm()',
  539. 'p75(measurements.frames_slow_rate)',
  540. 'p75(measurements.frames_frozen_rate)',
  541. ];
  542. if (organization.features.includes('mobile-vitals')) {
  543. fields.push('p75(measurements.time_to_initial_display)');
  544. }
  545. // At this point, all projects are mobile projects.
  546. // If in addition to that, all projects are react-native projects,
  547. // then show the stall percentage as well.
  548. const projectIds = genericEventView.project;
  549. if (projectIds.length > 0 && projectIds[0] !== ALL_ACCESS_PROJECTS) {
  550. const selectedProjects = projects.filter(p =>
  551. projectIds.includes(parseInt(p.id, 10))
  552. );
  553. if (
  554. selectedProjects.length > 0 &&
  555. selectedProjects.every(project => project.platform === 'react-native')
  556. ) {
  557. fields.push('p75(measurements.stall_percentage)');
  558. }
  559. }
  560. const hasStartAndEnd = query.start && query.end;
  561. const savedQuery: NewQuery = {
  562. id: undefined,
  563. name: t('Performance'),
  564. query: 'event.type:transaction',
  565. projects: [],
  566. fields: [...fields, 'count_unique(user)', 'count_miserable(user)', 'user_misery()'],
  567. version: 2,
  568. };
  569. const widths = Array(savedQuery.fields.length).fill(COL_WIDTH_UNDEFINED);
  570. widths[savedQuery.fields.length - 1] = '110';
  571. savedQuery.widths = widths;
  572. if (!query.statsPeriod && !hasStartAndEnd) {
  573. savedQuery.range = getDefaultStatsPeriod(organization);
  574. }
  575. savedQuery.orderby = decodeScalar(query.sort, '-tpm');
  576. const searchQuery = decodeScalar(query.query, '');
  577. savedQuery.query = prepareQueryForLandingPage(searchQuery, withStaticFilters);
  578. const eventView = EventView.fromNewQueryWithLocation(savedQuery, location);
  579. eventView.additionalConditions.addFilterValues('event.type', ['transaction']);
  580. return eventView;
  581. }
  582. function generateFrontendPageloadPerformanceEventView(
  583. location: Location,
  584. withStaticFilters: boolean,
  585. organization: Organization
  586. ): EventView {
  587. const {query} = location;
  588. const fields = [
  589. 'team_key_transaction',
  590. 'transaction',
  591. 'project',
  592. 'tpm()',
  593. 'p75(measurements.fcp)',
  594. 'p75(measurements.lcp)',
  595. 'p75(measurements.fid)',
  596. 'p75(measurements.cls)',
  597. 'count_unique(user)',
  598. 'count_miserable(user)',
  599. 'user_misery()',
  600. ];
  601. const hasStartAndEnd = query.start && query.end;
  602. const savedQuery: NewQuery = {
  603. id: undefined,
  604. name: t('Performance'),
  605. query: 'event.type:transaction',
  606. projects: [],
  607. fields,
  608. version: 2,
  609. };
  610. const widths = Array(savedQuery.fields.length).fill(COL_WIDTH_UNDEFINED);
  611. widths[savedQuery.fields.length - 1] = '110';
  612. savedQuery.widths = widths;
  613. if (!query.statsPeriod && !hasStartAndEnd) {
  614. savedQuery.range = getDefaultStatsPeriod(organization);
  615. }
  616. savedQuery.orderby = decodeScalar(query.sort, '-tpm');
  617. const searchQuery = decodeScalar(query.query, '');
  618. savedQuery.query = prepareQueryForLandingPage(searchQuery, withStaticFilters);
  619. const eventView = EventView.fromNewQueryWithLocation(savedQuery, location);
  620. eventView.additionalConditions.addFilterValues('event.type', ['transaction']);
  621. eventView.additionalConditions.addFilterValues('transaction.op', ['pageload']);
  622. return eventView;
  623. }
  624. export function generateFrontendOtherPerformanceEventView(
  625. location: Location,
  626. withStaticFilters: boolean,
  627. organization: Organization
  628. ): EventView {
  629. const {query} = location;
  630. const fields = [
  631. 'team_key_transaction',
  632. 'transaction',
  633. 'transaction.op',
  634. 'project',
  635. 'tpm()',
  636. 'p50(transaction.duration)',
  637. 'p75(transaction.duration)',
  638. 'p95(transaction.duration)',
  639. 'count_unique(user)',
  640. 'count_miserable(user)',
  641. 'user_misery()',
  642. ];
  643. const hasStartAndEnd = query.start && query.end;
  644. const savedQuery: NewQuery = {
  645. id: undefined,
  646. name: t('Performance'),
  647. query: 'event.type:transaction',
  648. projects: [],
  649. fields,
  650. version: 2,
  651. };
  652. const widths = Array(savedQuery.fields.length).fill(COL_WIDTH_UNDEFINED);
  653. widths[savedQuery.fields.length - 1] = '110';
  654. savedQuery.widths = widths;
  655. if (!query.statsPeriod && !hasStartAndEnd) {
  656. savedQuery.range = getDefaultStatsPeriod(organization);
  657. }
  658. savedQuery.orderby = decodeScalar(query.sort, '-tpm');
  659. const searchQuery = decodeScalar(query.query, '');
  660. savedQuery.query = prepareQueryForLandingPage(searchQuery, withStaticFilters);
  661. const eventView = EventView.fromNewQueryWithLocation(savedQuery, location);
  662. eventView.additionalConditions.addFilterValues('event.type', ['transaction']);
  663. return eventView;
  664. }
  665. export function generatePerformanceEventView(
  666. location: Location,
  667. projects: Project[],
  668. {isTrends = false, withStaticFilters = false} = {},
  669. organization: Organization
  670. ) {
  671. const eventView = generateGenericPerformanceEventView(
  672. location,
  673. withStaticFilters,
  674. organization
  675. );
  676. if (isTrends) {
  677. return eventView;
  678. }
  679. const display = getCurrentLandingDisplay(location, projects, eventView);
  680. switch (display?.field) {
  681. case LandingDisplayField.FRONTEND_PAGELOAD:
  682. return generateFrontendPageloadPerformanceEventView(
  683. location,
  684. withStaticFilters,
  685. organization
  686. );
  687. case LandingDisplayField.FRONTEND_OTHER:
  688. return generateFrontendOtherPerformanceEventView(
  689. location,
  690. withStaticFilters,
  691. organization
  692. );
  693. case LandingDisplayField.BACKEND:
  694. return generateBackendPerformanceEventView(
  695. location,
  696. withStaticFilters,
  697. organization
  698. );
  699. case LandingDisplayField.MOBILE:
  700. return generateMobilePerformanceEventView(
  701. location,
  702. projects,
  703. eventView,
  704. withStaticFilters,
  705. organization
  706. );
  707. default:
  708. return eventView;
  709. }
  710. }
  711. export function generatePerformanceVitalDetailView(
  712. location: Location,
  713. organization: Organization
  714. ): EventView {
  715. const {query} = location;
  716. const vitalName = vitalNameFromLocation(location);
  717. const hasStartAndEnd = query.start && query.end;
  718. const savedQuery: NewQuery = {
  719. id: undefined,
  720. name: t('Vitals Performance Details'),
  721. query: 'event.type:transaction',
  722. projects: [],
  723. fields: [
  724. 'team_key_transaction',
  725. 'transaction',
  726. 'project',
  727. 'count_unique(user)',
  728. 'count()',
  729. `p50(${vitalName})`,
  730. `p75(${vitalName})`,
  731. `p95(${vitalName})`,
  732. getVitalDetailTablePoorStatusFunction(vitalName),
  733. getVitalDetailTableMehStatusFunction(vitalName),
  734. ],
  735. version: 2,
  736. yAxis: [`p75(${vitalName})`],
  737. };
  738. if (!query.statsPeriod && !hasStartAndEnd) {
  739. savedQuery.range = getDefaultStatsPeriod(organization);
  740. }
  741. savedQuery.orderby = decodeScalar(query.sort, '-count');
  742. const searchQuery = decodeScalar(query.query, '');
  743. savedQuery.query = prepareQueryForLandingPage(searchQuery, false);
  744. const eventView = EventView.fromNewQueryWithLocation(savedQuery, location);
  745. eventView.additionalConditions.addFilterValues('event.type', ['transaction']);
  746. eventView.additionalConditions.addFilterValues('has', [vitalName]);
  747. return eventView;
  748. }