trace.tsx 4.0 KB

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