aggregateSpanDetail.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. import styled from '@emotion/styled';
  2. import type {Location} from 'history';
  3. import Link from 'sentry/components/links/link';
  4. import {t} from 'sentry/locale';
  5. import {space} from 'sentry/styles/space';
  6. import type {Organization, Project} from 'sentry/types';
  7. import type {AggregateEventTransaction} from 'sentry/types/event';
  8. import EventView from 'sentry/utils/discover/eventView';
  9. import {generateLinkToEventInTraceView} from 'sentry/utils/discover/urls';
  10. import {formatPercentage, getDuration} from 'sentry/utils/formatters';
  11. import type {
  12. QuickTraceEvent,
  13. TraceErrorOrIssue,
  14. } from 'sentry/utils/performance/quickTrace/types';
  15. import {useLocation} from 'sentry/utils/useLocation';
  16. import useProjects from 'sentry/utils/useProjects';
  17. import type {AggregateSpanType, ParsedTraceType} from './types';
  18. type Props = {
  19. childTransactions: QuickTraceEvent[] | null;
  20. event: Readonly<AggregateEventTransaction>;
  21. isRoot: boolean;
  22. organization: Organization;
  23. relatedErrors: TraceErrorOrIssue[] | null;
  24. resetCellMeasureCache: () => void;
  25. scrollToHash: (hash: string) => void;
  26. span: AggregateSpanType;
  27. trace: Readonly<ParsedTraceType>;
  28. };
  29. function renderSpanSamples(
  30. aggSpan: AggregateSpanType,
  31. project: Project | undefined,
  32. location: Location,
  33. organization: Organization
  34. ) {
  35. if (!project) {
  36. return null;
  37. }
  38. return aggSpan.samples?.map(({transaction, span, trace, timestamp}, index) => (
  39. <Link
  40. key={`${transaction}-${span}`}
  41. to={generateLinkToEventInTraceView({
  42. organization,
  43. eventSlug: `${project.slug}:${transaction}`,
  44. dataRow: {id: transaction, trace, timestamp},
  45. location,
  46. eventView: EventView.fromLocation(location),
  47. spanId: span,
  48. })}
  49. >{`${span}${index < aggSpan.samples.length - 1 ? ', ' : ''}`}</Link>
  50. ));
  51. }
  52. function AggregateSpanDetail({span, organization}: Props) {
  53. const location = useLocation();
  54. const {projects} = useProjects();
  55. const project = projects.find(p => p.id === location.query.project);
  56. const frequency = span?.frequency;
  57. const avgDuration = span?.timestamp - span?.start_timestamp;
  58. return (
  59. <SpanDetailContainer
  60. data-component="span-detail"
  61. onClick={event => {
  62. // prevent toggling the span detail
  63. event.stopPropagation();
  64. }}
  65. >
  66. <SpanDetails>
  67. <table className="table key-value">
  68. <tbody>
  69. <Row title={t('Avg Duration')}>{getDuration(avgDuration)}</Row>
  70. <Row title={t('Frequency')}>{frequency && formatPercentage(frequency)}</Row>
  71. <Row title={t('Span Samples')}>
  72. {renderSpanSamples(span, project, location, organization)}
  73. </Row>
  74. </tbody>
  75. </table>
  76. </SpanDetails>
  77. </SpanDetailContainer>
  78. );
  79. }
  80. export default AggregateSpanDetail;
  81. export function Row({
  82. title,
  83. keep,
  84. children,
  85. prefix,
  86. extra = null,
  87. }: {
  88. children: React.ReactNode;
  89. title: JSX.Element | string | null;
  90. extra?: React.ReactNode;
  91. keep?: boolean;
  92. prefix?: JSX.Element;
  93. }) {
  94. if (!keep && !children) {
  95. return null;
  96. }
  97. return (
  98. <tr>
  99. <td className="key">
  100. <Flex>
  101. {prefix}
  102. {title}
  103. </Flex>
  104. </td>
  105. <ValueTd className="value">
  106. <ValueRow>
  107. <StyledPre>
  108. <span className="val-string">{children}</span>
  109. </StyledPre>
  110. <ButtonContainer>{extra}</ButtonContainer>
  111. </ValueRow>
  112. </ValueTd>
  113. </tr>
  114. );
  115. }
  116. export const SpanDetailContainer = styled('div')`
  117. border-bottom: 1px solid ${p => p.theme.border};
  118. cursor: auto;
  119. `;
  120. const ValueTd = styled('td')`
  121. position: relative;
  122. `;
  123. const Flex = styled('div')`
  124. display: flex;
  125. align-items: center;
  126. `;
  127. const ValueRow = styled('div')`
  128. display: grid;
  129. grid-template-columns: auto min-content;
  130. gap: ${space(1)};
  131. border-radius: 4px;
  132. background-color: ${p => p.theme.surface200};
  133. margin: 2px;
  134. `;
  135. const StyledPre = styled('pre')`
  136. margin: 0 !important;
  137. background-color: transparent !important;
  138. `;
  139. const ButtonContainer = styled('div')`
  140. padding: 8px 10px;
  141. `;
  142. export const SpanDetails = styled('div')`
  143. padding: ${space(2)};
  144. table.table.key-value td.key {
  145. max-width: 280px;
  146. }
  147. `;