issueQuickTrace.tsx 5.7 KB

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