data.tsx 24 KB

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