configureDistributedTracing.tsx 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. import {Component} from 'react';
  2. import styled from '@emotion/styled';
  3. import quickTraceExample from 'sentry-images/spot/performance-quick-trace.svg';
  4. import {promptsCheck, promptsUpdate} from 'sentry/actionCreators/prompts';
  5. import {Client} from 'sentry/api';
  6. import Feature from 'sentry/components/acl/feature';
  7. import FeatureDisabled from 'sentry/components/acl/featureDisabled';
  8. import Button from 'sentry/components/button';
  9. import ButtonBar from 'sentry/components/buttonBar';
  10. import {Hovercard} from 'sentry/components/hovercard';
  11. import {Panel} from 'sentry/components/panels';
  12. import {t} from 'sentry/locale';
  13. import space from 'sentry/styles/space';
  14. import {Organization, Project} from 'sentry/types';
  15. import {Event} from 'sentry/types/event';
  16. import {trackAnalyticsEvent} from 'sentry/utils/analytics';
  17. import {getConfigureTracingDocsLink} from 'sentry/utils/docs';
  18. import {promptCanShow, promptIsDismissed} from 'sentry/utils/promptIsDismissed';
  19. import withApi from 'sentry/utils/withApi';
  20. const DISTRIBUTED_TRACING_FEATURE = 'distributed_tracing';
  21. type Props = {
  22. api: Client;
  23. event: Event;
  24. organization: Organization;
  25. project: Project;
  26. };
  27. type State = {
  28. shouldShow: boolean | null;
  29. };
  30. class ConfigureDistributedTracing extends Component<Props, State> {
  31. state: State = {
  32. shouldShow: null,
  33. };
  34. componentDidMount() {
  35. this.fetchData();
  36. }
  37. async fetchData() {
  38. const {api, event, project, organization} = this.props;
  39. if (!promptCanShow(DISTRIBUTED_TRACING_FEATURE, event.eventID)) {
  40. this.setState({shouldShow: false});
  41. return;
  42. }
  43. const data = await promptsCheck(api, {
  44. projectId: project.id,
  45. organizationId: organization.id,
  46. feature: DISTRIBUTED_TRACING_FEATURE,
  47. });
  48. this.setState({shouldShow: !promptIsDismissed(data ?? {}, 30)});
  49. }
  50. trackAnalytics({eventKey, eventName}) {
  51. const {project, organization} = this.props;
  52. trackAnalyticsEvent({
  53. eventKey,
  54. eventName,
  55. organization_id: parseInt(organization.id, 10),
  56. project_id: parseInt(project.id, 10),
  57. platform: project.platform,
  58. });
  59. }
  60. handleClick({action, eventKey, eventName}) {
  61. const {api, project, organization} = this.props;
  62. const data = {
  63. projectId: project.id,
  64. organizationId: organization.id,
  65. feature: DISTRIBUTED_TRACING_FEATURE,
  66. status: action,
  67. };
  68. promptsUpdate(api, data).then(() => this.setState({shouldShow: false}));
  69. this.trackAnalytics({eventKey, eventName});
  70. }
  71. renderActionButton(docsLink: string) {
  72. const features = ['organizations:performance-view'];
  73. const noFeatureMessage = t('Requires performance monitoring.');
  74. const renderDisabled = p => (
  75. <Hovercard
  76. body={
  77. <FeatureDisabled
  78. features={features}
  79. hideHelpToggle
  80. message={noFeatureMessage}
  81. featureName={noFeatureMessage}
  82. />
  83. }
  84. >
  85. {p.children(p)}
  86. </Hovercard>
  87. );
  88. return (
  89. <Feature
  90. hookName="feature-disabled:configure-distributed-tracing"
  91. features={features}
  92. renderDisabled={renderDisabled}
  93. >
  94. {() => (
  95. <Button
  96. size="sm"
  97. priority="primary"
  98. href={docsLink}
  99. onClick={() =>
  100. this.trackAnalytics({
  101. eventKey: 'quick_trace.missing_instrumentation.docs',
  102. eventName: 'Quick Trace: Missing Instrumentation Docs',
  103. })
  104. }
  105. >
  106. {t('Read the docs')}
  107. </Button>
  108. )}
  109. </Feature>
  110. );
  111. }
  112. render() {
  113. const {project} = this.props;
  114. const {shouldShow} = this.state;
  115. if (!shouldShow) {
  116. return null;
  117. }
  118. const docsLink = getConfigureTracingDocsLink(project);
  119. // if the platform does not support performance, do not show this prompt
  120. if (docsLink === null) {
  121. return null;
  122. }
  123. return (
  124. <ExampleQuickTracePanel dashedBorder>
  125. <div>
  126. <Header>{t('Configure Distributed Tracing')}</Header>
  127. <Description>
  128. {t('See what happened right before and after this error')}
  129. </Description>
  130. </div>
  131. <Image src={quickTraceExample} alt="configure distributed tracing" />
  132. <ActionButtons>
  133. {this.renderActionButton(docsLink)}
  134. <ButtonBar merged>
  135. <Button
  136. title={t('Remind me next month')}
  137. size="sm"
  138. onClick={() =>
  139. this.handleClick({
  140. action: 'snoozed',
  141. eventKey: 'quick_trace.missing_instrumentation.snoozed',
  142. eventName: 'Quick Trace: Missing Instrumentation Snoozed',
  143. })
  144. }
  145. >
  146. {t('Snooze')}
  147. </Button>
  148. <Button
  149. title={t('Dismiss for this project')}
  150. size="sm"
  151. onClick={() =>
  152. this.handleClick({
  153. action: 'dismissed',
  154. eventKey: 'quick_trace.missing_instrumentation.dismissed',
  155. eventName: 'Quick Trace: Missing Instrumentation Dismissed',
  156. })
  157. }
  158. >
  159. {t('Dismiss')}
  160. </Button>
  161. </ButtonBar>
  162. </ActionButtons>
  163. </ExampleQuickTracePanel>
  164. );
  165. }
  166. }
  167. const ExampleQuickTracePanel = styled(Panel)`
  168. display: grid;
  169. grid-template-columns: 1.5fr 1fr;
  170. grid-template-rows: auto max-content;
  171. gap: ${space(1)};
  172. background: none;
  173. padding: ${space(2)};
  174. margin: ${space(2)} 0;
  175. `;
  176. const Header = styled('h3')`
  177. font-size: ${p => p.theme.fontSizeSmall};
  178. text-transform: uppercase;
  179. color: ${p => p.theme.gray300};
  180. margin-bottom: ${space(1)};
  181. `;
  182. const Description = styled('div')`
  183. font-size: ${p => p.theme.fontSizeMedium};
  184. `;
  185. const Image = styled('img')`
  186. grid-row: 1/3;
  187. grid-column: 2/3;
  188. justify-self: end;
  189. `;
  190. const ActionButtons = styled('div')`
  191. display: grid;
  192. grid-template-columns: max-content auto;
  193. justify-items: start;
  194. align-items: end;
  195. grid-column-gap: ${space(1)};
  196. `;
  197. export default withApi(ConfigureDistributedTracing);