data.tsx 24 KB

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