issueQuickTrace.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. import {Component, Fragment} from 'react';
  2. import styled from '@emotion/styled';
  3. import {Location} from 'history';
  4. import {promptsCheck, promptsUpdate} from 'sentry/actionCreators/prompts';
  5. import {Client} from 'sentry/api';
  6. import Alert from 'sentry/components/alert';
  7. import Button from 'sentry/components/button';
  8. import ErrorBoundary from 'sentry/components/errorBoundary';
  9. import ExternalLink from 'sentry/components/links/externalLink';
  10. import Link from 'sentry/components/links/link';
  11. import Placeholder from 'sentry/components/placeholder';
  12. import QuickTrace from 'sentry/components/quickTrace';
  13. import {generateTraceTarget} from 'sentry/components/quickTrace/utils';
  14. import {IconClose} from 'sentry/icons';
  15. import {t, tct} from 'sentry/locale';
  16. import space from 'sentry/styles/space';
  17. import {Organization} from 'sentry/types';
  18. import {Event} from 'sentry/types/event';
  19. import {trackAnalyticsEvent} from 'sentry/utils/analytics';
  20. import QuickTraceQuery from 'sentry/utils/performance/quickTrace/quickTraceQuery';
  21. import {promptIsDismissed} from 'sentry/utils/promptIsDismissed';
  22. import withApi from 'sentry/utils/withApi';
  23. type Props = {
  24. api: Client;
  25. event: Event;
  26. location: Location;
  27. organization: Organization;
  28. };
  29. type State = {
  30. shouldShow: boolean | null;
  31. };
  32. class IssueQuickTrace extends Component<Props, State> {
  33. state: State = {
  34. shouldShow: null,
  35. };
  36. componentDidMount() {
  37. this.promptsCheck();
  38. }
  39. shouldComponentUpdate(nextProps, nextState: State) {
  40. return (
  41. this.props.event !== nextProps.event ||
  42. this.state.shouldShow !== nextState.shouldShow
  43. );
  44. }
  45. async promptsCheck() {
  46. const {api, event, organization} = this.props;
  47. const data = await promptsCheck(api, {
  48. organizationId: organization.id,
  49. projectId: event.projectID,
  50. feature: 'quick_trace_missing',
  51. });
  52. this.setState({shouldShow: !promptIsDismissed(data ?? {}, 30)});
  53. }
  54. handleTraceLink(organization: Organization) {
  55. trackAnalyticsEvent({
  56. eventKey: 'quick_trace.trace_id.clicked',
  57. eventName: 'Quick Trace: Trace ID clicked',
  58. organization_id: parseInt(organization.id, 10),
  59. source: 'issues',
  60. });
  61. }
  62. renderTraceLink({isLoading, error, trace, type}) {
  63. const {event, organization} = this.props;
  64. if (isLoading || error !== null || trace === null || type === 'empty') {
  65. return null;
  66. }
  67. return (
  68. <LinkContainer>
  69. <Link
  70. to={generateTraceTarget(event, organization)}
  71. onClick={() => this.handleTraceLink(organization)}
  72. >
  73. {t('View Full Trace')}
  74. </Link>
  75. </LinkContainer>
  76. );
  77. }
  78. snoozePrompt = () => {
  79. const {api, event, organization} = this.props;
  80. const data = {
  81. projectId: event.projectID,
  82. organizationId: organization.id,
  83. feature: 'quick_trace_missing',
  84. status: 'snoozed' as const,
  85. };
  86. promptsUpdate(api, data).then(() => this.setState({shouldShow: false}));
  87. };
  88. renderQuickTrace(results) {
  89. const {event, location, organization} = this.props;
  90. const {shouldShow} = this.state;
  91. const {isLoading, error, trace, type} = results;
  92. if (isLoading) {
  93. return <Placeholder height="24px" />;
  94. }
  95. if (error || trace === null || trace.length === 0) {
  96. if (!shouldShow) {
  97. return null;
  98. }
  99. return (
  100. <StyledAlert
  101. type="info"
  102. showIcon
  103. trailingItems={
  104. <Button
  105. priority="link"
  106. size="zero"
  107. title={t('Dismiss for a month')}
  108. onClick={this.snoozePrompt}
  109. >
  110. <IconClose />
  111. </Button>
  112. }
  113. >
  114. {tct('The [type] for this event cannot be found. [link]', {
  115. type: type === 'missing' ? t('transaction') : t('trace'),
  116. link: (
  117. <ExternalLink href="https://docs.sentry.io/product/sentry-basics/tracing/trace-view/#troubleshooting">
  118. {t('Read the docs to understand why.')}
  119. </ExternalLink>
  120. ),
  121. })}
  122. </StyledAlert>
  123. );
  124. }
  125. return (
  126. <QuickTrace
  127. event={event}
  128. quickTrace={results}
  129. location={location}
  130. organization={organization}
  131. anchor="left"
  132. errorDest="issue"
  133. transactionDest="performance"
  134. />
  135. );
  136. }
  137. render() {
  138. const {event, organization, location} = this.props;
  139. return (
  140. <ErrorBoundary mini>
  141. <QuickTraceQuery event={event} location={location} orgSlug={organization.slug}>
  142. {results => {
  143. return (
  144. <Fragment>
  145. {this.renderTraceLink(results)}
  146. <QuickTraceWrapper>{this.renderQuickTrace(results)}</QuickTraceWrapper>
  147. </Fragment>
  148. );
  149. }}
  150. </QuickTraceQuery>
  151. </ErrorBoundary>
  152. );
  153. }
  154. }
  155. const LinkContainer = styled('span')`
  156. margin-left: ${space(1)};
  157. padding-left: ${space(1)};
  158. position: relative;
  159. &:before {
  160. display: block;
  161. position: absolute;
  162. content: '';
  163. left: 0;
  164. top: 2px;
  165. height: 14px;
  166. border-left: 1px solid ${p => p.theme.border};
  167. }
  168. `;
  169. const QuickTraceWrapper = styled('div')`
  170. margin-top: ${space(0.5)};
  171. `;
  172. const StyledAlert = styled(Alert)`
  173. margin: 0;
  174. `;
  175. export default withApi(IssueQuickTrace);