content.tsx 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. import {useCallback, useState} from 'react';
  2. import styled from '@emotion/styled';
  3. import type {Location} from 'history';
  4. import Feature from 'sentry/components/acl/feature';
  5. import {Alert} from 'sentry/components/alert';
  6. import {Button} from 'sentry/components/button';
  7. import ButtonBar from 'sentry/components/buttonBar';
  8. import FeedbackWidgetButton from 'sentry/components/feedback/widget/feedbackWidgetButton';
  9. import * as Layout from 'sentry/components/layouts/thirds';
  10. import {DatePageFilter} from 'sentry/components/organizations/datePageFilter';
  11. import {EnvironmentPageFilter} from 'sentry/components/organizations/environmentPageFilter';
  12. import PageFilterBar from 'sentry/components/organizations/pageFilterBar';
  13. import PageFiltersContainer from 'sentry/components/organizations/pageFilters/container';
  14. import {ProjectPageFilter} from 'sentry/components/organizations/projectPageFilter';
  15. import {PageHeadingQuestionTooltip} from 'sentry/components/pageHeadingQuestionTooltip';
  16. import {
  17. EAPSpanSearchQueryBuilder,
  18. SpanSearchQueryBuilder,
  19. } from 'sentry/components/performance/spanSearchQueryBuilder';
  20. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  21. import {t} from 'sentry/locale';
  22. import {space} from 'sentry/styles/space';
  23. import type {Confidence} from 'sentry/types/organization';
  24. import {DiscoverDatasets} from 'sentry/utils/discover/types';
  25. import {
  26. type AggregationKey,
  27. ALLOWED_EXPLORE_VISUALIZE_AGGREGATES,
  28. } from 'sentry/utils/fields';
  29. import {useLocation} from 'sentry/utils/useLocation';
  30. import {useNavigate} from 'sentry/utils/useNavigate';
  31. import useOrganization from 'sentry/utils/useOrganization';
  32. import usePageFilters from 'sentry/utils/usePageFilters';
  33. import {ExploreCharts} from 'sentry/views/explore/charts';
  34. import {
  35. SpanTagsProvider,
  36. useSpanTags,
  37. } from 'sentry/views/explore/contexts/spanTagsContext';
  38. import {useDataset} from 'sentry/views/explore/hooks/useDataset';
  39. import {useUserQuery} from 'sentry/views/explore/hooks/useUserQuery';
  40. import {ExploreTables} from 'sentry/views/explore/tables';
  41. import {ExploreToolbar} from 'sentry/views/explore/toolbar';
  42. import {useResultMode} from './hooks/useResultsMode';
  43. interface ExploreContentProps {
  44. location: Location;
  45. }
  46. function ExploreContentImpl({}: ExploreContentProps) {
  47. const location = useLocation();
  48. const navigate = useNavigate();
  49. const organization = useOrganization();
  50. const {selection} = usePageFilters();
  51. const [dataset] = useDataset();
  52. const [resultsMode] = useResultMode();
  53. const numberTags = useSpanTags('number');
  54. const stringTags = useSpanTags('string');
  55. const [userQuery, setUserQuery] = useUserQuery();
  56. const toolbarExtras = organization.features.includes('visibility-explore-dataset')
  57. ? ['dataset toggle' as const]
  58. : [];
  59. const switchToOldTraceExplorer = useCallback(() => {
  60. navigate({
  61. ...location,
  62. query: {
  63. ...location.query,
  64. view: 'trace',
  65. },
  66. });
  67. }, [location, navigate]);
  68. const [confidence, setConfidence] = useState<Confidence>(null);
  69. const [chartError, setChartError] = useState<string>('');
  70. const [tableError, setTableError] = useState<string>('');
  71. const maxPickableDays = 7;
  72. return (
  73. <SentryDocumentTitle title={t('Traces')} orgSlug={organization.slug}>
  74. <PageFiltersContainer maxPickableDays={maxPickableDays}>
  75. <Layout.Page>
  76. <Layout.Header>
  77. <Layout.HeaderContent>
  78. <Layout.Title>
  79. {t('Traces')}
  80. <PageHeadingQuestionTooltip
  81. docsUrl="https://github.com/getsentry/sentry/discussions/81239"
  82. title={t(
  83. 'Find problematic spans/traces or compute real-time metrics via aggregation.'
  84. )}
  85. linkLabel={t('Read the Discussion')}
  86. />
  87. </Layout.Title>
  88. </Layout.HeaderContent>
  89. <Layout.HeaderActions>
  90. <ButtonBar gap={1}>
  91. <Feature organization={organization} features="visibility-explore-admin">
  92. <Button onClick={switchToOldTraceExplorer} size="sm">
  93. {t('Switch to Old Trace Explore')}
  94. </Button>
  95. </Feature>
  96. <FeedbackWidgetButton />
  97. </ButtonBar>
  98. </Layout.HeaderActions>
  99. </Layout.Header>
  100. <Body>
  101. {confidence === 'low' && (
  102. <ConfidenceAlert type="warning" showIcon>
  103. {t(
  104. 'Your low sample count may impact the accuracy of this extrapolation. Edit your query or increase your sample rate.'
  105. )}
  106. </ConfidenceAlert>
  107. )}
  108. <TopSection>
  109. <StyledPageFilterBar condensed>
  110. <ProjectPageFilter />
  111. <EnvironmentPageFilter />
  112. <DatePageFilter
  113. defaultPeriod="7d"
  114. maxPickableDays={maxPickableDays}
  115. relativeOptions={({arbitraryOptions}) => ({
  116. ...arbitraryOptions,
  117. '1h': t('Last 1 hour'),
  118. '24h': t('Last 24 hours'),
  119. '7d': t('Last 7 days'),
  120. })}
  121. />
  122. </StyledPageFilterBar>
  123. {dataset === DiscoverDatasets.SPANS_INDEXED ? (
  124. <SpanSearchQueryBuilder
  125. projects={selection.projects}
  126. initialQuery={userQuery}
  127. onSearch={setUserQuery}
  128. searchSource="explore"
  129. />
  130. ) : (
  131. <EAPSpanSearchQueryBuilder
  132. projects={selection.projects}
  133. initialQuery={userQuery}
  134. onSearch={setUserQuery}
  135. searchSource="explore"
  136. getFilterTokenWarning={
  137. resultsMode === 'samples'
  138. ? key => {
  139. if (
  140. ALLOWED_EXPLORE_VISUALIZE_AGGREGATES.includes(
  141. key as AggregationKey
  142. )
  143. ) {
  144. return t(
  145. "This key won't affect the results because samples mode does not support aggregate functions"
  146. );
  147. }
  148. return undefined;
  149. }
  150. : undefined
  151. }
  152. supportedAggregates={ALLOWED_EXPLORE_VISUALIZE_AGGREGATES}
  153. numberTags={numberTags}
  154. stringTags={stringTags}
  155. />
  156. )}
  157. </TopSection>
  158. <ExploreToolbar extras={toolbarExtras} />
  159. <MainSection fullWidth>
  160. {(tableError || chartError) && (
  161. <Alert type="error" showIcon>
  162. {tableError || chartError}
  163. </Alert>
  164. )}
  165. <ExploreCharts
  166. query={userQuery}
  167. setConfidence={setConfidence}
  168. setError={setChartError}
  169. />
  170. <ExploreTables confidence={confidence} setError={setTableError} />
  171. </MainSection>
  172. </Body>
  173. </Layout.Page>
  174. </PageFiltersContainer>
  175. </SentryDocumentTitle>
  176. );
  177. }
  178. export function ExploreContent(props: ExploreContentProps) {
  179. const [dataset] = useDataset();
  180. return (
  181. <SpanTagsProvider dataset={dataset} enabled>
  182. <ExploreContentImpl {...props} />
  183. </SpanTagsProvider>
  184. );
  185. }
  186. const Body = styled(Layout.Body)`
  187. gap: ${space(2)};
  188. @media (min-width: ${p => p.theme.breakpoints.medium}) {
  189. grid-template-columns: 350px minmax(100px, auto);
  190. gap: ${space(2)};
  191. }
  192. @media (min-width: ${p => p.theme.breakpoints.xxlarge}) {
  193. grid-template-columns: 400px minmax(100px, auto);
  194. }
  195. `;
  196. const ConfidenceAlert = styled(Alert)`
  197. grid-column: 1/3;
  198. margin: 0;
  199. `;
  200. const TopSection = styled('div')`
  201. display: grid;
  202. gap: ${space(2)};
  203. grid-column: 1/3;
  204. margin-bottom: ${space(2)};
  205. @media (min-width: ${p => p.theme.breakpoints.large}) {
  206. grid-template-columns: minmax(350px, auto) 1fr;
  207. margin-bottom: 0;
  208. }
  209. @media (min-width: ${p => p.theme.breakpoints.xxlarge}) {
  210. grid-template-columns: minmax(400px, auto) 1fr;
  211. }
  212. `;
  213. const MainSection = styled(Layout.Main)`
  214. grid-column: 2/3;
  215. `;
  216. const StyledPageFilterBar = styled(PageFilterBar)`
  217. width: auto;
  218. `;