index.tsx 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. import {Fragment, useMemo} from 'react';
  2. // eslint-disable-next-line no-restricted-imports
  3. import styled from '@emotion/styled';
  4. import {Observer} from 'mobx-react';
  5. import {Alert} from 'sentry/components/alert';
  6. import GuideAnchor from 'sentry/components/assistant/guideAnchor';
  7. import Panel from 'sentry/components/panels/panel';
  8. import SearchBar from 'sentry/components/searchBar';
  9. import {t, tn} from 'sentry/locale';
  10. import {space} from 'sentry/styles/space';
  11. import type {EventTransaction} from 'sentry/types/event';
  12. import type {Organization} from 'sentry/types/organization';
  13. import {trackAnalytics} from 'sentry/utils/analytics';
  14. import {isEmptyObject} from 'sentry/utils/object/isEmptyObject';
  15. import {QuickTraceContext} from 'sentry/utils/performance/quickTrace/quickTraceContext';
  16. import type {
  17. TraceError,
  18. TracePerformanceIssue,
  19. } from 'sentry/utils/performance/quickTrace/types';
  20. import {isTraceError} from 'sentry/utils/performance/quickTrace/utils';
  21. import withOrganization from 'sentry/utils/withOrganization';
  22. import Filter from './filter';
  23. import TraceErrorList from './traceErrorList';
  24. import TraceView from './traceView';
  25. import type {ParsedTraceType} from './types';
  26. import {getCumulativeAlertLevelFromErrors, parseTrace} from './utils';
  27. import WaterfallModel from './waterfallModel';
  28. type Props = {
  29. event: EventTransaction;
  30. organization: Organization;
  31. affectedSpanIds?: string[];
  32. };
  33. function TraceErrorAlerts({
  34. isLoading,
  35. errors,
  36. parsedTrace,
  37. performanceIssues,
  38. }: {
  39. errors: TraceError[] | undefined;
  40. isLoading: boolean;
  41. parsedTrace: ParsedTraceType;
  42. performanceIssues: TracePerformanceIssue[] | undefined;
  43. }) {
  44. if (isLoading) {
  45. return null;
  46. }
  47. const traceErrors: (TraceError | TracePerformanceIssue)[] = [];
  48. if (errors && errors.length > 0) {
  49. traceErrors.push(...errors);
  50. }
  51. if (performanceIssues && performanceIssues.length > 0) {
  52. traceErrors.push(...performanceIssues);
  53. }
  54. if (traceErrors.length === 0) {
  55. return null;
  56. }
  57. // This is intentional as unbalanced string formatters in `tn()` are problematic
  58. const label =
  59. traceErrors.length === 1
  60. ? t('There is an issue associated with this transaction event.')
  61. : tn(
  62. `There are %s issues associated with this transaction event.`,
  63. `There are %s issues associated with this transaction event.`,
  64. traceErrors.length
  65. );
  66. return (
  67. <AlertContainer>
  68. <Alert type={getCumulativeAlertLevelFromErrors(traceErrors)}>
  69. <ErrorLabel>{label}</ErrorLabel>
  70. <TraceErrorList
  71. trace={parsedTrace}
  72. errors={errors ?? []}
  73. performanceIssues={performanceIssues}
  74. />
  75. </Alert>
  76. </AlertContainer>
  77. );
  78. }
  79. function SpansInterface({event, affectedSpanIds, organization}: Props) {
  80. const parsedTrace = useMemo(() => parseTrace(event), [event]);
  81. const waterfallModel = useMemo(
  82. () => new WaterfallModel(event, affectedSpanIds),
  83. [event, affectedSpanIds]
  84. );
  85. const handleSpanFilter = (searchQuery: string) => {
  86. waterfallModel.querySpanSearch(searchQuery);
  87. trackAnalytics('performance_views.event_details.search_query', {
  88. organization,
  89. });
  90. };
  91. return (
  92. <Container hasErrors={!isEmptyObject(event.errors)}>
  93. <QuickTraceContext.Consumer>
  94. {quickTrace => {
  95. const errors: TraceError[] | undefined =
  96. quickTrace?.currentEvent && !isTraceError(quickTrace?.currentEvent)
  97. ? quickTrace?.currentEvent?.errors
  98. : undefined;
  99. const performance_issues: TracePerformanceIssue[] | undefined =
  100. quickTrace?.currentEvent && !isTraceError(quickTrace?.currentEvent)
  101. ? quickTrace?.currentEvent?.performance_issues
  102. : undefined;
  103. return (
  104. <Fragment>
  105. <TraceErrorAlerts
  106. isLoading={quickTrace?.isLoading ?? false}
  107. errors={errors}
  108. performanceIssues={performance_issues}
  109. parsedTrace={parsedTrace}
  110. />
  111. <Observer>
  112. {() => {
  113. return (
  114. <Search>
  115. <Filter
  116. operationNameCounts={waterfallModel.operationNameCounts}
  117. operationNameFilter={waterfallModel.operationNameFilters}
  118. toggleOperationNameFilter={
  119. waterfallModel.toggleOperationNameFilter
  120. }
  121. />
  122. <StyledSearchBar
  123. defaultQuery=""
  124. query={waterfallModel.searchQuery || ''}
  125. placeholder={t('Search for spans')}
  126. onSearch={handleSpanFilter}
  127. />
  128. </Search>
  129. );
  130. }}
  131. </Observer>
  132. <Panel>
  133. <Observer>
  134. {() => {
  135. return (
  136. <TraceView
  137. performanceIssues={performance_issues}
  138. waterfallModel={waterfallModel}
  139. organization={organization}
  140. />
  141. );
  142. }}
  143. </Observer>
  144. <GuideAnchorWrapper>
  145. <GuideAnchor target="span_tree" position="bottom" />
  146. </GuideAnchorWrapper>
  147. </Panel>
  148. </Fragment>
  149. );
  150. }}
  151. </QuickTraceContext.Consumer>
  152. </Container>
  153. );
  154. }
  155. const GuideAnchorWrapper = styled('div')`
  156. height: 0;
  157. width: 0;
  158. margin-left: 50%;
  159. `;
  160. const Container = styled('div')<{hasErrors: boolean}>`
  161. ${p =>
  162. p.hasErrors &&
  163. `
  164. padding: ${space(2)} 0;
  165. @media (min-width: ${p.theme.breakpoints.small}) {
  166. padding: ${space(3)} 0 0 0;
  167. }
  168. `}
  169. `;
  170. const Search = styled('div')`
  171. display: grid;
  172. gap: ${space(2)};
  173. grid-template-columns: max-content 1fr;
  174. width: 100%;
  175. margin-bottom: ${space(2)};
  176. `;
  177. const StyledSearchBar = styled(SearchBar)`
  178. flex-grow: 1;
  179. `;
  180. const AlertContainer = styled('div')`
  181. margin-bottom: ${space(1)};
  182. `;
  183. const ErrorLabel = styled('div')`
  184. margin-bottom: ${space(1)};
  185. `;
  186. export const Spans = withOrganization(SpansInterface);