electron.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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. } from 'sentry/components/onboarding/gettingStartedDoc/utils/replayOnboarding';
  23. import {t, tct} from 'sentry/locale';
  24. type Params = DocsParams;
  25. const getConfigureSnippet = (params: Params) => `
  26. import * as Sentry from "@sentry/electron";
  27. Sentry.init({
  28. dsn: "${params.dsn}",
  29. });`;
  30. const getMetricsConfigureSnippet = (params: Params) => `
  31. import * as Sentry from '@sentry/electron/main';
  32. // main process init
  33. Sentry.init({
  34. dsn: "${params.dsn}",
  35. _experiments: {
  36. metricsAggregator: true,
  37. },
  38. });`;
  39. const getMetricsVerifySnippet = () => `
  40. // Add 4 to a counter named 'hits'
  41. Sentry.metrics.increment('hits', 4);`;
  42. const getInstallConfig = () => [
  43. {
  44. code: [
  45. {
  46. label: 'npm',
  47. value: 'npm',
  48. language: 'bash',
  49. code: 'npm install --save @sentry/electron',
  50. },
  51. {
  52. label: 'yarn',
  53. value: 'yarn',
  54. language: 'bash',
  55. code: 'yarn add @sentry/electron',
  56. },
  57. ],
  58. },
  59. ];
  60. const onboarding: OnboardingConfig = {
  61. install: () => [
  62. {
  63. type: StepType.INSTALL,
  64. description: t('Add the Sentry Electron SDK package as a dependency:'),
  65. configurations: getInstallConfig(),
  66. },
  67. ],
  68. configure: params => [
  69. {
  70. type: StepType.CONFIGURE,
  71. description: tct(
  72. `You need to call [codeInit:Sentry.init] in the [codeMain:main] process and in every [codeRenderer:renderer] process you spawn.
  73. For more details about configuring the Electron SDK [docsLink:click here].`,
  74. {
  75. codeInit: <code />,
  76. codeMain: <code />,
  77. codeRenderer: <code />,
  78. docsLink: (
  79. <ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/electron/" />
  80. ),
  81. }
  82. ),
  83. configurations: [
  84. {
  85. language: 'javascript',
  86. code: getConfigureSnippet(params),
  87. },
  88. ],
  89. },
  90. getUploadSourceMapsStep({
  91. guideLink:
  92. 'https://docs.sentry.io/platforms/javascript/guides/electron/sourcemaps/',
  93. ...params,
  94. }),
  95. ],
  96. verify: () => [
  97. {
  98. type: StepType.VERIFY,
  99. description: t(
  100. `One way to verify your setup is by intentionally causing an error that breaks your application.`
  101. ),
  102. configurations: [
  103. {
  104. description: t(
  105. `Calling an undefined function will throw a JavaScript exception:`
  106. ),
  107. language: 'javascript',
  108. code: 'myUndefinedFunction();',
  109. },
  110. {
  111. description: t(
  112. `With Electron you can test native crash reporting by triggering a crash:`
  113. ),
  114. language: 'javascript',
  115. code: 'process.crash();',
  116. },
  117. ],
  118. additionalInfo: t(
  119. 'You may want to try inserting these code snippets into both your main and any renderer processes to verify Sentry is operational in both.'
  120. ),
  121. },
  122. ],
  123. };
  124. const replayOnboarding: OnboardingConfig = {
  125. install: () => [
  126. {
  127. type: StepType.INSTALL,
  128. description: tct(
  129. 'For the Session Replay to work, you must have the framework SDK (e.g. [code:@sentry/electron]) installed, minimum version 4.2.0.',
  130. {
  131. code: <code />,
  132. }
  133. ),
  134. configurations: getInstallConfig(),
  135. },
  136. ],
  137. configure: (params: Params) => [
  138. {
  139. type: StepType.CONFIGURE,
  140. description: getReplayConfigureDescription({
  141. link: 'https://docs.sentry.io/platforms/javascript/guides/electron/session-replay/',
  142. }),
  143. configurations: [
  144. {
  145. code: [
  146. {
  147. label: 'JavaScript',
  148. value: 'javascript',
  149. language: 'javascript',
  150. code: getReplaySDKSetupSnippet({
  151. importStatement: `import * as Sentry from "@sentry/electron/renderer";`,
  152. dsn: params.dsn,
  153. mask: params.replayOptions?.mask,
  154. block: params.replayOptions?.block,
  155. }),
  156. },
  157. ],
  158. additionalInfo: <TracePropagationMessage />,
  159. },
  160. ],
  161. },
  162. ],
  163. verify: () => [],
  164. nextSteps: () => [],
  165. };
  166. const customMetricsOnboarding: OnboardingConfig = {
  167. install: () => [
  168. {
  169. type: StepType.INSTALL,
  170. description: tct(
  171. 'You need a minimum version [codeVersion:4.17.0] of [codePackage:@sentry/electron].',
  172. {
  173. codeVersion: <code />,
  174. codePackage: <code />,
  175. }
  176. ),
  177. configurations: getInstallConfig(),
  178. },
  179. ],
  180. configure: params => [
  181. {
  182. type: StepType.CONFIGURE,
  183. description: tct(
  184. 'To enable capturing metrics, you first need to add the [codeIntegration:metricsAggregator] experiment to your [codeNamespace:Sentry.init] call in your main process.',
  185. {
  186. codeIntegration: <code />,
  187. codeNamespace: <code />,
  188. }
  189. ),
  190. configurations: [
  191. {
  192. code: [
  193. {
  194. label: 'JavaScript',
  195. value: 'javascript',
  196. language: 'javascript',
  197. code: getMetricsConfigureSnippet(params),
  198. },
  199. ],
  200. },
  201. ],
  202. },
  203. ],
  204. verify: () => [
  205. {
  206. type: StepType.VERIFY,
  207. description: tct(
  208. "Then you'll be able to add metrics as [codeCounters:counters], [codeSets:sets], [codeDistribution:distributions], and [codeGauge:gauges]. These are available under the [codeNamespace:Sentry.metrics] namespace. This API is available in both renderer and main processes. Try out this example:",
  209. {
  210. codeCounters: <code />,
  211. codeSets: <code />,
  212. codeDistribution: <code />,
  213. codeGauge: <code />,
  214. codeNamespace: <code />,
  215. }
  216. ),
  217. configurations: [
  218. {
  219. code: [
  220. {
  221. label: 'JavaScript',
  222. value: 'javascript',
  223. language: 'javascript',
  224. code: getMetricsVerifySnippet(),
  225. },
  226. ],
  227. },
  228. {
  229. description: t(
  230. 'With a bit of delay you can see the data appear in the Sentry UI.'
  231. ),
  232. },
  233. {
  234. description: tct(
  235. 'Learn more about metrics and how to configure them, by reading the [docsLink:docs].',
  236. {
  237. docsLink: (
  238. <ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/electron/metrics/" />
  239. ),
  240. }
  241. ),
  242. },
  243. ],
  244. },
  245. ],
  246. };
  247. const feedbackOnboarding: OnboardingConfig = {
  248. install: () => [
  249. {
  250. type: StepType.INSTALL,
  251. description: tct(
  252. '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.',
  253. {
  254. code: <code />,
  255. }
  256. ),
  257. configurations: getInstallConfig(),
  258. },
  259. ],
  260. configure: (params: Params) => [
  261. {
  262. type: StepType.CONFIGURE,
  263. description: getFeedbackConfigureDescription({
  264. linkConfig:
  265. 'https://docs.sentry.io/platforms/javascript/guides/electron/user-feedback/configuration/',
  266. linkButton:
  267. 'https://docs.sentry.io/platforms/javascript/guides/electron/user-feedback/configuration/#bring-your-own-button',
  268. }),
  269. configurations: [
  270. {
  271. code: [
  272. {
  273. label: 'JavaScript',
  274. value: 'javascript',
  275. language: 'javascript',
  276. code: getFeedbackSDKSetupSnippet({
  277. importStatement: `import * as Sentry from "@sentry/electron/renderer";`,
  278. dsn: params.dsn,
  279. feedbackOptions: params.feedbackOptions,
  280. }),
  281. },
  282. ],
  283. },
  284. ],
  285. additionalInfo: crashReportCallout({
  286. link: 'https://docs.sentry.io/platforms/javascript/guides/electron/user-feedback/#crash-report-modal',
  287. }),
  288. },
  289. ],
  290. verify: () => [],
  291. nextSteps: () => [],
  292. };
  293. const crashReportOnboarding: OnboardingConfig = {
  294. introduction: () => getCrashReportModalIntroduction(),
  295. install: (params: Params) => [
  296. {
  297. type: StepType.INSTALL,
  298. description: getCrashReportModalInstallDescriptionJavaScript(),
  299. configurations: [
  300. {
  301. code: [
  302. {
  303. label: 'JavaScript',
  304. value: 'javascript',
  305. language: 'javascript',
  306. code: `const { init, showReportDialog } = require("@sentry/electron");
  307. init({
  308. dsn: "${params.dsn}",
  309. beforeSend(event) {
  310. // Check if it is an exception, if so, show the report dialog
  311. // Note that this only will work in the renderer process, it's a noop on the main process
  312. if (event.exception && event.event_id) {
  313. showReportDialog({ eventId: event_id });
  314. }
  315. return event;
  316. },
  317. });`,
  318. },
  319. ],
  320. },
  321. ],
  322. },
  323. ],
  324. configure: () => [
  325. {
  326. type: StepType.CONFIGURE,
  327. description: getCrashReportModalConfigDescription({
  328. link: 'https://docs.sentry.io/platforms/javascript/guides/electron/user-feedback/configuration/#crash-report-modal',
  329. }),
  330. additionalInfo: widgetCallout({
  331. link: 'https://docs.sentry.io/platforms/javascript/guides/electron/user-feedback/#user-feedback-widget',
  332. }),
  333. },
  334. ],
  335. verify: () => [],
  336. nextSteps: () => [],
  337. };
  338. const docs: Docs = {
  339. onboarding,
  340. feedbackOnboardingNpm: feedbackOnboarding,
  341. replayOnboardingNpm: replayOnboarding,
  342. customMetricsOnboarding,
  343. crashReportOnboarding,
  344. };
  345. export default docs;