transactionDetail.tsx 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. import {Component, Fragment} from 'react';
  2. import {browserHistory} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import type {Location} from 'history';
  5. import omit from 'lodash/omit';
  6. import {Alert} from 'sentry/components/alert';
  7. import {Button} from 'sentry/components/button';
  8. import {CopyToClipboardButton} from 'sentry/components/copyToClipboardButton';
  9. import DateTime from 'sentry/components/dateTime';
  10. import {getFormattedTimeRangeWithLeadingAndTrailingZero} from 'sentry/components/events/interfaces/spans/utils';
  11. import Link from 'sentry/components/links/link';
  12. import {
  13. ErrorDot,
  14. ErrorLevel,
  15. ErrorMessageContent,
  16. ErrorMessageTitle,
  17. ErrorTitle,
  18. } from 'sentry/components/performance/waterfall/rowDetails';
  19. import {generateIssueEventTarget} from 'sentry/components/quickTrace/utils';
  20. import {PAGE_URL_PARAM} from 'sentry/constants/pageFilters';
  21. import {t, tn} from 'sentry/locale';
  22. import {space} from 'sentry/styles/space';
  23. import type {Organization} from 'sentry/types';
  24. import {trackAnalytics} from 'sentry/utils/analytics';
  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. <StyledButton size="xs" to={target}>
  95. {t('View Event')}
  96. </StyledButton>
  97. );
  98. }
  99. renderGoToSummaryButton() {
  100. const {location, organization, transaction} = this.props;
  101. const target = transactionSummaryRouteWithQuery({
  102. orgSlug: organization.slug,
  103. transaction: transaction.transaction,
  104. query: omit(location.query, Object.values(PAGE_URL_PARAM)),
  105. projectID: String(transaction.project_id),
  106. });
  107. return (
  108. <StyledButton size="xs" to={target}>
  109. {t('View Summary')}
  110. </StyledButton>
  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. <StyledButton size="xs" to={target} onClick={handleOnClick}>
  131. {t('View Profile')}
  132. </StyledButton>
  133. );
  134. }
  135. renderMeasurements() {
  136. const {transaction} = this.props;
  137. const {measurements = {}} = transaction;
  138. const measurementKeys = Object.keys(measurements)
  139. .filter(name => Boolean(WEB_VITAL_DETAILS[`measurements.${name}`]))
  140. .sort();
  141. if (measurementKeys.length <= 0) {
  142. return null;
  143. }
  144. return (
  145. <Fragment>
  146. {measurementKeys.map(measurement => (
  147. <Row
  148. key={measurement}
  149. title={WEB_VITAL_DETAILS[`measurements.${measurement}`]?.name}
  150. >
  151. {`${Number(measurements[measurement].value.toFixed(3)).toLocaleString()}ms`}
  152. </Row>
  153. ))}
  154. </Fragment>
  155. );
  156. }
  157. scrollBarIntoView =
  158. (transactionId: string) => (e: React.MouseEvent<HTMLAnchorElement>) => {
  159. // do not use the default anchor behaviour
  160. // because it will be hidden behind the minimap
  161. e.preventDefault();
  162. const hash = `#txn-${transactionId}`;
  163. this.props.scrollIntoView();
  164. // TODO(txiao): This is causing a rerender of the whole page,
  165. // which can be slow.
  166. //
  167. // make sure to update the location
  168. browserHistory.push({
  169. ...this.props.location,
  170. hash,
  171. });
  172. };
  173. renderTransactionDetail() {
  174. const {location, organization, transaction} = this.props;
  175. const startTimestamp = Math.min(transaction.start_timestamp, transaction.timestamp);
  176. const endTimestamp = Math.max(transaction.start_timestamp, transaction.timestamp);
  177. const {start: startTimeWithLeadingZero, end: endTimeWithLeadingZero} =
  178. getFormattedTimeRangeWithLeadingAndTrailingZero(startTimestamp, endTimestamp);
  179. const duration = (endTimestamp - startTimestamp) * 1000;
  180. const durationString = `${Number(duration.toFixed(3)).toLocaleString()}ms`;
  181. return (
  182. <TransactionDetails>
  183. <table className="table key-value">
  184. <tbody>
  185. <Row
  186. title={
  187. <TransactionIdTitle
  188. onClick={this.scrollBarIntoView(transaction.event_id)}
  189. >
  190. {t('Event ID')}
  191. </TransactionIdTitle>
  192. }
  193. extra={this.renderGoToTransactionButton()}
  194. >
  195. {transaction.event_id}
  196. <CopyToClipboardButton
  197. borderless
  198. size="zero"
  199. iconSize="xs"
  200. text={`${window.location.href.replace(window.location.hash, '')}#txn-${
  201. transaction.event_id
  202. }`}
  203. />
  204. </Row>
  205. <Row title="Transaction" extra={this.renderGoToSummaryButton()}>
  206. {transaction.transaction}
  207. </Row>
  208. <Row title="Transaction Status">{transaction['transaction.status']}</Row>
  209. <Row title="Span ID">{transaction.span_id}</Row>
  210. {transaction.profile_id && (
  211. <Row title="Profile ID" extra={this.renderGoToProfileButton()}>
  212. {transaction.profile_id}
  213. </Row>
  214. )}
  215. <Row title="Project">{transaction.project_slug}</Row>
  216. <Row title="Start Date">
  217. {getDynamicText({
  218. fixed: 'Mar 19, 2021 11:06:27 AM UTC',
  219. value: (
  220. <Fragment>
  221. <DateTime date={startTimestamp * 1000} />
  222. {` (${startTimeWithLeadingZero})`}
  223. </Fragment>
  224. ),
  225. })}
  226. </Row>
  227. <Row title="End Date">
  228. {getDynamicText({
  229. fixed: 'Mar 19, 2021 11:06:28 AM UTC',
  230. value: (
  231. <Fragment>
  232. <DateTime date={endTimestamp * 1000} />
  233. {` (${endTimeWithLeadingZero})`}
  234. </Fragment>
  235. ),
  236. })}
  237. </Row>
  238. <Row title="Duration">{durationString}</Row>
  239. <Row title="Operation">{transaction['transaction.op'] || ''}</Row>
  240. {this.renderMeasurements()}
  241. <Tags
  242. location={location}
  243. organization={organization}
  244. tags={transaction.tags ?? []}
  245. event={transaction}
  246. />
  247. </tbody>
  248. </table>
  249. </TransactionDetails>
  250. );
  251. }
  252. render() {
  253. return (
  254. <CustomProfiler id="TransactionDetail">
  255. <TransactionDetailsContainer
  256. onClick={event => {
  257. // prevent toggling the transaction detail
  258. event.stopPropagation();
  259. }}
  260. >
  261. {this.renderTransactionErrors()}
  262. {this.renderTransactionDetail()}
  263. </TransactionDetailsContainer>
  264. </CustomProfiler>
  265. );
  266. }
  267. }
  268. const TransactionIdTitle = styled('a')`
  269. display: flex;
  270. color: ${p => p.theme.textColor};
  271. :hover {
  272. color: ${p => p.theme.textColor};
  273. }
  274. `;
  275. const StyledButton = styled(Button)`
  276. position: absolute;
  277. top: ${space(0.75)};
  278. right: ${space(0.5)};
  279. `;
  280. export default TransactionDetail;