electron.tsx 11 KB

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