content.tsx 8.8 KB

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