data.tsx 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869
  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. isMetricsData: 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) && !isMetricsData) {
  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. // 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. // event.type is not a valid metric tag, so it will be added to the query only
  429. // in case the metric switch is disabled (for now).
  430. if (!isMetricsData) {
  431. eventView.additionalConditions.addFilterValues('event.type', ['transaction']);
  432. }
  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. isMetricsData: 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) && !isMetricsData) {
  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. // the query here is a user entered condition, no need to escape it
  489. conditions.setFilterValues(
  490. 'transaction',
  491. [`*${conditions.freeText.join(' ')}*`],
  492. false
  493. );
  494. conditions.freeText = [];
  495. }
  496. savedQuery.query = conditions.formatString();
  497. const eventView = EventView.fromNewQueryWithLocation(savedQuery, location);
  498. // event.type is not a valid metric tag, so it will be added to the query only
  499. // in case the metric switch is disabled (for now).
  500. if (!isMetricsData) {
  501. eventView.additionalConditions.addFilterValues('event.type', ['transaction']);
  502. }
  503. return eventView;
  504. }
  505. function generateMobilePerformanceEventView(
  506. location: Location,
  507. projects: Project[],
  508. genericEventView: EventView,
  509. isMetricsData: 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.app_start_cold)',
  519. 'p75(measurements.app_start_warm)',
  520. 'p75(measurements.frames_slow_rate)',
  521. 'p75(measurements.frames_frozen_rate)',
  522. ];
  523. // At this point, all projects are mobile projects.
  524. // If in addition to that, all projects are react-native projects,
  525. // then show the stall percentage as well.
  526. const projectIds = genericEventView.project;
  527. if (projectIds.length > 0 && projectIds[0] !== ALL_ACCESS_PROJECTS) {
  528. const selectedProjects = projects.filter(p =>
  529. projectIds.includes(parseInt(p.id, 10))
  530. );
  531. if (
  532. selectedProjects.length > 0 &&
  533. selectedProjects.every(project => project.platform === 'react-native')
  534. ) {
  535. // TODO(tonyx): remove these once the SDKs are ready
  536. fields.pop();
  537. fields.pop();
  538. fields.push('p75(measurements.stall_percentage)');
  539. }
  540. }
  541. const hasStartAndEnd = query.start && query.end;
  542. const savedQuery: NewQuery = {
  543. id: undefined,
  544. name: t('Performance'),
  545. query: 'event.type:transaction',
  546. projects: [],
  547. fields: [...fields, 'count_unique(user)', 'count_miserable(user)', 'user_misery()'],
  548. version: 2,
  549. };
  550. const widths = Array(savedQuery.fields.length).fill(COL_WIDTH_UNDEFINED);
  551. widths[savedQuery.fields.length - 1] = '110';
  552. savedQuery.widths = widths;
  553. if (!query.statsPeriod && !hasStartAndEnd) {
  554. savedQuery.range = DEFAULT_STATS_PERIOD;
  555. }
  556. savedQuery.orderby = decodeScalar(query.sort, '-tpm');
  557. const searchQuery = decodeScalar(query.query, '');
  558. const conditions = new MutableSearch(searchQuery);
  559. // This is not an override condition since we want the duration to appear in the search bar as a default.
  560. if (shouldAddDefaultConditions(location) && !isMetricsData) {
  561. conditions.setFilterValues('transaction.duration', ['<15m']);
  562. }
  563. // If there is a bare text search, we want to treat it as a search
  564. // on the transaction name.
  565. if (conditions.freeText.length > 0) {
  566. // the query here is a user entered condition, no need to escape it
  567. conditions.setFilterValues(
  568. 'transaction',
  569. [`*${conditions.freeText.join(' ')}*`],
  570. false
  571. );
  572. conditions.freeText = [];
  573. }
  574. savedQuery.query = conditions.formatString();
  575. const eventView = EventView.fromNewQueryWithLocation(savedQuery, location);
  576. // event.type is not a valid metric tag, so it will be added to the query only
  577. // in case the metric switch is disabled (for now).
  578. if (!isMetricsData) {
  579. eventView.additionalConditions.addFilterValues('event.type', ['transaction']);
  580. }
  581. return eventView;
  582. }
  583. function generateFrontendPageloadPerformanceEventView(
  584. location: Location,
  585. isMetricsData: boolean
  586. ): EventView {
  587. const {query} = location;
  588. const fields = [
  589. 'team_key_transaction',
  590. 'transaction',
  591. 'project',
  592. 'tpm()',
  593. 'p75(measurements.fcp)',
  594. 'p75(measurements.lcp)',
  595. 'p75(measurements.fid)',
  596. 'p75(measurements.cls)',
  597. 'count_unique(user)',
  598. 'count_miserable(user)',
  599. 'user_misery()',
  600. ];
  601. const hasStartAndEnd = query.start && query.end;
  602. const savedQuery: NewQuery = {
  603. id: undefined,
  604. name: t('Performance'),
  605. query: 'event.type:transaction',
  606. projects: [],
  607. fields,
  608. version: 2,
  609. };
  610. const widths = Array(savedQuery.fields.length).fill(COL_WIDTH_UNDEFINED);
  611. widths[savedQuery.fields.length - 1] = '110';
  612. savedQuery.widths = widths;
  613. if (!query.statsPeriod && !hasStartAndEnd) {
  614. savedQuery.range = DEFAULT_STATS_PERIOD;
  615. }
  616. savedQuery.orderby = decodeScalar(query.sort, '-tpm');
  617. const searchQuery = decodeScalar(query.query, '');
  618. const conditions = new MutableSearch(searchQuery);
  619. // This is not an override condition since we want the duration to appear in the search bar as a default.
  620. if (shouldAddDefaultConditions(location) && !isMetricsData) {
  621. conditions.setFilterValues('transaction.duration', ['<15m']);
  622. }
  623. // If there is a bare text search, we want to treat it as a search
  624. // on the transaction name.
  625. if (conditions.freeText.length > 0) {
  626. // the query here is a user entered condition, no need to escape it
  627. conditions.setFilterValues(
  628. 'transaction',
  629. [`*${conditions.freeText.join(' ')}*`],
  630. false
  631. );
  632. conditions.freeText = [];
  633. }
  634. savedQuery.query = conditions.formatString();
  635. const eventView = EventView.fromNewQueryWithLocation(savedQuery, location);
  636. // event.type and transaction.op are not valid metric tags, so they will be added to the query only
  637. // in case the metric switch is disabled (for now).
  638. if (!isMetricsData) {
  639. eventView.additionalConditions.addFilterValues('event.type', ['transaction']);
  640. eventView.additionalConditions.addFilterValues('transaction.op', ['pageload']);
  641. }
  642. return eventView;
  643. }
  644. function generateFrontendOtherPerformanceEventView(
  645. location: Location,
  646. isMetricsData: boolean
  647. ): EventView {
  648. const {query} = location;
  649. const fields = [
  650. 'team_key_transaction',
  651. 'transaction',
  652. 'project',
  653. 'transaction.op',
  654. 'tpm()',
  655. 'p50(transaction.duration)',
  656. 'p75(transaction.duration)',
  657. 'p95(transaction.duration)',
  658. 'count_unique(user)',
  659. 'count_miserable(user)',
  660. 'user_misery()',
  661. ];
  662. const hasStartAndEnd = query.start && query.end;
  663. const savedQuery: NewQuery = {
  664. id: undefined,
  665. name: t('Performance'),
  666. query: 'event.type:transaction',
  667. projects: [],
  668. fields,
  669. version: 2,
  670. };
  671. const widths = Array(savedQuery.fields.length).fill(COL_WIDTH_UNDEFINED);
  672. widths[savedQuery.fields.length - 1] = '110';
  673. savedQuery.widths = widths;
  674. if (!query.statsPeriod && !hasStartAndEnd) {
  675. savedQuery.range = DEFAULT_STATS_PERIOD;
  676. }
  677. savedQuery.orderby = decodeScalar(query.sort, '-tpm');
  678. const searchQuery = decodeScalar(query.query, '');
  679. const conditions = new MutableSearch(searchQuery);
  680. // This is not an override condition since we want the duration to appear in the search bar as a default.
  681. if (shouldAddDefaultConditions(location) && !isMetricsData) {
  682. conditions.setFilterValues('transaction.duration', ['<15m']);
  683. }
  684. // If there is a bare text search, we want to treat it as a search
  685. // on the transaction name.
  686. if (conditions.freeText.length > 0) {
  687. // the query here is a user entered condition, no need to escape it
  688. conditions.setFilterValues(
  689. 'transaction',
  690. [`*${conditions.freeText.join(' ')}*`],
  691. false
  692. );
  693. conditions.freeText = [];
  694. }
  695. savedQuery.query = conditions.formatString();
  696. const eventView = EventView.fromNewQueryWithLocation(savedQuery, location);
  697. // event.type and !transaction.op are not valid metric tags, so they will be added to the query only
  698. // in case the metric switch is disabled (for now).
  699. if (!isMetricsData) {
  700. eventView.additionalConditions.addFilterValues('event.type', ['transaction']);
  701. }
  702. return eventView;
  703. }
  704. export function generatePerformanceEventView(
  705. location: Location,
  706. projects: Project[],
  707. {isTrends = false, isMetricsData = false} = {}
  708. ) {
  709. const eventView = generateGenericPerformanceEventView(location, isMetricsData);
  710. if (isTrends) {
  711. return eventView;
  712. }
  713. const display = getCurrentLandingDisplay(location, projects, eventView);
  714. switch (display?.field) {
  715. case LandingDisplayField.FRONTEND_PAGELOAD:
  716. return generateFrontendPageloadPerformanceEventView(location, isMetricsData);
  717. case LandingDisplayField.FRONTEND_OTHER:
  718. return generateFrontendOtherPerformanceEventView(location, isMetricsData);
  719. case LandingDisplayField.BACKEND:
  720. return generateBackendPerformanceEventView(location, isMetricsData);
  721. case LandingDisplayField.MOBILE:
  722. return generateMobilePerformanceEventView(
  723. location,
  724. projects,
  725. eventView,
  726. isMetricsData
  727. );
  728. default:
  729. return eventView;
  730. }
  731. }
  732. export function generatePerformanceVitalDetailView(
  733. location: Location,
  734. isMetricsData: boolean
  735. ): EventView {
  736. const {query} = location;
  737. const vitalName = vitalNameFromLocation(location);
  738. const hasStartAndEnd = query.start && query.end;
  739. const savedQuery: NewQuery = {
  740. id: undefined,
  741. name: t('Vitals Performance Details'),
  742. query: 'event.type:transaction',
  743. projects: [],
  744. fields: [
  745. 'team_key_transaction',
  746. 'transaction',
  747. 'project',
  748. 'count_unique(user)',
  749. 'count()',
  750. `p50(${vitalName})`,
  751. `p75(${vitalName})`,
  752. `p95(${vitalName})`,
  753. getVitalDetailTablePoorStatusFunction(vitalName),
  754. getVitalDetailTableMehStatusFunction(vitalName),
  755. ],
  756. version: 2,
  757. };
  758. if (!query.statsPeriod && !hasStartAndEnd) {
  759. savedQuery.range = DEFAULT_STATS_PERIOD;
  760. }
  761. savedQuery.orderby = decodeScalar(query.sort, '-count');
  762. const searchQuery = decodeScalar(query.query, '');
  763. const conditions = new MutableSearch(searchQuery);
  764. // If there is a bare text search, we want to treat it as a search
  765. // on the transaction name.
  766. if (conditions.freeText.length > 0) {
  767. // the query here is a user entered condition, no need to escape it
  768. conditions.setFilterValues(
  769. 'transaction',
  770. [`*${conditions.freeText.join(' ')}*`],
  771. false
  772. );
  773. conditions.freeText = [];
  774. }
  775. savedQuery.query = conditions.formatString();
  776. const eventView = EventView.fromNewQueryWithLocation(savedQuery, location);
  777. // event.type and has are not valid metric tags, so they will be added to the query only
  778. // in case the metric switch is disabled (for now).
  779. if (!isMetricsData) {
  780. eventView.additionalConditions.addFilterValues('event.type', ['transaction']);
  781. eventView.additionalConditions.addFilterValues('has', [vitalName]);
  782. }
  783. return eventView;
  784. }