electron.tsx 11 KB

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