transactionDetail.tsx 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. import {Component, Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import type {Location} from 'history';
  4. import omit from 'lodash/omit';
  5. import {Alert} from 'sentry/components/alert';
  6. import {LinkButton} from 'sentry/components/button';
  7. import {CopyToClipboardButton} from 'sentry/components/copyToClipboardButton';
  8. import {DateTime} from 'sentry/components/dateTime';
  9. import {getFormattedTimeRangeWithLeadingAndTrailingZero} from 'sentry/components/events/interfaces/spans/utils';
  10. import Link from 'sentry/components/links/link';
  11. import {
  12. ErrorDot,
  13. ErrorLevel,
  14. ErrorMessageContent,
  15. ErrorMessageTitle,
  16. ErrorTitle,
  17. } from 'sentry/components/performance/waterfall/rowDetails';
  18. import {generateIssueEventTarget} from 'sentry/components/quickTrace/utils';
  19. import {PAGE_URL_PARAM} from 'sentry/constants/pageFilters';
  20. import {t, tn} from 'sentry/locale';
  21. import {space} from 'sentry/styles/space';
  22. import type {Organization} from 'sentry/types/organization';
  23. import {trackAnalytics} from 'sentry/utils/analytics';
  24. import {browserHistory} from 'sentry/utils/browserHistory';
  25. import {generateEventSlug} from 'sentry/utils/discover/urls';
  26. import getDynamicText from 'sentry/utils/getDynamicText';
  27. import type {TraceFullDetailed} from 'sentry/utils/performance/quickTrace/types';
  28. import {getTransactionDetailsUrl} from 'sentry/utils/performance/urls';
  29. import {WEB_VITAL_DETAILS} from 'sentry/utils/performance/vitals/constants';
  30. import {CustomProfiler} from 'sentry/utils/performanceForSentry';
  31. import {generateProfileFlamechartRoute} from 'sentry/utils/profiling/routes';
  32. import {transactionSummaryRouteWithQuery} from 'sentry/views/performance/transactionSummary/utils';
  33. import {Row, Tags, TransactionDetails, TransactionDetailsContainer} from './styles';
  34. type Props = {
  35. location: Location;
  36. organization: Organization;
  37. scrollIntoView: () => void;
  38. transaction: TraceFullDetailed;
  39. };
  40. class TransactionDetail extends Component<Props> {
  41. componentDidMount() {
  42. const {organization, transaction} = this.props;
  43. trackAnalytics('performance_views.trace_view.open_transaction_details', {
  44. organization,
  45. operation: transaction['transaction.op'],
  46. transaction: transaction.transaction,
  47. });
  48. }
  49. renderTransactionErrors() {
  50. const {organization, transaction} = this.props;
  51. const {errors, performance_issues} = transaction;
  52. if (errors.length + performance_issues.length === 0) {
  53. return null;
  54. }
  55. return (
  56. <Alert
  57. system
  58. type="error"
  59. expand={[...errors, ...performance_issues].map(error => (
  60. <ErrorMessageContent key={error.event_id}>
  61. <ErrorDot level={error.level} />
  62. <ErrorLevel>{error.level}</ErrorLevel>
  63. <ErrorTitle>
  64. <Link to={generateIssueEventTarget(error, organization)}>
  65. {error.title}
  66. </Link>
  67. </ErrorTitle>
  68. </ErrorMessageContent>
  69. ))}
  70. >
  71. <ErrorMessageTitle>
  72. {tn(
  73. '%s issue occurred in this transaction.',
  74. '%s issues occurred in this transaction.',
  75. errors.length + performance_issues.length
  76. )}
  77. </ErrorMessageTitle>
  78. </Alert>
  79. );
  80. }
  81. renderGoToTransactionButton() {
  82. const {location, organization, transaction} = this.props;
  83. const eventSlug = generateEventSlug({
  84. id: transaction.event_id,
  85. project: transaction.project_slug,
  86. });
  87. const target = getTransactionDetailsUrl(
  88. organization.slug,
  89. eventSlug,
  90. transaction.transaction,
  91. omit(location.query, Object.values(PAGE_URL_PARAM))
  92. );
  93. return (
  94. <StyledLinkButton size="xs" to={target}>
  95. {t('View Event')}
  96. </StyledLinkButton>
  97. );
  98. }
  99. renderGoToSummaryButton() {
  100. const {location, organization, transaction} = this.props;
  101. const target = transactionSummaryRouteWithQuery({
  102. organization,
  103. transaction: transaction.transaction,
  104. query: omit(location.query, Object.values(PAGE_URL_PARAM)),
  105. projectID: String(transaction.project_id),
  106. });
  107. return (
  108. <StyledLinkButton size="xs" to={target}>
  109. {t('View Summary')}
  110. </StyledLinkButton>
  111. );
  112. }
  113. renderGoToProfileButton() {
  114. const {organization, transaction} = this.props;
  115. if (!transaction.profile_id) {
  116. return null;
  117. }
  118. const target = generateProfileFlamechartRoute({
  119. orgSlug: organization.slug,
  120. projectSlug: transaction.project_slug,
  121. profileId: transaction.profile_id,
  122. });
  123. function handleOnClick() {
  124. trackAnalytics('profiling_views.go_to_flamegraph', {
  125. organization,
  126. source: 'performance.trace_view',
  127. });
  128. }
  129. return (
  130. <StyledLinkButton size="xs" to={target} onClick={handleOnClick}>
  131. {t('View Profile')}
  132. </StyledLinkButton>
  133. );
  134. }
  135. renderMeasurements() {
  136. const {transaction} = this.props;
  137. const {measurements = {}} = transaction;
  138. const measurementKeys = Object.keys(measurements)
  139. // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
  140. .filter(name => Boolean(WEB_VITAL_DETAILS[`measurements.${name}`]))
  141. .sort();
  142. if (measurementKeys.length <= 0) {
  143. return null;
  144. }
  145. return (
  146. <Fragment>
  147. {measurementKeys.map(measurement => (
  148. <Row
  149. key={measurement}
  150. // @ts-expect-error TS(7053): Element implicitly has an 'any' type because expre... Remove this comment to see the full error message
  151. title={WEB_VITAL_DETAILS[`measurements.${measurement}`]?.name}
  152. >
  153. {`${Number(measurements[measurement]!.value.toFixed(3)).toLocaleString()}ms`}
  154. </Row>
  155. ))}
  156. </Fragment>
  157. );
  158. }
  159. scrollBarIntoView =
  160. (transactionId: string) => (e: React.MouseEvent<HTMLAnchorElement>) => {
  161. // do not use the default anchor behaviour
  162. // because it will be hidden behind the minimap
  163. e.preventDefault();
  164. const hash = `#txn-${transactionId}`;
  165. this.props.scrollIntoView();
  166. // TODO(txiao): This is causing a rerender of the whole page,
  167. // which can be slow.
  168. //
  169. // make sure to update the location
  170. browserHistory.push({
  171. ...this.props.location,
  172. hash,
  173. });
  174. };
  175. renderTransactionDetail() {
  176. const {location, organization, transaction} = this.props;
  177. const startTimestamp = Math.min(transaction.start_timestamp, transaction.timestamp);
  178. const endTimestamp = Math.max(transaction.start_timestamp, transaction.timestamp);
  179. const {start: startTimeWithLeadingZero, end: endTimeWithLeadingZero} =
  180. getFormattedTimeRangeWithLeadingAndTrailingZero(startTimestamp, endTimestamp);
  181. const duration = (endTimestamp - startTimestamp) * 1000;
  182. const durationString = `${Number(duration.toFixed(3)).toLocaleString()}ms`;
  183. return (
  184. <TransactionDetails>
  185. <table className="table key-value">
  186. <tbody>
  187. <Row
  188. title={
  189. <TransactionIdTitle
  190. onClick={this.scrollBarIntoView(transaction.event_id)}
  191. >
  192. {t('Event ID')}
  193. </TransactionIdTitle>
  194. }
  195. extra={this.renderGoToTransactionButton()}
  196. >
  197. {transaction.event_id}
  198. <CopyToClipboardButton
  199. borderless
  200. size="zero"
  201. iconSize="xs"
  202. text={`${window.location.href.replace(window.location.hash, '')}#txn-${
  203. transaction.event_id
  204. }`}
  205. />
  206. </Row>
  207. <Row title="Transaction" extra={this.renderGoToSummaryButton()}>
  208. {transaction.transaction}
  209. </Row>
  210. <Row title="Transaction Status">{transaction['transaction.status']}</Row>
  211. <Row title="Span ID">{transaction.span_id}</Row>
  212. {transaction.profile_id && (
  213. <Row title="Profile ID" extra={this.renderGoToProfileButton()}>
  214. {transaction.profile_id}
  215. </Row>
  216. )}
  217. <Row title="Project">{transaction.project_slug}</Row>
  218. <Row title="Start Date">
  219. {getDynamicText({
  220. fixed: 'Mar 19, 2021 11:06:27 AM UTC',
  221. value: (
  222. <Fragment>
  223. <DateTime date={startTimestamp * 1000} />
  224. {` (${startTimeWithLeadingZero})`}
  225. </Fragment>
  226. ),
  227. })}
  228. </Row>
  229. <Row title="End Date">
  230. {getDynamicText({
  231. fixed: 'Mar 19, 2021 11:06:28 AM UTC',
  232. value: (
  233. <Fragment>
  234. <DateTime date={endTimestamp * 1000} />
  235. {` (${endTimeWithLeadingZero})`}
  236. </Fragment>
  237. ),
  238. })}
  239. </Row>
  240. <Row title="Duration">{durationString}</Row>
  241. <Row title="Operation">{transaction['transaction.op'] || ''}</Row>
  242. {this.renderMeasurements()}
  243. <Tags
  244. location={location}
  245. organization={organization}
  246. tags={transaction.tags ?? []}
  247. event={transaction}
  248. />
  249. </tbody>
  250. </table>
  251. </TransactionDetails>
  252. );
  253. }
  254. render() {
  255. return (
  256. <CustomProfiler id="TransactionDetail">
  257. <TransactionDetailsContainer
  258. onClick={event => {
  259. // prevent toggling the transaction detail
  260. event.stopPropagation();
  261. }}
  262. >
  263. {this.renderTransactionErrors()}
  264. {this.renderTransactionDetail()}
  265. </TransactionDetailsContainer>
  266. </CustomProfiler>
  267. );
  268. }
  269. }
  270. const TransactionIdTitle = styled('a')`
  271. display: flex;
  272. color: ${p => p.theme.textColor};
  273. :hover {
  274. color: ${p => p.theme.textColor};
  275. }
  276. `;
  277. const StyledLinkButton = styled(LinkButton)`
  278. position: absolute;
  279. top: ${space(0.75)};
  280. right: ${space(0.5)};
  281. `;
  282. export default TransactionDetail;