data.tsx 26 KB

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