data.tsx 25 KB

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