data.tsx 25 KB

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