content.tsx 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. import {useMemo} from 'react';
  2. import styled from '@emotion/styled';
  3. import type {Location} from 'history';
  4. import omit from 'lodash/omit';
  5. import {LinkButton} from 'sentry/components/button';
  6. import {CompactSelect} from 'sentry/components/compactSelect';
  7. import * as Layout from 'sentry/components/layouts/thirds';
  8. import {DatePageFilter} from 'sentry/components/organizations/datePageFilter';
  9. import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
  10. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  11. import {normalizeDateTimeParams} from 'sentry/components/organizations/pageFilters/parse';
  12. import {TransactionSearchQueryBuilder} from 'sentry/components/performance/transactionSearchQueryBuilder';
  13. import {t} from 'sentry/locale';
  14. import {space} from 'sentry/styles/space';
  15. import type {Organization} from 'sentry/types/organization';
  16. import type {Project} from 'sentry/types/project';
  17. import {trackAnalytics} from 'sentry/utils/analytics';
  18. import {browserHistory} from 'sentry/utils/browserHistory';
  19. import type EventView from 'sentry/utils/discover/eventView';
  20. import {SavedQueryDatasets} from 'sentry/utils/discover/types';
  21. import type {WebVital} from 'sentry/utils/fields';
  22. import {decodeScalar} from 'sentry/utils/queryString';
  23. import projectSupportsReplay from 'sentry/utils/replays/projectSupportsReplay';
  24. import {useRoutes} from 'sentry/utils/useRoutes';
  25. import {hasDatasetSelector} from 'sentry/views/dashboards/utils';
  26. import {useDomainViewFilters} from 'sentry/views/insights/pages/useFilters';
  27. import {
  28. platformToPerformanceType,
  29. ProjectPerformanceType,
  30. } from 'sentry/views/performance/utils';
  31. import type {SpanOperationBreakdownFilter} from '../filter';
  32. import Filter, {filterToSearchConditions} from '../filter';
  33. import type {SetStateAction} from '../types';
  34. import EventsTable from './eventsTable';
  35. import type {EventsDisplayFilterName} from './utils';
  36. import {getEventsFilterOptions} from './utils';
  37. type Props = {
  38. eventView: EventView;
  39. eventsDisplayFilterName: EventsDisplayFilterName;
  40. location: Location;
  41. onChangeEventsDisplayFilter: (eventsDisplayFilterName: EventsDisplayFilterName) => void;
  42. onChangeSpanOperationBreakdownFilter: (newFilter: SpanOperationBreakdownFilter) => void;
  43. organization: Organization;
  44. projectId: string;
  45. projects: Project[];
  46. setError: SetStateAction<string | undefined>;
  47. spanOperationBreakdownFilter: SpanOperationBreakdownFilter;
  48. transactionName: string;
  49. percentileValues?: Record<EventsDisplayFilterName, number>;
  50. webVital?: WebVital;
  51. };
  52. export const TRANSACTIONS_LIST_TITLES: Readonly<string[]> = [
  53. t('event id'),
  54. t('user'),
  55. t('operation duration'),
  56. t('total duration'),
  57. t('trace id'),
  58. t('timestamp'),
  59. ];
  60. function EventsContent(props: Props) {
  61. const {
  62. location,
  63. organization,
  64. eventView: originalEventView,
  65. transactionName,
  66. spanOperationBreakdownFilter,
  67. webVital,
  68. setError,
  69. projectId,
  70. projects,
  71. } = props;
  72. const routes = useRoutes();
  73. const domainViewFilters = useDomainViewFilters();
  74. const {eventView, titles} = useMemo(() => {
  75. const eventViewClone = originalEventView.clone();
  76. const transactionsListTitles = TRANSACTIONS_LIST_TITLES.slice();
  77. const project = projects.find(p => p.id === projectId);
  78. const fields = [...eventViewClone.fields];
  79. if (webVital) {
  80. transactionsListTitles.splice(3, 0, webVital);
  81. }
  82. const spanOperationBreakdownConditions = filterToSearchConditions(
  83. spanOperationBreakdownFilter,
  84. location
  85. );
  86. if (spanOperationBreakdownConditions) {
  87. eventViewClone.query =
  88. `${eventViewClone.query} ${spanOperationBreakdownConditions}`.trim();
  89. transactionsListTitles.splice(2, 1, t('%s duration', spanOperationBreakdownFilter));
  90. }
  91. const platform = platformToPerformanceType(projects, eventViewClone.project);
  92. if (platform === ProjectPerformanceType.BACKEND) {
  93. const userIndex = transactionsListTitles.indexOf('user');
  94. if (userIndex > 0) {
  95. transactionsListTitles.splice(userIndex + 1, 0, 'http.method');
  96. fields.splice(userIndex + 1, 0, {field: 'http.method'});
  97. }
  98. }
  99. if (
  100. // only show for projects that already sent a profile
  101. // once we have a more compact design we will show this for
  102. // projects that support profiling as well
  103. project?.hasProfiles &&
  104. (organization.features.includes('profiling') ||
  105. organization.features.includes('continuous-profiling'))
  106. ) {
  107. transactionsListTitles.push(t('profile'));
  108. if (organization.features.includes('profiling')) {
  109. fields.push({field: 'profile.id'});
  110. }
  111. if (organization.features.includes('continuous-profiling')) {
  112. fields.push({field: 'profiler.id'});
  113. fields.push({field: 'thread.id'});
  114. fields.push({field: 'precise.start_ts'});
  115. fields.push({field: 'precise.finish_ts'});
  116. }
  117. }
  118. if (
  119. organization.features.includes('session-replay') &&
  120. project &&
  121. projectSupportsReplay(project)
  122. ) {
  123. transactionsListTitles.push(t('replay'));
  124. fields.push({field: 'replayId'});
  125. }
  126. eventViewClone.fields = fields;
  127. return {
  128. eventView: eventViewClone,
  129. titles: transactionsListTitles,
  130. };
  131. }, [
  132. originalEventView,
  133. location,
  134. organization,
  135. projects,
  136. projectId,
  137. spanOperationBreakdownFilter,
  138. webVital,
  139. ]);
  140. return (
  141. <Layout.Main fullWidth>
  142. <Search {...props} eventView={eventView} />
  143. <EventsTable
  144. eventView={eventView}
  145. organization={organization}
  146. routes={routes}
  147. location={location}
  148. setError={setError}
  149. columnTitles={titles}
  150. transactionName={transactionName}
  151. domainViewFilters={domainViewFilters}
  152. />
  153. </Layout.Main>
  154. );
  155. }
  156. function Search(props: Props) {
  157. const {
  158. eventView,
  159. location,
  160. organization,
  161. spanOperationBreakdownFilter,
  162. onChangeSpanOperationBreakdownFilter,
  163. eventsDisplayFilterName,
  164. onChangeEventsDisplayFilter,
  165. percentileValues,
  166. } = props;
  167. const handleSearch = (query: string) => {
  168. const queryParams = normalizeDateTimeParams({
  169. ...(location.query || {}),
  170. query,
  171. });
  172. // do not propagate pagination when making a new search
  173. const searchQueryParams = omit(queryParams, 'cursor');
  174. browserHistory.push({
  175. pathname: location.pathname,
  176. query: searchQueryParams,
  177. });
  178. };
  179. const query = decodeScalar(location.query.query, '');
  180. const eventsFilterOptions = getEventsFilterOptions(
  181. spanOperationBreakdownFilter,
  182. percentileValues
  183. );
  184. const handleDiscoverButtonClick = () => {
  185. trackAnalytics('performance_views.all_events.open_in_discover', {
  186. organization,
  187. });
  188. };
  189. const projectIds = useMemo(() => eventView.project?.slice(), [eventView.project]);
  190. return (
  191. <FilterActions>
  192. <Filter
  193. organization={organization}
  194. currentFilter={spanOperationBreakdownFilter}
  195. onChangeFilter={onChangeSpanOperationBreakdownFilter}
  196. />
  197. <PageFilterBar condensed>
  198. <EnvironmentPageFilter />
  199. <DatePageFilter />
  200. </PageFilterBar>
  201. <StyledSearchBarWrapper>
  202. <TransactionSearchQueryBuilder
  203. projects={projectIds}
  204. initialQuery={query}
  205. onSearch={handleSearch}
  206. searchSource="transaction_events"
  207. />
  208. </StyledSearchBarWrapper>
  209. <CompactSelect
  210. triggerProps={{prefix: t('Percentile')}}
  211. value={eventsDisplayFilterName}
  212. onChange={opt => onChangeEventsDisplayFilter(opt.value)}
  213. options={Object.entries(eventsFilterOptions).map(([name, filter]) => ({
  214. value: name as EventsDisplayFilterName,
  215. label: filter.label,
  216. }))}
  217. />
  218. <LinkButton
  219. to={eventView.getResultsViewUrlTarget(
  220. organization.slug,
  221. false,
  222. hasDatasetSelector(organization) ? SavedQueryDatasets.TRANSACTIONS : undefined
  223. )}
  224. onClick={handleDiscoverButtonClick}
  225. >
  226. {t('Open in Discover')}
  227. </LinkButton>
  228. </FilterActions>
  229. );
  230. }
  231. const FilterActions = styled('div')`
  232. display: grid;
  233. gap: ${space(2)};
  234. margin-bottom: ${space(2)};
  235. @media (min-width: ${p => p.theme.breakpoints.small}) {
  236. grid-template-columns: repeat(4, min-content);
  237. }
  238. @media (min-width: ${p => p.theme.breakpoints.xlarge}) {
  239. grid-template-columns: auto auto 1fr auto auto;
  240. }
  241. `;
  242. const StyledSearchBarWrapper = styled('div')`
  243. @media (min-width: ${p => p.theme.breakpoints.small}) {
  244. order: 1;
  245. grid-column: 1/6;
  246. }
  247. @media (min-width: ${p => p.theme.breakpoints.xlarge}) {
  248. order: initial;
  249. grid-column: auto;
  250. }
  251. `;
  252. export default EventsContent;