trace.tsx 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. import {Fragment, useMemo} from 'react';
  2. import styled from '@emotion/styled';
  3. import type {Location} from 'history';
  4. import {SectionHeading} from 'sentry/components/charts/styles';
  5. import EventVitals from 'sentry/components/events/eventVitals';
  6. import Panel from 'sentry/components/panels/panel';
  7. import Placeholder from 'sentry/components/placeholder';
  8. import {t} from 'sentry/locale';
  9. import {space} from 'sentry/styles/space';
  10. import type {EventTransaction, Organization} from 'sentry/types';
  11. import {generateQueryWithTag} from 'sentry/utils';
  12. import type EventView from 'sentry/utils/discover/eventView';
  13. import {formatTagKey} from 'sentry/utils/discover/fields';
  14. import type {
  15. TraceFullDetailed,
  16. TraceSplitResults,
  17. } from 'sentry/utils/performance/quickTrace/types';
  18. import {WEB_VITAL_DETAILS} from 'sentry/utils/performance/vitals/constants';
  19. import type {UseApiQueryResult} from 'sentry/utils/queryClient';
  20. import type RequestError from 'sentry/utils/requestError/requestError';
  21. import Tags from 'sentry/views/discover/tags';
  22. import type {TraceTree} from 'sentry/views/performance/newTraceDetails/traceTree';
  23. import TraceWarnings from 'sentry/views/performance/newTraceDetails/traceWarnings';
  24. import {getTraceInfo} from '../../../traceDetails/utils';
  25. const WEB_VITALS = [
  26. WEB_VITAL_DETAILS['measurements.cls'],
  27. WEB_VITAL_DETAILS['measurements.lcp'],
  28. WEB_VITAL_DETAILS['measurements.ttfb'],
  29. WEB_VITAL_DETAILS['measurements.fcp'],
  30. WEB_VITAL_DETAILS['measurements.fid'],
  31. ];
  32. type TraceFooterProps = {
  33. location: Location;
  34. organization: Organization;
  35. rootEventResults: UseApiQueryResult<EventTransaction, RequestError>;
  36. traceEventView: EventView;
  37. traces: TraceSplitResults<TraceFullDetailed> | null;
  38. tree: TraceTree;
  39. };
  40. function NoWebVitals() {
  41. return (
  42. <div style={{flex: 1}}>
  43. <SectionHeading>{t('WebVitals')}</SectionHeading>
  44. <WebVitalsWrapper>
  45. {WEB_VITALS.map(detail => (
  46. <StyledPanel key={detail.name}>
  47. <div>{detail.name}</div>
  48. <div>{' \u2014 '}</div>
  49. </StyledPanel>
  50. ))}
  51. </WebVitalsWrapper>
  52. </div>
  53. );
  54. }
  55. function TraceDataLoading() {
  56. return (
  57. <TraceFooterWrapper>
  58. <div style={{flex: 1}}>
  59. <SectionHeading>{t('WebVitals')}</SectionHeading>
  60. <Fragment>
  61. <StyledPlaceholderVital key="title-1" />
  62. <StyledPlaceholderVital key="title-2" />
  63. <StyledPlaceholderVital key="title-3" />
  64. <StyledPlaceholderVital key="title-4" />
  65. <StyledPlaceholderVital key="title-5" />
  66. </Fragment>
  67. </div>
  68. <div style={{flex: 1}}>
  69. <SectionHeading>{t('Tag Summary')}</SectionHeading>
  70. <Fragment>
  71. <StyledPlaceholderTagTitle key="title-1" />
  72. <StyledPlaceholderTag key="bar-1" />
  73. <StyledPlaceholderTagTitle key="title-2" />
  74. <StyledPlaceholderTag key="bar-2" />
  75. <StyledPlaceholderTagTitle key="title-3" />
  76. <StyledPlaceholderTag key="bar-3" />
  77. </Fragment>
  78. </div>
  79. </TraceFooterWrapper>
  80. );
  81. }
  82. export function TraceLevelDetails(props: TraceFooterProps) {
  83. const treeType = useMemo(() => {
  84. return props.tree.shape;
  85. }, [props.tree]);
  86. if (!props.traces) {
  87. return <TraceDataLoading />;
  88. }
  89. const {data: rootEvent} = props.rootEventResults;
  90. const {transactions, orphan_errors} = props.traces;
  91. const traceInfo = getTraceInfo(transactions, orphan_errors);
  92. const orphanErrorsCount = traceInfo.trailingOrphansCount ?? 0;
  93. const transactionsCount = traceInfo.transactions.size ?? 0;
  94. const totalNumOfEvents = transactionsCount + orphanErrorsCount;
  95. const webVitals = Object.keys(rootEvent?.measurements ?? {})
  96. .filter(name => Boolean(WEB_VITAL_DETAILS[`measurements.${name}`]))
  97. .sort();
  98. return rootEvent ? (
  99. <Fragment>
  100. {treeType ? <TraceWarnings type={treeType} /> : null}
  101. <TraceFooterWrapper>
  102. {webVitals.length > 0 ? (
  103. <div style={{flex: 1}}>
  104. <EventVitals event={rootEvent} />
  105. </div>
  106. ) : (
  107. <NoWebVitals />
  108. )}
  109. <div style={{flex: 1}}>
  110. <Tags
  111. generateUrl={(key: string, value: string) => {
  112. const url = props.traceEventView.getResultsViewUrlTarget(
  113. props.organization.slug,
  114. false
  115. );
  116. url.query = generateQueryWithTag(url.query, {
  117. key: formatTagKey(key),
  118. value,
  119. });
  120. return url;
  121. }}
  122. totalValues={totalNumOfEvents}
  123. eventView={props.traceEventView}
  124. organization={props.organization}
  125. location={props.location}
  126. />
  127. </div>
  128. </TraceFooterWrapper>
  129. </Fragment>
  130. ) : null;
  131. }
  132. const TraceFooterWrapper = styled('div')`
  133. display: flex;
  134. gap: ${space(2)};
  135. `;
  136. const StyledPlaceholderTag = styled(Placeholder)`
  137. border-radius: ${p => p.theme.borderRadius};
  138. height: 16px;
  139. margin-bottom: ${space(1.5)};
  140. `;
  141. const StyledPlaceholderTagTitle = styled(Placeholder)`
  142. width: 100px;
  143. height: 12px;
  144. margin-bottom: ${space(0.5)};
  145. `;
  146. const StyledPlaceholderVital = styled(StyledPlaceholderTagTitle)`
  147. width: 100%;
  148. height: 50px;
  149. margin-bottom: ${space(0.5)};
  150. `;
  151. const StyledPanel = styled(Panel)`
  152. padding: ${space(1)} ${space(1.5)};
  153. margin-bottom: ${space(1)};
  154. width: 100%;
  155. `;
  156. const WebVitalsWrapper = styled('div')`
  157. display: flex;
  158. align-items: center;
  159. flex-direction: column;
  160. `;