groupingVariant.tsx 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. import {Component} from 'react';
  2. import styled from '@emotion/styled';
  3. import capitalize from 'lodash/capitalize';
  4. import KeyValueList from 'sentry/components/events/interfaces/keyValueList';
  5. import {RawSpanType} from 'sentry/components/events/interfaces/spans/types';
  6. import QuestionTooltip from 'sentry/components/questionTooltip';
  7. import {SegmentedControl} from 'sentry/components/segmentedControl';
  8. import {Tooltip} from 'sentry/components/tooltip';
  9. import {IconCheckmark, IconClose} from 'sentry/icons';
  10. import {t} from 'sentry/locale';
  11. import {space} from 'sentry/styles/space';
  12. import {
  13. EntrySpans,
  14. Event,
  15. EventGroupComponent,
  16. EventGroupVariant,
  17. EventGroupVariantType,
  18. } from 'sentry/types';
  19. import GroupingComponent from './groupingComponent';
  20. import {hasNonContributingComponent} from './utils';
  21. type Props = {
  22. event: Event;
  23. showGroupingConfig: boolean;
  24. variant: EventGroupVariant;
  25. };
  26. type State = {
  27. showNonContributing: boolean;
  28. };
  29. type VariantData = [string, React.ReactNode][];
  30. function addFingerprintInfo(data: VariantData, variant: EventGroupVariant) {
  31. if ('matched_rule' in variant) {
  32. data.push([
  33. t('Fingerprint rule'),
  34. <TextWithQuestionTooltip key="type">
  35. {variant.matched_rule}
  36. <QuestionTooltip
  37. size="xs"
  38. position="top"
  39. title={t('The server-side fingerprinting rule that produced the fingerprint.')}
  40. />
  41. </TextWithQuestionTooltip>,
  42. ]);
  43. }
  44. if ('values' in variant) {
  45. data.push([t('Fingerprint values'), variant.values]);
  46. }
  47. if ('client_values' in variant) {
  48. data.push([
  49. t('Client fingerprint values'),
  50. <TextWithQuestionTooltip key="type">
  51. {variant.client_values}
  52. <QuestionTooltip
  53. size="xs"
  54. position="top"
  55. title={t(
  56. 'The client sent a fingerprint that was overridden by a server-side fingerprinting rule.'
  57. )}
  58. />
  59. </TextWithQuestionTooltip>,
  60. ]);
  61. }
  62. }
  63. class GroupVariant extends Component<Props, State> {
  64. state: State = {
  65. showNonContributing: false,
  66. };
  67. getVariantData(): [VariantData, EventGroupComponent | undefined] {
  68. const {event, variant, showGroupingConfig} = this.props;
  69. const data: VariantData = [];
  70. let component: EventGroupComponent | undefined;
  71. if (!this.state.showNonContributing && variant.hash === null) {
  72. return [data, component];
  73. }
  74. if (variant.hash !== null) {
  75. data.push([
  76. t('Hash'),
  77. <TextWithQuestionTooltip key="hash">
  78. <Hash>{variant.hash}</Hash>
  79. <QuestionTooltip
  80. size="xs"
  81. position="top"
  82. title={t('Events with the same hash are grouped together')}
  83. />
  84. </TextWithQuestionTooltip>,
  85. ]);
  86. }
  87. if (variant.hashMismatch) {
  88. data.push([
  89. t('Hash mismatch'),
  90. t('hashing algorithm produced a hash that does not match the event'),
  91. ]);
  92. }
  93. switch (variant.type) {
  94. case EventGroupVariantType.COMPONENT:
  95. component = variant.component;
  96. data.push([
  97. t('Type'),
  98. <TextWithQuestionTooltip key="type">
  99. {variant.type}
  100. <QuestionTooltip
  101. size="xs"
  102. position="top"
  103. title={t(
  104. 'Uses a complex grouping algorithm taking event data into account'
  105. )}
  106. />
  107. </TextWithQuestionTooltip>,
  108. ]);
  109. if (showGroupingConfig && variant.config?.id) {
  110. data.push([t('Grouping Config'), variant.config.id]);
  111. }
  112. break;
  113. case EventGroupVariantType.CUSTOM_FINGERPRINT:
  114. data.push([
  115. t('Type'),
  116. <TextWithQuestionTooltip key="type">
  117. {variant.type}
  118. <QuestionTooltip
  119. size="xs"
  120. position="top"
  121. title={t('Overrides the default grouping by a custom fingerprinting rule')}
  122. />
  123. </TextWithQuestionTooltip>,
  124. ]);
  125. addFingerprintInfo(data, variant);
  126. break;
  127. case EventGroupVariantType.SALTED_COMPONENT:
  128. component = variant.component;
  129. data.push([
  130. t('Type'),
  131. <TextWithQuestionTooltip key="type">
  132. {variant.type}
  133. <QuestionTooltip
  134. size="xs"
  135. position="top"
  136. title={t(
  137. 'Uses a complex grouping algorithm taking event data and a fingerprint into account'
  138. )}
  139. />
  140. </TextWithQuestionTooltip>,
  141. ]);
  142. addFingerprintInfo(data, variant);
  143. if (showGroupingConfig && variant.config?.id) {
  144. data.push([t('Grouping Config'), variant.config.id]);
  145. }
  146. break;
  147. case EventGroupVariantType.PERFORMANCE_PROBLEM:
  148. const spansToHashes = Object.fromEntries(
  149. event.entries
  150. .find((c): c is EntrySpans => c.type === 'spans')
  151. ?.data?.map((span: RawSpanType) => [span.span_id, span.hash]) ?? []
  152. );
  153. data.push([
  154. t('Type'),
  155. <TextWithQuestionTooltip key="type">
  156. {variant.type}
  157. <QuestionTooltip
  158. size="xs"
  159. position="top"
  160. title={t(
  161. 'Uses the evidence from performance issue detection to generate a fingerprint.'
  162. )}
  163. />
  164. </TextWithQuestionTooltip>,
  165. ]);
  166. data.push(['Performance Issue Type', variant.key]);
  167. data.push(['Span Operation', variant.evidence.op]);
  168. data.push([
  169. 'Parent Span Hashes',
  170. variant.evidence?.parent_span_ids?.map(id => spansToHashes[id]) ?? [],
  171. ]);
  172. data.push([
  173. 'Source Span Hashes',
  174. variant.evidence?.cause_span_ids?.map(id => spansToHashes[id]) ?? [],
  175. ]);
  176. data.push([
  177. 'Offender Span Hashes',
  178. [...new Set(variant.evidence?.offender_span_ids?.map(id => spansToHashes[id]))],
  179. ]);
  180. break;
  181. default:
  182. break;
  183. }
  184. if (component) {
  185. data.push([
  186. t('Grouping'),
  187. <GroupingTree key={component.id}>
  188. <GroupingComponent
  189. component={component}
  190. showNonContributing={this.state.showNonContributing}
  191. />
  192. </GroupingTree>,
  193. ]);
  194. }
  195. return [data, component];
  196. }
  197. renderTitle() {
  198. const {variant} = this.props;
  199. const isContributing = variant.hash !== null;
  200. let title: string;
  201. if (isContributing) {
  202. title = t('Contributing variant');
  203. } else {
  204. const hint = 'component' in variant ? variant.component?.hint : undefined;
  205. if (hint) {
  206. title = t('Non-contributing variant: %s', hint);
  207. } else {
  208. title = t('Non-contributing variant');
  209. }
  210. }
  211. return (
  212. <Tooltip title={title}>
  213. <VariantTitle>
  214. <ContributionIcon isContributing={isContributing} />
  215. {t('By')}{' '}
  216. {variant.description
  217. ?.split(' ')
  218. .map(i => capitalize(i))
  219. .join(' ') ?? t('Nothing')}
  220. </VariantTitle>
  221. </Tooltip>
  222. );
  223. }
  224. renderContributionToggle() {
  225. const {showNonContributing} = this.state;
  226. return (
  227. <SegmentedControl
  228. aria-label={t('Filter by contribution')}
  229. size="xs"
  230. value={showNonContributing ? 'all' : 'relevant'}
  231. onChange={key => this.setState({showNonContributing: key === 'all'})}
  232. >
  233. <SegmentedControl.Item key="relevant">
  234. {t('Contributing values')}
  235. </SegmentedControl.Item>
  236. <SegmentedControl.Item key="all">{t('All values')}</SegmentedControl.Item>
  237. </SegmentedControl>
  238. );
  239. }
  240. render() {
  241. const [data, component] = this.getVariantData();
  242. return (
  243. <VariantWrapper>
  244. <Header>
  245. {this.renderTitle()}
  246. {hasNonContributingComponent(component) && this.renderContributionToggle()}
  247. </Header>
  248. <KeyValueList
  249. data={data.map(d => ({
  250. key: d[0],
  251. subject: d[0],
  252. value: d[1],
  253. }))}
  254. isContextData
  255. shouldSort={false}
  256. />
  257. </VariantWrapper>
  258. );
  259. }
  260. }
  261. const VariantWrapper = styled('div')`
  262. margin-bottom: ${space(4)};
  263. `;
  264. const Header = styled('div')`
  265. display: flex;
  266. align-items: center;
  267. justify-content: space-between;
  268. margin-bottom: ${space(2)};
  269. @media (max-width: ${p => p.theme.breakpoints.small}) {
  270. display: block;
  271. }
  272. `;
  273. const VariantTitle = styled('h5')`
  274. font-size: ${p => p.theme.fontSizeMedium};
  275. margin: 0;
  276. display: flex;
  277. align-items: center;
  278. `;
  279. const ContributionIcon = styled(({isContributing, ...p}) =>
  280. isContributing ? (
  281. <IconCheckmark size="sm" isCircled color="successText" {...p} />
  282. ) : (
  283. <IconClose size="sm" isCircled color="dangerText" {...p} />
  284. )
  285. )`
  286. margin-right: ${space(1)};
  287. `;
  288. const GroupingTree = styled('div')`
  289. color: ${p => p.theme.textColor};
  290. `;
  291. const TextWithQuestionTooltip = styled('div')`
  292. display: grid;
  293. align-items: center;
  294. grid-template-columns: auto 1fr;
  295. gap: ${space(0.5)};
  296. `;
  297. const Hash = styled('span')`
  298. @media (max-width: ${p => p.theme.breakpoints.small}) {
  299. ${p => p.theme.overflowEllipsis};
  300. width: 210px;
  301. }
  302. `;
  303. export default GroupVariant;