data.tsx 24 KB

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