data.tsx 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824
  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, withStaticFilters) {
  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. WEB_VITAL_DETAILS[trendParameter.column] &&
  474. !organization.features.includes('performance-new-trends')
  475. ) {
  476. eventView.additionalConditions.addFilterValues('has', [trendParameter.column]);
  477. }
  478. }
  479. return eventView;
  480. }
  481. export function generateBackendPerformanceEventView(
  482. location: Location,
  483. withStaticFilters: boolean,
  484. organization: Organization
  485. ): EventView {
  486. const {query} = location;
  487. const fields = [
  488. 'team_key_transaction',
  489. 'http.method',
  490. 'transaction',
  491. 'transaction.op',
  492. 'project',
  493. 'tpm()',
  494. 'p50()',
  495. 'p95()',
  496. 'failure_rate()',
  497. 'apdex()',
  498. 'count_unique(user)',
  499. 'count_miserable(user)',
  500. 'user_misery()',
  501. ];
  502. const hasStartAndEnd = query.start && query.end;
  503. const savedQuery: NewQuery = {
  504. id: undefined,
  505. name: t('Performance'),
  506. query: 'event.type:transaction',
  507. projects: [],
  508. fields,
  509. version: 2,
  510. };
  511. const widths = Array(savedQuery.fields.length).fill(COL_WIDTH_UNDEFINED);
  512. widths[savedQuery.fields.length - 1] = '110';
  513. savedQuery.widths = widths;
  514. if (!query.statsPeriod && !hasStartAndEnd) {
  515. savedQuery.range = getDefaultStatsPeriod(organization);
  516. }
  517. savedQuery.orderby = decodeScalar(query.sort, '-tpm');
  518. const searchQuery = decodeScalar(query.query, '');
  519. savedQuery.query = prepareQueryForLandingPage(searchQuery, withStaticFilters);
  520. const eventView = EventView.fromNewQueryWithLocation(savedQuery, location);
  521. eventView.additionalConditions.addFilterValues('event.type', ['transaction']);
  522. return eventView;
  523. }
  524. export function generateMobilePerformanceEventView(
  525. location: Location,
  526. projects: Project[],
  527. genericEventView: EventView,
  528. withStaticFilters: boolean,
  529. organization: Organization
  530. ): EventView {
  531. const {query} = location;
  532. const fields = [
  533. 'team_key_transaction',
  534. 'transaction',
  535. 'transaction.op',
  536. 'project',
  537. 'tpm()',
  538. 'p75(measurements.frames_slow_rate)',
  539. 'p75(measurements.frames_frozen_rate)',
  540. ];
  541. if (organization.features.includes('mobile-vitals')) {
  542. fields.push('p75(measurements.time_to_initial_display)');
  543. }
  544. // At this point, all projects are mobile projects.
  545. // If in addition to that, all projects are react-native projects,
  546. // then show the stall percentage as well.
  547. const projectIds = genericEventView.project;
  548. if (projectIds.length > 0 && projectIds[0] !== ALL_ACCESS_PROJECTS) {
  549. const selectedProjects = projects.filter(p =>
  550. projectIds.includes(parseInt(p.id, 10))
  551. );
  552. if (
  553. selectedProjects.length > 0 &&
  554. selectedProjects.every(project => project.platform === 'react-native')
  555. ) {
  556. fields.push('p75(measurements.stall_percentage)');
  557. }
  558. }
  559. const hasStartAndEnd = query.start && query.end;
  560. const savedQuery: NewQuery = {
  561. id: undefined,
  562. name: t('Performance'),
  563. query: 'event.type:transaction',
  564. projects: [],
  565. fields: [...fields, 'count_unique(user)', 'count_miserable(user)', 'user_misery()'],
  566. version: 2,
  567. };
  568. const widths = Array(savedQuery.fields.length).fill(COL_WIDTH_UNDEFINED);
  569. widths[savedQuery.fields.length - 1] = '110';
  570. savedQuery.widths = widths;
  571. if (!query.statsPeriod && !hasStartAndEnd) {
  572. savedQuery.range = getDefaultStatsPeriod(organization);
  573. }
  574. savedQuery.orderby = decodeScalar(query.sort, '-tpm');
  575. const searchQuery = decodeScalar(query.query, '');
  576. savedQuery.query = prepareQueryForLandingPage(searchQuery, withStaticFilters);
  577. const eventView = EventView.fromNewQueryWithLocation(savedQuery, location);
  578. eventView.additionalConditions.addFilterValues('event.type', ['transaction']);
  579. return eventView;
  580. }
  581. function generateFrontendPageloadPerformanceEventView(
  582. location: Location,
  583. withStaticFilters: boolean,
  584. organization: Organization
  585. ): EventView {
  586. const {query} = location;
  587. const fields = [
  588. 'team_key_transaction',
  589. 'transaction',
  590. 'project',
  591. 'tpm()',
  592. 'p75(measurements.fcp)',
  593. 'p75(measurements.lcp)',
  594. 'p75(measurements.fid)',
  595. 'p75(measurements.cls)',
  596. 'count_unique(user)',
  597. 'count_miserable(user)',
  598. 'user_misery()',
  599. ];
  600. const hasStartAndEnd = query.start && query.end;
  601. const savedQuery: NewQuery = {
  602. id: undefined,
  603. name: t('Performance'),
  604. query: 'event.type:transaction',
  605. projects: [],
  606. fields,
  607. version: 2,
  608. };
  609. const widths = Array(savedQuery.fields.length).fill(COL_WIDTH_UNDEFINED);
  610. widths[savedQuery.fields.length - 1] = '110';
  611. savedQuery.widths = widths;
  612. if (!query.statsPeriod && !hasStartAndEnd) {
  613. savedQuery.range = getDefaultStatsPeriod(organization);
  614. }
  615. savedQuery.orderby = decodeScalar(query.sort, '-tpm');
  616. const searchQuery = decodeScalar(query.query, '');
  617. savedQuery.query = prepareQueryForLandingPage(searchQuery, withStaticFilters);
  618. const eventView = EventView.fromNewQueryWithLocation(savedQuery, location);
  619. eventView.additionalConditions.addFilterValues('event.type', ['transaction']);
  620. eventView.additionalConditions.addFilterValues('transaction.op', ['pageload']);
  621. return eventView;
  622. }
  623. export function generateFrontendOtherPerformanceEventView(
  624. location: Location,
  625. withStaticFilters: boolean,
  626. organization: Organization
  627. ): EventView {
  628. const {query} = location;
  629. const fields = [
  630. 'team_key_transaction',
  631. 'transaction',
  632. 'transaction.op',
  633. 'project',
  634. 'tpm()',
  635. 'p50(transaction.duration)',
  636. 'p75(transaction.duration)',
  637. 'p95(transaction.duration)',
  638. 'count_unique(user)',
  639. 'count_miserable(user)',
  640. 'user_misery()',
  641. ];
  642. const hasStartAndEnd = query.start && query.end;
  643. const savedQuery: NewQuery = {
  644. id: undefined,
  645. name: t('Performance'),
  646. query: 'event.type:transaction',
  647. projects: [],
  648. fields,
  649. version: 2,
  650. };
  651. const widths = Array(savedQuery.fields.length).fill(COL_WIDTH_UNDEFINED);
  652. widths[savedQuery.fields.length - 1] = '110';
  653. savedQuery.widths = widths;
  654. if (!query.statsPeriod && !hasStartAndEnd) {
  655. savedQuery.range = getDefaultStatsPeriod(organization);
  656. }
  657. savedQuery.orderby = decodeScalar(query.sort, '-tpm');
  658. const searchQuery = decodeScalar(query.query, '');
  659. savedQuery.query = prepareQueryForLandingPage(searchQuery, withStaticFilters);
  660. const eventView = EventView.fromNewQueryWithLocation(savedQuery, location);
  661. eventView.additionalConditions.addFilterValues('event.type', ['transaction']);
  662. return eventView;
  663. }
  664. export function generatePerformanceEventView(
  665. location: Location,
  666. projects: Project[],
  667. {isTrends = false, withStaticFilters = false} = {},
  668. organization: Organization
  669. ) {
  670. const eventView = generateGenericPerformanceEventView(
  671. location,
  672. withStaticFilters,
  673. organization
  674. );
  675. if (isTrends) {
  676. return eventView;
  677. }
  678. const display = getCurrentLandingDisplay(location, projects, eventView);
  679. switch (display?.field) {
  680. case LandingDisplayField.FRONTEND_PAGELOAD:
  681. return generateFrontendPageloadPerformanceEventView(
  682. location,
  683. withStaticFilters,
  684. organization
  685. );
  686. case LandingDisplayField.FRONTEND_OTHER:
  687. return generateFrontendOtherPerformanceEventView(
  688. location,
  689. withStaticFilters,
  690. organization
  691. );
  692. case LandingDisplayField.BACKEND:
  693. return generateBackendPerformanceEventView(
  694. location,
  695. withStaticFilters,
  696. organization
  697. );
  698. case LandingDisplayField.MOBILE:
  699. return generateMobilePerformanceEventView(
  700. location,
  701. projects,
  702. eventView,
  703. withStaticFilters,
  704. organization
  705. );
  706. default:
  707. return eventView;
  708. }
  709. }
  710. export function generatePerformanceVitalDetailView(
  711. location: Location,
  712. organization: Organization
  713. ): EventView {
  714. const {query} = location;
  715. const vitalName = vitalNameFromLocation(location);
  716. const hasStartAndEnd = query.start && query.end;
  717. const savedQuery: NewQuery = {
  718. id: undefined,
  719. name: t('Vitals Performance Details'),
  720. query: 'event.type:transaction',
  721. projects: [],
  722. fields: [
  723. 'team_key_transaction',
  724. 'transaction',
  725. 'project',
  726. 'count_unique(user)',
  727. 'count()',
  728. `p50(${vitalName})`,
  729. `p75(${vitalName})`,
  730. `p95(${vitalName})`,
  731. getVitalDetailTablePoorStatusFunction(vitalName),
  732. getVitalDetailTableMehStatusFunction(vitalName),
  733. ],
  734. version: 2,
  735. yAxis: [`p75(${vitalName})`],
  736. };
  737. if (!query.statsPeriod && !hasStartAndEnd) {
  738. savedQuery.range = getDefaultStatsPeriod(organization);
  739. }
  740. savedQuery.orderby = decodeScalar(query.sort, '-count');
  741. const searchQuery = decodeScalar(query.query, '');
  742. savedQuery.query = prepareQueryForLandingPage(searchQuery, false);
  743. const eventView = EventView.fromNewQueryWithLocation(savedQuery, location);
  744. eventView.additionalConditions.addFilterValues('event.type', ['transaction']);
  745. eventView.additionalConditions.addFilterValues('has', [vitalName]);
  746. return eventView;
  747. }