trace.tsx 5.0 KB

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