data.tsx 24 KB

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