data.tsx 24 KB

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