transactionDetail.tsx 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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, IconProfiling} 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 {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. trackAdvancedAnalyticsEvent('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} = transaction;
  53. if (errors.length === 0) {
  54. return null;
  55. }
  56. return (
  57. <Alert
  58. system
  59. type="error"
  60. expand={errors.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 error event occurred in this transaction.',
  75. '%s error events occurred in this transaction.',
  76. errors.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. trackAdvancedAnalyticsEvent('profiling_views.go_to_flamegraph', {
  126. organization,
  127. source: 'performance.trace_view',
  128. });
  129. }
  130. return (
  131. <StyledButton
  132. size="xs"
  133. to={target}
  134. onClick={handleOnClick}
  135. icon={<IconProfiling size="xs" />}
  136. >
  137. {t('Go to Profile')}
  138. </StyledButton>
  139. );
  140. }
  141. renderMeasurements() {
  142. const {transaction} = this.props;
  143. const {measurements = {}} = transaction;
  144. const measurementKeys = Object.keys(measurements)
  145. .filter(name => Boolean(WEB_VITAL_DETAILS[`measurements.${name}`]))
  146. .sort();
  147. if (measurementKeys.length <= 0) {
  148. return null;
  149. }
  150. return (
  151. <Fragment>
  152. {measurementKeys.map(measurement => (
  153. <Row
  154. key={measurement}
  155. title={WEB_VITAL_DETAILS[`measurements.${measurement}`]?.name}
  156. >
  157. {`${Number(measurements[measurement].value.toFixed(3)).toLocaleString()}ms`}
  158. </Row>
  159. ))}
  160. </Fragment>
  161. );
  162. }
  163. scrollBarIntoView =
  164. (transactionId: string) => (e: React.MouseEvent<HTMLAnchorElement>) => {
  165. // do not use the default anchor behaviour
  166. // because it will be hidden behind the minimap
  167. e.preventDefault();
  168. const hash = `#txn-${transactionId}`;
  169. this.props.scrollIntoView();
  170. // TODO(txiao): This is causing a rerender of the whole page,
  171. // which can be slow.
  172. //
  173. // make sure to update the location
  174. browserHistory.push({
  175. ...this.props.location,
  176. hash,
  177. });
  178. };
  179. renderTransactionDetail() {
  180. const {location, organization, transaction} = this.props;
  181. const startTimestamp = Math.min(transaction.start_timestamp, transaction.timestamp);
  182. const endTimestamp = Math.max(transaction.start_timestamp, transaction.timestamp);
  183. const {start: startTimeWithLeadingZero, end: endTimeWithLeadingZero} =
  184. getFormattedTimeRangeWithLeadingAndTrailingZero(startTimestamp, endTimestamp);
  185. const duration = (endTimestamp - startTimestamp) * 1000;
  186. const durationString = `${Number(duration.toFixed(3)).toLocaleString()}ms`;
  187. return (
  188. <TransactionDetails>
  189. <table className="table key-value">
  190. <tbody>
  191. <Row
  192. title={
  193. <TransactionIdTitle
  194. onClick={this.scrollBarIntoView(transaction.event_id)}
  195. >
  196. {t('Event ID')}
  197. <Clipboard
  198. value={`${window.location.href.replace(
  199. window.location.hash,
  200. ''
  201. )}#txn-${transaction.event_id}`}
  202. >
  203. <StyledIconLink />
  204. </Clipboard>
  205. </TransactionIdTitle>
  206. }
  207. extra={this.renderGoToTransactionButton()}
  208. >
  209. {transaction.event_id}
  210. </Row>
  211. <Row title="Transaction" extra={this.renderGoToSummaryButton()}>
  212. {transaction.transaction}
  213. </Row>
  214. <Row title="Transaction Status">{transaction['transaction.status']}</Row>
  215. <Row title="Span ID">{transaction.span_id}</Row>
  216. {transaction.profile_id && (
  217. <Row title="Profile ID" extra={this.renderGoToProfileButton()}>
  218. {transaction.profile_id}
  219. </Row>
  220. )}
  221. <Row title="Project">{transaction.project_slug}</Row>
  222. <Row title="Start Date">
  223. {getDynamicText({
  224. fixed: 'Mar 19, 2021 11:06:27 AM UTC',
  225. value: (
  226. <Fragment>
  227. <DateTime date={startTimestamp * 1000} />
  228. {` (${startTimeWithLeadingZero})`}
  229. </Fragment>
  230. ),
  231. })}
  232. </Row>
  233. <Row title="End Date">
  234. {getDynamicText({
  235. fixed: 'Mar 19, 2021 11:06:28 AM UTC',
  236. value: (
  237. <Fragment>
  238. <DateTime date={endTimestamp * 1000} />
  239. {` (${endTimeWithLeadingZero})`}
  240. </Fragment>
  241. ),
  242. })}
  243. </Row>
  244. <Row title="Duration">{durationString}</Row>
  245. <Row title="Operation">{transaction['transaction.op'] || ''}</Row>
  246. {this.renderMeasurements()}
  247. <Tags
  248. location={location}
  249. organization={organization}
  250. transaction={transaction}
  251. />
  252. </tbody>
  253. </table>
  254. </TransactionDetails>
  255. );
  256. }
  257. render() {
  258. return (
  259. <CustomerProfiler id="TransactionDetail">
  260. <TransactionDetailsContainer
  261. onClick={event => {
  262. // prevent toggling the transaction detail
  263. event.stopPropagation();
  264. }}
  265. >
  266. {this.renderTransactionErrors()}
  267. {this.renderTransactionDetail()}
  268. </TransactionDetailsContainer>
  269. </CustomerProfiler>
  270. );
  271. }
  272. }
  273. const TransactionIdTitle = styled('a')`
  274. display: flex;
  275. color: ${p => p.theme.textColor};
  276. :hover {
  277. color: ${p => p.theme.textColor};
  278. }
  279. `;
  280. const StyledIconLink = styled(IconLink)`
  281. display: block;
  282. color: ${p => p.theme.gray300};
  283. margin-left: ${space(1)};
  284. `;
  285. const StyledButton = styled(Button)`
  286. position: absolute;
  287. top: ${space(0.75)};
  288. right: ${space(0.5)};
  289. `;
  290. export default TransactionDetail;