electron.tsx 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. import ExternalLink from 'sentry/components/links/externalLink';
  2. import crashReportCallout from 'sentry/components/onboarding/gettingStartedDoc/feedback/crashReportCallout';
  3. import widgetCallout from 'sentry/components/onboarding/gettingStartedDoc/feedback/widgetCallout';
  4. import TracePropagationMessage from 'sentry/components/onboarding/gettingStartedDoc/replay/tracePropagationMessage';
  5. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  6. import type {
  7. Docs,
  8. DocsParams,
  9. OnboardingConfig,
  10. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  11. import {getUploadSourceMapsStep} from 'sentry/components/onboarding/gettingStartedDoc/utils';
  12. import {
  13. getCrashReportModalConfigDescription,
  14. getCrashReportModalInstallDescriptionJavaScript,
  15. getCrashReportModalIntroduction,
  16. getFeedbackConfigureDescription,
  17. getFeedbackSDKSetupSnippet,
  18. } from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
  19. import {
  20. getReplayConfigureDescription,
  21. getReplaySDKSetupSnippet,
  22. getReplayVerifyStep,
  23. } from 'sentry/components/onboarding/gettingStartedDoc/utils/replayOnboarding';
  24. import {t, tct} from 'sentry/locale';
  25. type Params = DocsParams;
  26. const getConfigureSnippet = (params: Params) => `
  27. import * as Sentry from "@sentry/electron";
  28. Sentry.init({
  29. dsn: "${params.dsn.public}",
  30. });`;
  31. const getInstallConfig = () => [
  32. {
  33. code: [
  34. {
  35. label: 'npm',
  36. value: 'npm',
  37. language: 'bash',
  38. code: 'npm install --save @sentry/electron',
  39. },
  40. {
  41. label: 'yarn',
  42. value: 'yarn',
  43. language: 'bash',
  44. code: 'yarn add @sentry/electron',
  45. },
  46. ],
  47. },
  48. ];
  49. const onboarding: OnboardingConfig = {
  50. install: () => [
  51. {
  52. type: StepType.INSTALL,
  53. description: t('Add the Sentry Electron SDK package as a dependency:'),
  54. configurations: getInstallConfig(),
  55. },
  56. ],
  57. configure: params => [
  58. {
  59. type: StepType.CONFIGURE,
  60. description: tct(
  61. `You need to call [code:Sentry.init] in the [code:main] process and in every [code:renderer] process you spawn.
  62. For more details about configuring the Electron SDK [docsLink:click here].`,
  63. {
  64. code: <code />,
  65. docsLink: (
  66. <ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/electron/" />
  67. ),
  68. }
  69. ),
  70. configurations: [
  71. {
  72. language: 'javascript',
  73. code: getConfigureSnippet(params),
  74. },
  75. ],
  76. },
  77. getUploadSourceMapsStep({
  78. guideLink:
  79. 'https://docs.sentry.io/platforms/javascript/guides/electron/sourcemaps/',
  80. ...params,
  81. }),
  82. ],
  83. verify: () => [
  84. {
  85. type: StepType.VERIFY,
  86. description: t(
  87. `One way to verify your setup is by intentionally causing an error that breaks your application.`
  88. ),
  89. configurations: [
  90. {
  91. description: t(
  92. `Calling an undefined function will throw a JavaScript exception:`
  93. ),
  94. language: 'javascript',
  95. code: 'myUndefinedFunction();',
  96. },
  97. {
  98. description: t(
  99. `With Electron you can test native crash reporting by triggering a crash:`
  100. ),
  101. language: 'javascript',
  102. code: 'process.crash();',
  103. },
  104. ],
  105. additionalInfo: t(
  106. 'You may want to try inserting these code snippets into both your main and any renderer processes to verify Sentry is operational in both.'
  107. ),
  108. },
  109. ],
  110. };
  111. const replayOnboarding: OnboardingConfig = {
  112. install: () => [
  113. {
  114. type: StepType.INSTALL,
  115. description: tct(
  116. 'For the Session Replay to work, you must have the framework SDK (e.g. [code:@sentry/electron]) installed, minimum version 4.2.0.',
  117. {
  118. code: <code />,
  119. }
  120. ),
  121. configurations: getInstallConfig(),
  122. },
  123. ],
  124. configure: (params: Params) => [
  125. {
  126. type: StepType.CONFIGURE,
  127. description: getReplayConfigureDescription({
  128. link: 'https://docs.sentry.io/platforms/javascript/guides/electron/session-replay/',
  129. }),
  130. configurations: [
  131. {
  132. code: [
  133. {
  134. label: 'JavaScript',
  135. value: 'javascript',
  136. language: 'javascript',
  137. code: getReplaySDKSetupSnippet({
  138. importStatement: `import * as Sentry from "@sentry/electron/renderer";`,
  139. dsn: params.dsn.public,
  140. mask: params.replayOptions?.mask,
  141. block: params.replayOptions?.block,
  142. }),
  143. },
  144. ],
  145. additionalInfo: <TracePropagationMessage />,
  146. },
  147. ],
  148. },
  149. ],
  150. verify: getReplayVerifyStep(),
  151. nextSteps: () => [],
  152. };
  153. const feedbackOnboarding: OnboardingConfig = {
  154. install: () => [
  155. {
  156. type: StepType.INSTALL,
  157. description: tct(
  158. 'For the User Feedback integration to work, you must have the Sentry browser SDK package, or an equivalent framework SDK (e.g. [code:@sentry/electron]) installed, minimum version 7.85.0.',
  159. {
  160. code: <code />,
  161. }
  162. ),
  163. configurations: getInstallConfig(),
  164. },
  165. ],
  166. configure: (params: Params) => [
  167. {
  168. type: StepType.CONFIGURE,
  169. description: getFeedbackConfigureDescription({
  170. linkConfig:
  171. 'https://docs.sentry.io/platforms/javascript/guides/electron/user-feedback/configuration/',
  172. linkButton:
  173. 'https://docs.sentry.io/platforms/javascript/guides/electron/user-feedback/configuration/#bring-your-own-button',
  174. }),
  175. configurations: [
  176. {
  177. code: [
  178. {
  179. label: 'JavaScript',
  180. value: 'javascript',
  181. language: 'javascript',
  182. code: getFeedbackSDKSetupSnippet({
  183. importStatement: `import * as Sentry from "@sentry/electron/renderer";`,
  184. dsn: params.dsn.public,
  185. feedbackOptions: params.feedbackOptions,
  186. }),
  187. },
  188. ],
  189. },
  190. ],
  191. additionalInfo: crashReportCallout({
  192. link: 'https://docs.sentry.io/platforms/javascript/guides/electron/user-feedback/#crash-report-modal',
  193. }),
  194. },
  195. ],
  196. verify: () => [],
  197. nextSteps: () => [],
  198. };
  199. const crashReportOnboarding: OnboardingConfig = {
  200. introduction: () => getCrashReportModalIntroduction(),
  201. install: (params: Params) => [
  202. {
  203. type: StepType.INSTALL,
  204. description: getCrashReportModalInstallDescriptionJavaScript(),
  205. configurations: [
  206. {
  207. code: [
  208. {
  209. label: 'JavaScript',
  210. value: 'javascript',
  211. language: 'javascript',
  212. code: `const { init, showReportDialog } = require("@sentry/electron");
  213. init({
  214. dsn: "${params.dsn.public}",
  215. beforeSend(event) {
  216. // Check if it is an exception, if so, show the report dialog
  217. // Note that this only will work in the renderer process, it's a noop on the main process
  218. if (event.exception && event.event_id) {
  219. showReportDialog({ eventId: event_id });
  220. }
  221. return event;
  222. },
  223. });`,
  224. },
  225. ],
  226. },
  227. ],
  228. },
  229. ],
  230. configure: () => [
  231. {
  232. type: StepType.CONFIGURE,
  233. description: getCrashReportModalConfigDescription({
  234. link: 'https://docs.sentry.io/platforms/javascript/guides/electron/user-feedback/configuration/#crash-report-modal',
  235. }),
  236. additionalInfo: widgetCallout({
  237. link: 'https://docs.sentry.io/platforms/javascript/guides/electron/user-feedback/#user-feedback-widget',
  238. }),
  239. },
  240. ],
  241. verify: () => [],
  242. nextSteps: () => [],
  243. };
  244. const docs: Docs = {
  245. onboarding,
  246. feedbackOnboardingNpm: feedbackOnboarding,
  247. replayOnboarding,
  248. crashReportOnboarding,
  249. };
  250. export default docs;