trace.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. import styled from '@emotion/styled';
  2. import Loading from 'sentry/components/loadingIndicator';
  3. import Placeholder from 'sentry/components/placeholder';
  4. import {IconSad} from 'sentry/icons';
  5. import {t} from 'sentry/locale';
  6. import {Organization} from 'sentry/types';
  7. import EventView from 'sentry/utils/discover/eventView';
  8. import {TraceError, TraceFullDetailed} from 'sentry/utils/performance/quickTrace/types';
  9. import useRouteAnalyticsParams from 'sentry/utils/routeAnalytics/useRouteAnalyticsParams';
  10. import {useLocation} from 'sentry/utils/useLocation';
  11. import useOrganization from 'sentry/utils/useOrganization';
  12. import useProjects from 'sentry/utils/useProjects';
  13. import TraceView, {
  14. StyledTracePanel,
  15. } from 'sentry/views/performance/traceDetails/traceView';
  16. import {hasTraceData} from 'sentry/views/performance/traceDetails/utils';
  17. import EmptyState from 'sentry/views/replays/detail/emptyState';
  18. import FluidHeight from 'sentry/views/replays/detail/layout/fluidHeight';
  19. import {
  20. useFetchTransactions,
  21. useTransactionData,
  22. } from 'sentry/views/replays/detail/trace/replayTransactionContext';
  23. import type {ReplayRecord} from 'sentry/views/replays/types';
  24. function TracesNotFound({performanceActive}: {performanceActive: boolean}) {
  25. // We want to send the 'trace_status' data if the project actively uses and has access to the performance monitoring.
  26. useRouteAnalyticsParams(performanceActive ? {trace_status: 'trace missing'} : {});
  27. return (
  28. <BorderedSection data-test-id="replay-details-trace-tab">
  29. <EmptyState>
  30. <p>{t('No traces found')}</p>
  31. </EmptyState>
  32. </BorderedSection>
  33. );
  34. }
  35. function TraceFound({
  36. organization,
  37. performanceActive,
  38. eventView,
  39. traces,
  40. orphanErrors,
  41. }: {
  42. eventView: EventView | null;
  43. organization: Organization;
  44. performanceActive: boolean;
  45. traces: TraceFullDetailed[] | null;
  46. orphanErrors?: TraceError[];
  47. }) {
  48. const location = useLocation();
  49. // We want to send the 'trace_status' data if the project actively uses and has access to the performance monitoring.
  50. useRouteAnalyticsParams(performanceActive ? {trace_status: 'success'} : {});
  51. return (
  52. <OverflowScrollBorderedSection>
  53. <TraceView
  54. meta={null}
  55. traces={traces || []}
  56. location={location}
  57. organization={organization}
  58. traceEventView={eventView!}
  59. traceSlug="Replay"
  60. orphanErrors={orphanErrors}
  61. />
  62. </OverflowScrollBorderedSection>
  63. );
  64. }
  65. type Props = {
  66. replayRecord: undefined | ReplayRecord;
  67. };
  68. function Trace({replayRecord}: Props) {
  69. const organization = useOrganization();
  70. const {projects} = useProjects();
  71. const {
  72. state: {didInit, errors, isFetching, traces, orphanErrors},
  73. eventView,
  74. } = useTransactionData();
  75. useFetchTransactions();
  76. if (!replayRecord || !didInit || (isFetching && !traces?.length)) {
  77. // Show the blank screen until we start fetching, thats when you get a spinner
  78. return (
  79. <StyledPlaceholder height="100%">
  80. {isFetching ? <Loading /> : null}
  81. </StyledPlaceholder>
  82. );
  83. }
  84. if (errors.length) {
  85. // Same style as <EmptyStateWarning>
  86. return (
  87. <BorderedSection>
  88. <EmptyState withIcon={false}>
  89. <IconSad legacySize="54px" />
  90. <p>{t('Unable to retrieve traces')}</p>
  91. </EmptyState>
  92. </BorderedSection>
  93. );
  94. }
  95. const project = projects.find(p => p.id === replayRecord.project_id);
  96. const hasPerformance = project?.firstTransactionEvent === true;
  97. const performanceActive =
  98. organization.features.includes('performance-view') && hasPerformance;
  99. if (!hasTraceData(traces, orphanErrors)) {
  100. return <TracesNotFound performanceActive={performanceActive} />;
  101. }
  102. return (
  103. <TraceFound
  104. performanceActive={performanceActive}
  105. organization={organization}
  106. eventView={eventView}
  107. traces={traces ?? []}
  108. orphanErrors={orphanErrors}
  109. />
  110. );
  111. }
  112. // This has the gray background, to match other loaders on Replay Details
  113. const StyledPlaceholder = styled(Placeholder)`
  114. border: 1px solid ${p => p.theme.border};
  115. border-radius: ${p => p.theme.borderRadius};
  116. `;
  117. // White background, to match the loaded component
  118. const BorderedSection = styled(FluidHeight)`
  119. border: 1px solid ${p => p.theme.border};
  120. border-radius: ${p => p.theme.borderRadius};
  121. `;
  122. const OverflowScrollBorderedSection = styled(BorderedSection)`
  123. overflow: scroll;
  124. ${StyledTracePanel} {
  125. border: none;
  126. }
  127. `;
  128. export default Trace;