data.tsx 28 KB

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