data.tsx 25 KB

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