data.tsx 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861
  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 isUsingLimitedSearch(location: Location, withStaticFilters: boolean) {
  376. const {query} = location;
  377. const mepSearchState = decodeScalar(query[METRIC_SEARCH_SETTING_PARAM], '');
  378. const mepSettingState = decodeScalar(query[METRIC_SETTING_PARAM], ''); // TODO: Can be removed since it's for dev ui only.
  379. return (
  380. withStaticFilters &&
  381. (mepSearchState === MEPState.metricsOnly || mepSettingState === MEPState.metricsOnly)
  382. );
  383. }
  384. function generateGenericPerformanceEventView(
  385. location: Location,
  386. withStaticFilters: boolean
  387. ): EventView {
  388. const {query} = location;
  389. const fields = [
  390. 'team_key_transaction',
  391. 'transaction',
  392. 'project',
  393. 'tpm()',
  394. 'p50()',
  395. 'p95()',
  396. 'failure_rate()',
  397. 'apdex()',
  398. 'count_unique(user)',
  399. 'count_miserable(user)',
  400. 'user_misery()',
  401. ];
  402. const hasStartAndEnd = query.start && query.end;
  403. const savedQuery: NewQuery = {
  404. id: undefined,
  405. name: t('Performance'),
  406. query: 'event.type:transaction',
  407. projects: [],
  408. fields,
  409. version: 2,
  410. };
  411. const widths = Array(savedQuery.fields.length).fill(COL_WIDTH_UNDEFINED);
  412. widths[savedQuery.fields.length - 1] = '110';
  413. savedQuery.widths = widths;
  414. if (!query.statsPeriod && !hasStartAndEnd) {
  415. savedQuery.range = DEFAULT_STATS_PERIOD;
  416. }
  417. savedQuery.orderby = decodeScalar(query.sort, '-tpm');
  418. const searchQuery = decodeScalar(query.query, '');
  419. const conditions = new MutableSearch(searchQuery);
  420. const isLimitedSearch = isUsingLimitedSearch(location, withStaticFilters);
  421. // If there is a bare text search, we want to treat it as a search
  422. // on the transaction name.
  423. if (conditions.freeText.length > 0) {
  424. const parsedFreeText = isLimitedSearch
  425. ? decodeScalar(conditions.freeText, '')
  426. : conditions.freeText.join(' ');
  427. if (isLimitedSearch) {
  428. // the query here is a user entered condition, no need to escape it
  429. conditions.setFilterValues('transaction', [`${parsedFreeText}`], false);
  430. } else {
  431. // the query here is a user entered condition, no need to escape it
  432. conditions.setFilterValues('transaction', [`*${parsedFreeText}*`], false);
  433. }
  434. conditions.freeText = [];
  435. }
  436. if (isLimitedSearch) {
  437. conditions.tokens = conditions.tokens.filter(
  438. token => token.key && TOKEN_KEYS_SUPPORTED_IN_LIMITED_SEARCH.includes(token.key)
  439. );
  440. }
  441. savedQuery.query = conditions.formatString();
  442. const eventView = EventView.fromNewQueryWithLocation(savedQuery, location);
  443. eventView.additionalConditions.addFilterValues('event.type', ['transaction']);
  444. if (query.trendParameter) {
  445. // projects and projectIds are not necessary here since trendParameter will always
  446. // be present in location and will not be determined based on the project type
  447. const trendParameter = getCurrentTrendParameter(location, [], []);
  448. if (WEB_VITAL_DETAILS[trendParameter.column]) {
  449. eventView.additionalConditions.addFilterValues('has', [trendParameter.column]);
  450. }
  451. }
  452. return eventView;
  453. }
  454. function generateBackendPerformanceEventView(
  455. location: Location,
  456. withStaticFilters: boolean
  457. ): EventView {
  458. const {query} = location;
  459. const fields = [
  460. 'team_key_transaction',
  461. 'transaction',
  462. 'project',
  463. 'transaction.op',
  464. 'http.method',
  465. 'tpm()',
  466. 'p50()',
  467. 'p95()',
  468. 'failure_rate()',
  469. 'apdex()',
  470. 'count_unique(user)',
  471. 'count_miserable(user)',
  472. 'user_misery()',
  473. ];
  474. const hasStartAndEnd = query.start && query.end;
  475. const savedQuery: NewQuery = {
  476. id: undefined,
  477. name: t('Performance'),
  478. query: 'event.type:transaction',
  479. projects: [],
  480. fields,
  481. version: 2,
  482. };
  483. const widths = Array(savedQuery.fields.length).fill(COL_WIDTH_UNDEFINED);
  484. widths[savedQuery.fields.length - 1] = '110';
  485. savedQuery.widths = widths;
  486. if (!query.statsPeriod && !hasStartAndEnd) {
  487. savedQuery.range = DEFAULT_STATS_PERIOD;
  488. }
  489. savedQuery.orderby = decodeScalar(query.sort, '-tpm');
  490. const searchQuery = decodeScalar(query.query, '');
  491. const conditions = new MutableSearch(searchQuery);
  492. const isLimitedSearch = isUsingLimitedSearch(location, withStaticFilters);
  493. // If there is a bare text search, we want to treat it as a search
  494. // on the transaction name.
  495. if (conditions.freeText.length > 0) {
  496. const parsedFreeText = isLimitedSearch
  497. ? decodeScalar(conditions.freeText, '')
  498. : conditions.freeText.join(' ');
  499. if (isLimitedSearch) {
  500. // the query here is a user entered condition, no need to escape it
  501. conditions.setFilterValues('transaction', [`${parsedFreeText}`], false);
  502. } else {
  503. // the query here is a user entered condition, no need to escape it
  504. conditions.setFilterValues('transaction', [`*${parsedFreeText}*`], false);
  505. }
  506. conditions.freeText = [];
  507. }
  508. savedQuery.query = conditions.formatString();
  509. const eventView = EventView.fromNewQueryWithLocation(savedQuery, location);
  510. eventView.additionalConditions.addFilterValues('event.type', ['transaction']);
  511. return eventView;
  512. }
  513. function generateMobilePerformanceEventView(
  514. location: Location,
  515. projects: Project[],
  516. genericEventView: EventView,
  517. withStaticFilters: boolean
  518. ): EventView {
  519. const {query} = location;
  520. const fields = [
  521. 'team_key_transaction',
  522. 'transaction',
  523. 'project',
  524. 'transaction.op',
  525. 'tpm()',
  526. 'p75(measurements.frames_slow_rate)',
  527. 'p75(measurements.frames_frozen_rate)',
  528. ];
  529. // At this point, all projects are mobile projects.
  530. // If in addition to that, all projects are react-native projects,
  531. // then show the stall percentage as well.
  532. const projectIds = genericEventView.project;
  533. if (projectIds.length > 0 && projectIds[0] !== ALL_ACCESS_PROJECTS) {
  534. const selectedProjects = projects.filter(p =>
  535. projectIds.includes(parseInt(p.id, 10))
  536. );
  537. if (
  538. selectedProjects.length > 0 &&
  539. selectedProjects.every(project => project.platform === 'react-native')
  540. ) {
  541. fields.push('p75(measurements.stall_percentage)');
  542. }
  543. }
  544. const hasStartAndEnd = query.start && query.end;
  545. const savedQuery: NewQuery = {
  546. id: undefined,
  547. name: t('Performance'),
  548. query: 'event.type:transaction',
  549. projects: [],
  550. fields: [...fields, 'count_unique(user)', 'count_miserable(user)', 'user_misery()'],
  551. version: 2,
  552. };
  553. const widths = Array(savedQuery.fields.length).fill(COL_WIDTH_UNDEFINED);
  554. widths[savedQuery.fields.length - 1] = '110';
  555. savedQuery.widths = widths;
  556. if (!query.statsPeriod && !hasStartAndEnd) {
  557. savedQuery.range = DEFAULT_STATS_PERIOD;
  558. }
  559. savedQuery.orderby = decodeScalar(query.sort, '-tpm');
  560. const searchQuery = decodeScalar(query.query, '');
  561. const conditions = new MutableSearch(searchQuery);
  562. const isLimitedSearch = isUsingLimitedSearch(location, withStaticFilters);
  563. // If there is a bare text search, we want to treat it as a search
  564. // on the transaction name.
  565. if (conditions.freeText.length > 0) {
  566. const parsedFreeText = isLimitedSearch
  567. ? // pick first element to search transactions by name
  568. decodeScalar(conditions.freeText, '')
  569. : conditions.freeText.join(' ');
  570. if (isLimitedSearch) {
  571. // the query here is a user entered condition, no need to escape it
  572. conditions.setFilterValues('transaction', [`${parsedFreeText}`], false);
  573. } else {
  574. // the query here is a user entered condition, no need to escape it
  575. conditions.setFilterValues('transaction', [`*${parsedFreeText}*`], false);
  576. }
  577. conditions.freeText = [];
  578. }
  579. savedQuery.query = conditions.formatString();
  580. const eventView = EventView.fromNewQueryWithLocation(savedQuery, location);
  581. eventView.additionalConditions.addFilterValues('event.type', ['transaction']);
  582. return eventView;
  583. }
  584. function generateFrontendPageloadPerformanceEventView(
  585. location: Location,
  586. withStaticFilters: boolean
  587. ): EventView {
  588. const {query} = location;
  589. const fields = [
  590. 'team_key_transaction',
  591. 'transaction',
  592. 'project',
  593. 'tpm()',
  594. 'p75(measurements.fcp)',
  595. 'p75(measurements.lcp)',
  596. 'p75(measurements.fid)',
  597. 'p75(measurements.cls)',
  598. 'count_unique(user)',
  599. 'count_miserable(user)',
  600. 'user_misery()',
  601. ];
  602. const hasStartAndEnd = query.start && query.end;
  603. const savedQuery: NewQuery = {
  604. id: undefined,
  605. name: t('Performance'),
  606. query: 'event.type:transaction',
  607. projects: [],
  608. fields,
  609. version: 2,
  610. };
  611. const widths = Array(savedQuery.fields.length).fill(COL_WIDTH_UNDEFINED);
  612. widths[savedQuery.fields.length - 1] = '110';
  613. savedQuery.widths = widths;
  614. if (!query.statsPeriod && !hasStartAndEnd) {
  615. savedQuery.range = DEFAULT_STATS_PERIOD;
  616. }
  617. savedQuery.orderby = decodeScalar(query.sort, '-tpm');
  618. const searchQuery = decodeScalar(query.query, '');
  619. const conditions = new MutableSearch(searchQuery);
  620. const isLimitedSearch = isUsingLimitedSearch(location, withStaticFilters);
  621. // If there is a bare text search, we want to treat it as a search
  622. // on the transaction name.
  623. if (conditions.freeText.length > 0) {
  624. const parsedFreeText = isLimitedSearch
  625. ? // pick first element to search transactions by name
  626. decodeScalar(conditions.freeText, '')
  627. : conditions.freeText.join(' ');
  628. if (isLimitedSearch) {
  629. // the query here is a user entered condition, no need to escape it
  630. conditions.setFilterValues('transaction', [`${parsedFreeText}`], false);
  631. } else {
  632. // the query here is a user entered condition, no need to escape it
  633. conditions.setFilterValues('transaction', [`*${parsedFreeText}*`], false);
  634. }
  635. conditions.freeText = [];
  636. }
  637. savedQuery.query = conditions.formatString();
  638. const eventView = EventView.fromNewQueryWithLocation(savedQuery, location);
  639. eventView.additionalConditions.addFilterValues('event.type', ['transaction']);
  640. eventView.additionalConditions.addFilterValues('transaction.op', ['pageload']);
  641. return eventView;
  642. }
  643. function generateFrontendOtherPerformanceEventView(
  644. location: Location,
  645. withStaticFilters: boolean
  646. ): EventView {
  647. const {query} = location;
  648. const fields = [
  649. 'team_key_transaction',
  650. 'transaction',
  651. 'project',
  652. 'transaction.op',
  653. 'tpm()',
  654. 'p50(transaction.duration)',
  655. 'p75(transaction.duration)',
  656. 'p95(transaction.duration)',
  657. 'count_unique(user)',
  658. 'count_miserable(user)',
  659. 'user_misery()',
  660. ];
  661. const hasStartAndEnd = query.start && query.end;
  662. const savedQuery: NewQuery = {
  663. id: undefined,
  664. name: t('Performance'),
  665. query: 'event.type:transaction',
  666. projects: [],
  667. fields,
  668. version: 2,
  669. };
  670. const widths = Array(savedQuery.fields.length).fill(COL_WIDTH_UNDEFINED);
  671. widths[savedQuery.fields.length - 1] = '110';
  672. savedQuery.widths = widths;
  673. if (!query.statsPeriod && !hasStartAndEnd) {
  674. savedQuery.range = DEFAULT_STATS_PERIOD;
  675. }
  676. savedQuery.orderby = decodeScalar(query.sort, '-tpm');
  677. const searchQuery = decodeScalar(query.query, '');
  678. const conditions = new MutableSearch(searchQuery);
  679. const isLimitedSearch = isUsingLimitedSearch(location, withStaticFilters);
  680. // If there is a bare text search, we want to treat it as a search
  681. // on the transaction name.
  682. if (conditions.freeText.length > 0 && !isLimitedSearch) {
  683. const parsedFreeText = isLimitedSearch
  684. ? // pick first element to search transactions by name
  685. decodeScalar(conditions.freeText, '')
  686. : conditions.freeText.join(' ');
  687. if (isLimitedSearch) {
  688. // the query here is a user entered condition, no need to escape it
  689. conditions.setFilterValues('transaction', [`${parsedFreeText}`], false);
  690. } else {
  691. // the query here is a user entered condition, no need to escape it
  692. conditions.setFilterValues('transaction', [`*${parsedFreeText}*`], false);
  693. }
  694. conditions.freeText = [];
  695. }
  696. savedQuery.query = conditions.formatString();
  697. const eventView = EventView.fromNewQueryWithLocation(savedQuery, location);
  698. eventView.additionalConditions.addFilterValues('event.type', ['transaction']);
  699. return eventView;
  700. }
  701. export function generatePerformanceEventView(
  702. location: Location,
  703. projects: Project[],
  704. {isTrends = false, withStaticFilters = false} = {}
  705. ) {
  706. const eventView = generateGenericPerformanceEventView(location, withStaticFilters);
  707. if (isTrends) {
  708. return eventView;
  709. }
  710. const display = getCurrentLandingDisplay(location, projects, eventView);
  711. switch (display?.field) {
  712. case LandingDisplayField.FRONTEND_PAGELOAD:
  713. return generateFrontendPageloadPerformanceEventView(location, withStaticFilters);
  714. case LandingDisplayField.FRONTEND_OTHER:
  715. return generateFrontendOtherPerformanceEventView(location, withStaticFilters);
  716. case LandingDisplayField.BACKEND:
  717. return generateBackendPerformanceEventView(location, withStaticFilters);
  718. case LandingDisplayField.MOBILE:
  719. return generateMobilePerformanceEventView(
  720. location,
  721. projects,
  722. eventView,
  723. withStaticFilters
  724. );
  725. default:
  726. return eventView;
  727. }
  728. }
  729. export function generatePerformanceVitalDetailView(location: Location): EventView {
  730. const {query} = location;
  731. const vitalName = vitalNameFromLocation(location);
  732. const hasStartAndEnd = query.start && query.end;
  733. const savedQuery: NewQuery = {
  734. id: undefined,
  735. name: t('Vitals Performance Details'),
  736. query: 'event.type:transaction',
  737. projects: [],
  738. fields: [
  739. 'team_key_transaction',
  740. 'transaction',
  741. 'project',
  742. 'count_unique(user)',
  743. 'count()',
  744. `p50(${vitalName})`,
  745. `p75(${vitalName})`,
  746. `p95(${vitalName})`,
  747. getVitalDetailTablePoorStatusFunction(vitalName),
  748. getVitalDetailTableMehStatusFunction(vitalName),
  749. ],
  750. version: 2,
  751. yAxis: [`p75(${vitalName})`],
  752. };
  753. if (!query.statsPeriod && !hasStartAndEnd) {
  754. savedQuery.range = DEFAULT_STATS_PERIOD;
  755. }
  756. savedQuery.orderby = decodeScalar(query.sort, '-count');
  757. const searchQuery = decodeScalar(query.query, '');
  758. const conditions = new MutableSearch(searchQuery);
  759. // If there is a bare text search, we want to treat it as a search
  760. // on the transaction name.
  761. if (conditions.freeText.length > 0) {
  762. // the query here is a user entered condition, no need to escape it
  763. conditions.setFilterValues(
  764. 'transaction',
  765. [`*${conditions.freeText.join(' ')}*`],
  766. false
  767. );
  768. conditions.freeText = [];
  769. }
  770. conditions.setFilterValues('event.type', ['transaction']);
  771. savedQuery.query = conditions.formatString();
  772. const eventView = EventView.fromNewQueryWithLocation(savedQuery, location);
  773. eventView.additionalConditions.addFilterValues('event.type', ['transaction']);
  774. eventView.additionalConditions.addFilterValues('has', [vitalName]);
  775. return eventView;
  776. }