transactionDetail.tsx 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. import {Component, Fragment} from 'react';
  2. import {browserHistory} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import {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 Clipboard from 'sentry/components/clipboard';
  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 {IconLink} from 'sentry/icons';
  22. import {t, tn} from 'sentry/locale';
  23. import {space} from 'sentry/styles/space';
  24. import {Organization} from 'sentry/types';
  25. import {trackAnalytics} from 'sentry/utils/analytics';
  26. import {generateEventSlug} from 'sentry/utils/discover/urls';
  27. import getDynamicText from 'sentry/utils/getDynamicText';
  28. import {TraceFullDetailed} from 'sentry/utils/performance/quickTrace/types';
  29. import {getTransactionDetailsUrl} from 'sentry/utils/performance/urls';
  30. import {WEB_VITAL_DETAILS} from 'sentry/utils/performance/vitals/constants';
  31. import {CustomProfiler} from 'sentry/utils/performanceForSentry';
  32. import {generateProfileFlamechartRoute} from 'sentry/utils/profiling/routes';
  33. import {transactionSummaryRouteWithQuery} from 'sentry/views/performance/transactionSummary/utils';
  34. import {Row, Tags, TransactionDetails, TransactionDetailsContainer} from './styles';
  35. type Props = {
  36. location: Location;
  37. organization: Organization;
  38. scrollIntoView: () => void;
  39. transaction: TraceFullDetailed;
  40. };
  41. class TransactionDetail extends Component<Props> {
  42. componentDidMount() {
  43. const {organization, transaction} = this.props;
  44. trackAnalytics('performance_views.trace_view.open_transaction_details', {
  45. organization,
  46. operation: transaction['transaction.op'],
  47. transaction: transaction.transaction,
  48. });
  49. }
  50. renderTransactionErrors() {
  51. const {organization, transaction} = this.props;
  52. const {errors, performance_issues} = transaction;
  53. if (errors.length + performance_issues.length === 0) {
  54. return null;
  55. }
  56. return (
  57. <Alert
  58. system
  59. type="error"
  60. expand={[...errors, ...performance_issues].map(error => (
  61. <ErrorMessageContent key={error.event_id}>
  62. <ErrorDot level={error.level} />
  63. <ErrorLevel>{error.level}</ErrorLevel>
  64. <ErrorTitle>
  65. <Link to={generateIssueEventTarget(error, organization)}>
  66. {error.title}
  67. </Link>
  68. </ErrorTitle>
  69. </ErrorMessageContent>
  70. ))}
  71. >
  72. <ErrorMessageTitle>
  73. {tn(
  74. '%s issue occurred in this transaction.',
  75. '%s issues occurred in this transaction.',
  76. errors.length + performance_issues.length
  77. )}
  78. </ErrorMessageTitle>
  79. </Alert>
  80. );
  81. }
  82. renderGoToTransactionButton() {
  83. const {location, organization, transaction} = this.props;
  84. const eventSlug = generateEventSlug({
  85. id: transaction.event_id,
  86. project: transaction.project_slug,
  87. });
  88. const target = getTransactionDetailsUrl(
  89. organization.slug,
  90. eventSlug,
  91. transaction.transaction,
  92. omit(location.query, Object.values(PAGE_URL_PARAM))
  93. );
  94. return (
  95. <StyledButton size="xs" to={target}>
  96. {t('View Event')}
  97. </StyledButton>
  98. );
  99. }
  100. renderGoToSummaryButton() {
  101. const {location, organization, transaction} = this.props;
  102. const target = transactionSummaryRouteWithQuery({
  103. orgSlug: organization.slug,
  104. transaction: transaction.transaction,
  105. query: omit(location.query, Object.values(PAGE_URL_PARAM)),
  106. projectID: String(transaction.project_id),
  107. });
  108. return (
  109. <StyledButton size="xs" to={target}>
  110. {t('View Summary')}
  111. </StyledButton>
  112. );
  113. }
  114. renderGoToProfileButton() {
  115. const {organization, transaction} = this.props;
  116. if (!transaction.profile_id) {
  117. return null;
  118. }
  119. const target = generateProfileFlamechartRoute({
  120. orgSlug: organization.slug,
  121. projectSlug: transaction.project_slug,
  122. profileId: transaction.profile_id,
  123. });
  124. function handleOnClick() {
  125. trackAnalytics('profiling_views.go_to_flamegraph', {
  126. organization,
  127. source: 'performance.trace_view',
  128. });
  129. }
  130. return (
  131. <StyledButton size="xs" to={target} onClick={handleOnClick}>
  132. {t('View Profile')}
  133. </StyledButton>
  134. );
  135. }
  136. renderMeasurements() {
  137. const {transaction} = this.props;
  138. const {measurements = {}} = transaction;
  139. const measurementKeys = Object.keys(measurements)
  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. title={WEB_VITAL_DETAILS[`measurements.${measurement}`]?.name}
  151. >
  152. {`${Number(measurements[measurement].value.toFixed(3)).toLocaleString()}ms`}
  153. </Row>
  154. ))}
  155. </Fragment>
  156. );
  157. }
  158. scrollBarIntoView =
  159. (transactionId: string) => (e: React.MouseEvent<HTMLAnchorElement>) => {
  160. // do not use the default anchor behaviour
  161. // because it will be hidden behind the minimap
  162. e.preventDefault();
  163. const hash = `#txn-${transactionId}`;
  164. this.props.scrollIntoView();
  165. // TODO(txiao): This is causing a rerender of the whole page,
  166. // which can be slow.
  167. //
  168. // make sure to update the location
  169. browserHistory.push({
  170. ...this.props.location,
  171. hash,
  172. });
  173. };
  174. renderTransactionDetail() {
  175. const {location, organization, transaction} = this.props;
  176. const startTimestamp = Math.min(transaction.start_timestamp, transaction.timestamp);
  177. const endTimestamp = Math.max(transaction.start_timestamp, transaction.timestamp);
  178. const {start: startTimeWithLeadingZero, end: endTimeWithLeadingZero} =
  179. getFormattedTimeRangeWithLeadingAndTrailingZero(startTimestamp, endTimestamp);
  180. const duration = (endTimestamp - startTimestamp) * 1000;
  181. const durationString = `${Number(duration.toFixed(3)).toLocaleString()}ms`;
  182. return (
  183. <TransactionDetails>
  184. <table className="table key-value">
  185. <tbody>
  186. <Row
  187. title={
  188. <TransactionIdTitle
  189. onClick={this.scrollBarIntoView(transaction.event_id)}
  190. >
  191. {t('Event ID')}
  192. <Clipboard
  193. value={`${window.location.href.replace(
  194. window.location.hash,
  195. ''
  196. )}#txn-${transaction.event_id}`}
  197. >
  198. <StyledIconLink />
  199. </Clipboard>
  200. </TransactionIdTitle>
  201. }
  202. extra={this.renderGoToTransactionButton()}
  203. >
  204. {transaction.event_id}
  205. </Row>
  206. <Row title="Transaction" extra={this.renderGoToSummaryButton()}>
  207. {transaction.transaction}
  208. </Row>
  209. <Row title="Transaction Status">{transaction['transaction.status']}</Row>
  210. <Row title="Span ID">{transaction.span_id}</Row>
  211. {transaction.profile_id && (
  212. <Row title="Profile ID" extra={this.renderGoToProfileButton()}>
  213. {transaction.profile_id}
  214. </Row>
  215. )}
  216. <Row title="Project">{transaction.project_slug}</Row>
  217. <Row title="Start Date">
  218. {getDynamicText({
  219. fixed: 'Mar 19, 2021 11:06:27 AM UTC',
  220. value: (
  221. <Fragment>
  222. <DateTime date={startTimestamp * 1000} />
  223. {` (${startTimeWithLeadingZero})`}
  224. </Fragment>
  225. ),
  226. })}
  227. </Row>
  228. <Row title="End Date">
  229. {getDynamicText({
  230. fixed: 'Mar 19, 2021 11:06:28 AM UTC',
  231. value: (
  232. <Fragment>
  233. <DateTime date={endTimestamp * 1000} />
  234. {` (${endTimeWithLeadingZero})`}
  235. </Fragment>
  236. ),
  237. })}
  238. </Row>
  239. <Row title="Duration">{durationString}</Row>
  240. <Row title="Operation">{transaction['transaction.op'] || ''}</Row>
  241. {this.renderMeasurements()}
  242. <Tags
  243. location={location}
  244. organization={organization}
  245. transaction={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 StyledIconLink = styled(IconLink)`
  276. display: block;
  277. color: ${p => p.theme.gray300};
  278. margin-left: ${space(1)};
  279. `;
  280. const StyledButton = styled(Button)`
  281. position: absolute;
  282. top: ${space(0.75)};
  283. right: ${space(0.5)};
  284. `;
  285. export default TransactionDetail;