data.tsx 27 KB

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