transactionDetail.tsx 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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 trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
  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 {CustomerProfiler} from 'sentry/utils/performanceForSentry';
  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. scrollToHash: (hash: string) => void;
  38. transaction: TraceFullDetailed;
  39. };
  40. class TransactionDetail extends Component<Props> {
  41. componentDidMount() {
  42. const {organization, transaction} = this.props;
  43. trackAdvancedAnalyticsEvent('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} = transaction;
  52. if (errors.length === 0) {
  53. return null;
  54. }
  55. return (
  56. <Alert
  57. system
  58. type="error"
  59. expand={errors.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. 'An error event occurred in this transaction.',
  74. '%s error events occurred in this transaction.',
  75. errors.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. renderMeasurements() {
  114. const {transaction} = this.props;
  115. const {measurements = {}} = transaction;
  116. const measurementKeys = Object.keys(measurements)
  117. .filter(name => Boolean(WEB_VITAL_DETAILS[`measurements.${name}`]))
  118. .sort();
  119. if (measurementKeys.length <= 0) {
  120. return null;
  121. }
  122. return (
  123. <Fragment>
  124. {measurementKeys.map(measurement => (
  125. <Row
  126. key={measurement}
  127. title={WEB_VITAL_DETAILS[`measurements.${measurement}`]?.name}
  128. >
  129. {`${Number(measurements[measurement].value.toFixed(3)).toLocaleString()}ms`}
  130. </Row>
  131. ))}
  132. </Fragment>
  133. );
  134. }
  135. scrollBarIntoView =
  136. (transactionId: string) => (e: React.MouseEvent<HTMLAnchorElement>) => {
  137. // do not use the default anchor behaviour
  138. // because it will be hidden behind the minimap
  139. e.preventDefault();
  140. const hash = `#txn-${transactionId}`;
  141. this.props.scrollToHash(hash);
  142. // TODO(txiao): This is causing a rerender of the whole page,
  143. // which can be slow.
  144. //
  145. // make sure to update the location
  146. browserHistory.push({
  147. ...this.props.location,
  148. hash,
  149. });
  150. };
  151. renderTransactionDetail() {
  152. const {location, organization, transaction} = this.props;
  153. const startTimestamp = Math.min(transaction.start_timestamp, transaction.timestamp);
  154. const endTimestamp = Math.max(transaction.start_timestamp, transaction.timestamp);
  155. const {start: startTimeWithLeadingZero, end: endTimeWithLeadingZero} =
  156. getFormattedTimeRangeWithLeadingAndTrailingZero(startTimestamp, endTimestamp);
  157. const duration = (endTimestamp - startTimestamp) * 1000;
  158. const durationString = `${Number(duration.toFixed(3)).toLocaleString()}ms`;
  159. return (
  160. <TransactionDetails>
  161. <table className="table key-value">
  162. <tbody>
  163. <Row
  164. title={
  165. <TransactionIdTitle
  166. onClick={this.scrollBarIntoView(transaction.event_id)}
  167. >
  168. {t('Event ID')}
  169. <Clipboard
  170. value={`${window.location.href.replace(
  171. window.location.hash,
  172. ''
  173. )}#txn-${transaction.event_id}`}
  174. >
  175. <StyledIconLink />
  176. </Clipboard>
  177. </TransactionIdTitle>
  178. }
  179. extra={this.renderGoToTransactionButton()}
  180. >
  181. {transaction.event_id}
  182. </Row>
  183. <Row title="Transaction" extra={this.renderGoToSummaryButton()}>
  184. {transaction.transaction}
  185. </Row>
  186. <Row title="Transaction Status">{transaction['transaction.status']}</Row>
  187. <Row title="Span ID">{transaction.span_id}</Row>
  188. <Row title="Project">{transaction.project_slug}</Row>
  189. <Row title="Start Date">
  190. {getDynamicText({
  191. fixed: 'Mar 19, 2021 11:06:27 AM UTC',
  192. value: (
  193. <Fragment>
  194. <DateTime date={startTimestamp * 1000} />
  195. {` (${startTimeWithLeadingZero})`}
  196. </Fragment>
  197. ),
  198. })}
  199. </Row>
  200. <Row title="End Date">
  201. {getDynamicText({
  202. fixed: 'Mar 19, 2021 11:06:28 AM UTC',
  203. value: (
  204. <Fragment>
  205. <DateTime date={endTimestamp * 1000} />
  206. {` (${endTimeWithLeadingZero})`}
  207. </Fragment>
  208. ),
  209. })}
  210. </Row>
  211. <Row title="Duration">{durationString}</Row>
  212. <Row title="Operation">{transaction['transaction.op'] || ''}</Row>
  213. {this.renderMeasurements()}
  214. <Tags
  215. location={location}
  216. organization={organization}
  217. transaction={transaction}
  218. />
  219. </tbody>
  220. </table>
  221. </TransactionDetails>
  222. );
  223. }
  224. render() {
  225. return (
  226. <CustomerProfiler id="TransactionDetail">
  227. <TransactionDetailsContainer
  228. onClick={event => {
  229. // prevent toggling the transaction detail
  230. event.stopPropagation();
  231. }}
  232. >
  233. {this.renderTransactionErrors()}
  234. {this.renderTransactionDetail()}
  235. </TransactionDetailsContainer>
  236. </CustomerProfiler>
  237. );
  238. }
  239. }
  240. const TransactionIdTitle = styled('a')`
  241. display: flex;
  242. color: ${p => p.theme.textColor};
  243. :hover {
  244. color: ${p => p.theme.textColor};
  245. }
  246. `;
  247. const StyledIconLink = styled(IconLink)`
  248. display: block;
  249. color: ${p => p.theme.gray300};
  250. margin-left: ${space(1)};
  251. `;
  252. const StyledButton = styled(Button)`
  253. position: absolute;
  254. top: ${space(0.75)};
  255. right: ${space(0.5)};
  256. `;
  257. export default TransactionDetail;