data.tsx 24 KB

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