data.tsx 26 KB

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