index.tsx 5.0 KB

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