data.tsx 25 KB

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