integrationSetup.tsx 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. import 'prism-sentry/index.css';
  2. import {Component, Fragment} from 'react';
  3. import styled from '@emotion/styled';
  4. import {motion} from 'framer-motion';
  5. import {openInviteMembersModal} from 'sentry/actionCreators/modal';
  6. import {Client} from 'sentry/api';
  7. import Alert from 'sentry/components/alert';
  8. import Button from 'sentry/components/button';
  9. import ButtonBar from 'sentry/components/buttonBar';
  10. import LoadingError from 'sentry/components/loadingError';
  11. import {PlatformKey} from 'sentry/data/platformCategories';
  12. import platforms from 'sentry/data/platforms';
  13. import {t, tct} from 'sentry/locale';
  14. import space from 'sentry/styles/space';
  15. import {IntegrationProvider, Organization} from 'sentry/types';
  16. import trackAdvancedAnalyticsEvent from 'sentry/utils/analytics/trackAdvancedAnalyticsEvent';
  17. import getDynamicText from 'sentry/utils/getDynamicText';
  18. import {trackIntegrationAnalytics} from 'sentry/utils/integrationUtil';
  19. import withApi from 'sentry/utils/withApi';
  20. import withOrganization from 'sentry/utils/withOrganization';
  21. import AddIntegrationButton from 'sentry/views/organizationIntegrations/addIntegrationButton';
  22. import FirstEventFooter from './components/firstEventFooter';
  23. import AddInstallationInstructions from './components/integrations/addInstallationInstructions';
  24. import PostInstallCodeSnippet from './components/integrations/postInstallCodeSnippet';
  25. import SetupIntroduction from './components/setupIntroduction';
  26. import {StepProps} from './types';
  27. type Props = StepProps & {
  28. api: Client;
  29. integrationSlug: string;
  30. organization: Organization;
  31. };
  32. type State = {
  33. hasError: boolean;
  34. installed: boolean;
  35. loadedPlatform: PlatformKey | null;
  36. provider: IntegrationProvider | null;
  37. };
  38. class IntegrationSetup extends Component<Props, State> {
  39. state: State = {
  40. loadedPlatform: null,
  41. hasError: false,
  42. provider: null,
  43. installed: false,
  44. };
  45. componentDidMount() {
  46. this.fetchData();
  47. }
  48. componentDidUpdate(nextProps: Props) {
  49. if (
  50. nextProps.platform !== this.props.platform ||
  51. nextProps.project !== this.props.project
  52. ) {
  53. this.fetchData();
  54. }
  55. }
  56. get manualSetupUrl() {
  57. const {search} = window.location;
  58. // honor any existing query params
  59. const separator = search.includes('?') ? '&' : '?';
  60. return `${search}${separator}manual=1`;
  61. }
  62. get platformDocs() {
  63. // TODO: make dynamic based on the integration
  64. return 'https://docs.sentry.io/product/integrations/cloud-monitoring/aws-lambda/';
  65. }
  66. fetchData = async () => {
  67. const {api, organization, platform, integrationSlug} = this.props;
  68. if (!integrationSlug) {
  69. return;
  70. }
  71. try {
  72. const endpoint = `/organizations/${organization.slug}/config/integrations/?provider_key=${integrationSlug}`;
  73. const integrations = await api.requestPromise(endpoint);
  74. const provider = integrations.providers[0];
  75. this.setState({provider, loadedPlatform: platform, hasError: false});
  76. } catch (error) {
  77. this.setState({hasError: error});
  78. throw error;
  79. }
  80. };
  81. handleFullDocsClick = () => {
  82. const {organization} = this.props;
  83. trackAdvancedAnalyticsEvent('growth.onboarding_view_full_docs', {organization});
  84. };
  85. trackSwitchToManual = () => {
  86. const {organization, integrationSlug} = this.props;
  87. trackIntegrationAnalytics('integrations.switch_manual_sdk_setup', {
  88. integration_type: 'first_party',
  89. integration: integrationSlug,
  90. view: 'onboarding',
  91. organization,
  92. });
  93. };
  94. handleAddIntegration = () => {
  95. this.setState({installed: true});
  96. };
  97. renderSetupInstructions = () => {
  98. const {platform} = this.props;
  99. const {loadedPlatform} = this.state;
  100. const currentPlatform = loadedPlatform ?? platform ?? 'other';
  101. return (
  102. <SetupIntroduction
  103. stepHeaderText={t(
  104. 'Automatically instrument %s',
  105. platforms.find(p => p.id === currentPlatform)?.name ?? ''
  106. )}
  107. platform={currentPlatform}
  108. />
  109. );
  110. };
  111. renderIntegrationInstructions() {
  112. const {organization, project} = this.props;
  113. const {provider} = this.state;
  114. if (!provider || !project) {
  115. return null;
  116. }
  117. return (
  118. <Fragment>
  119. {this.renderSetupInstructions()}
  120. <motion.p
  121. variants={{
  122. initial: {opacity: 0},
  123. animate: {opacity: 1},
  124. exit: {opacity: 0},
  125. }}
  126. >
  127. {tct(
  128. "Don't have have permissions to create a Cloudformation stack? [link:Invite your team instead].",
  129. {
  130. link: (
  131. <Button
  132. priority="link"
  133. onClick={() => {
  134. openInviteMembersModal();
  135. }}
  136. aria-label={t('Invite your team instead')}
  137. />
  138. ),
  139. }
  140. )}
  141. </motion.p>
  142. <motion.div
  143. variants={{
  144. initial: {opacity: 0},
  145. animate: {opacity: 1},
  146. exit: {opacity: 0},
  147. }}
  148. >
  149. <AddInstallationInstructions />
  150. </motion.div>
  151. <DocsWrapper>
  152. <StyledButtonBar gap={1}>
  153. <AddIntegrationButton
  154. provider={provider}
  155. onAddIntegration={this.handleAddIntegration}
  156. organization={organization}
  157. priority="primary"
  158. size="sm"
  159. analyticsParams={{view: 'onboarding', already_installed: false}}
  160. modalParams={{projectId: project.id}}
  161. />
  162. <Button
  163. size="sm"
  164. to={{
  165. pathname: window.location.pathname,
  166. query: {manual: '1'},
  167. }}
  168. onClick={this.trackSwitchToManual}
  169. >
  170. {t('Manual Setup')}
  171. </Button>
  172. </StyledButtonBar>
  173. </DocsWrapper>
  174. </Fragment>
  175. );
  176. }
  177. renderPostInstallInstructions() {
  178. const {organization, project, platform} = this.props;
  179. const {provider} = this.state;
  180. if (!project || !provider || !platform) {
  181. return null;
  182. }
  183. return (
  184. <Fragment>
  185. {this.renderSetupInstructions()}
  186. <PostInstallCodeSnippet provider={provider} platform={platform} isOnboarding />
  187. <FirstEventFooter
  188. project={project}
  189. organization={organization}
  190. docsLink={this.platformDocs}
  191. docsOnClick={this.handleFullDocsClick}
  192. />
  193. </Fragment>
  194. );
  195. }
  196. render() {
  197. const {platform} = this.props;
  198. const {hasError} = this.state;
  199. const loadingError = (
  200. <LoadingError
  201. message={t('Failed to load the integration for the %s platform.', platform)}
  202. onRetry={this.fetchData}
  203. />
  204. );
  205. const testOnlyAlert = (
  206. <Alert type="warning">
  207. Platform documentation is not rendered in for tests in CI
  208. </Alert>
  209. );
  210. return (
  211. <Fragment>
  212. {this.state.installed
  213. ? this.renderPostInstallInstructions()
  214. : this.renderIntegrationInstructions()}
  215. {getDynamicText({
  216. value: !hasError ? null : loadingError,
  217. fixed: testOnlyAlert,
  218. })}
  219. </Fragment>
  220. );
  221. }
  222. }
  223. const DocsWrapper = styled(motion.div)``;
  224. DocsWrapper.defaultProps = {
  225. initial: {opacity: 0, y: 40},
  226. animate: {opacity: 1, y: 0},
  227. exit: {opacity: 0},
  228. };
  229. const StyledButtonBar = styled(ButtonBar)`
  230. margin-top: ${space(3)};
  231. width: max-content;
  232. @media (max-width: ${p => p.theme.breakpoints.small}) {
  233. width: auto;
  234. grid-row-gap: ${space(1)};
  235. grid-auto-flow: row;
  236. }
  237. `;
  238. export default withOrganization(withApi(IntegrationSetup));