electron.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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. // Only needed for SDK versions < 8.0.0
  38. // _experiments: {
  39. // metricsAggregator: true,
  40. // },
  41. });`;
  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: t(
  184. 'With the default snippet in place, there is no need for any further configuration.'
  185. ),
  186. configurations: [
  187. {
  188. code: getMetricsConfigureSnippet(params),
  189. language: 'javascript',
  190. },
  191. ],
  192. },
  193. ],
  194. verify: () => [
  195. {
  196. type: StepType.VERIFY,
  197. description: tct(
  198. "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.",
  199. {
  200. codeCounters: <code />,
  201. codeSets: <code />,
  202. codeDistribution: <code />,
  203. codeGauge: <code />,
  204. codeNamespace: <code />,
  205. }
  206. ),
  207. configurations: [
  208. {
  209. description: metricTagsExplanation,
  210. },
  211. {
  212. description: t('Try out these examples:'),
  213. code: [
  214. {
  215. label: 'Counter',
  216. value: 'counter',
  217. language: 'javascript',
  218. code: exampleSnippets.javascript.counter,
  219. },
  220. {
  221. label: 'Distribution',
  222. value: 'distribution',
  223. language: 'javascript',
  224. code: exampleSnippets.javascript.distribution,
  225. },
  226. {
  227. label: 'Set',
  228. value: 'set',
  229. language: 'javascript',
  230. code: exampleSnippets.javascript.set,
  231. },
  232. {
  233. label: 'Gauge',
  234. value: 'gauge',
  235. language: 'javascript',
  236. code: exampleSnippets.javascript.gauge,
  237. },
  238. ],
  239. },
  240. {
  241. description: t(
  242. 'It can take up to 3 minutes for the data to appear in the Sentry UI.'
  243. ),
  244. },
  245. {
  246. description: tct(
  247. 'Learn more about metrics and how to configure them, by reading the [docsLink:docs].',
  248. {
  249. docsLink: (
  250. <ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/electron/metrics/" />
  251. ),
  252. }
  253. ),
  254. },
  255. ],
  256. },
  257. ],
  258. };
  259. const feedbackOnboarding: OnboardingConfig = {
  260. install: () => [
  261. {
  262. type: StepType.INSTALL,
  263. description: tct(
  264. '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.',
  265. {
  266. code: <code />,
  267. }
  268. ),
  269. configurations: getInstallConfig(),
  270. },
  271. ],
  272. configure: (params: Params) => [
  273. {
  274. type: StepType.CONFIGURE,
  275. description: getFeedbackConfigureDescription({
  276. linkConfig:
  277. 'https://docs.sentry.io/platforms/javascript/guides/electron/user-feedback/configuration/',
  278. linkButton:
  279. 'https://docs.sentry.io/platforms/javascript/guides/electron/user-feedback/configuration/#bring-your-own-button',
  280. }),
  281. configurations: [
  282. {
  283. code: [
  284. {
  285. label: 'JavaScript',
  286. value: 'javascript',
  287. language: 'javascript',
  288. code: getFeedbackSDKSetupSnippet({
  289. importStatement: `import * as Sentry from "@sentry/electron/renderer";`,
  290. dsn: params.dsn,
  291. feedbackOptions: params.feedbackOptions,
  292. }),
  293. },
  294. ],
  295. },
  296. ],
  297. additionalInfo: crashReportCallout({
  298. link: 'https://docs.sentry.io/platforms/javascript/guides/electron/user-feedback/#crash-report-modal',
  299. }),
  300. },
  301. ],
  302. verify: () => [],
  303. nextSteps: () => [],
  304. };
  305. const crashReportOnboarding: OnboardingConfig = {
  306. introduction: () => getCrashReportModalIntroduction(),
  307. install: (params: Params) => [
  308. {
  309. type: StepType.INSTALL,
  310. description: getCrashReportModalInstallDescriptionJavaScript(),
  311. configurations: [
  312. {
  313. code: [
  314. {
  315. label: 'JavaScript',
  316. value: 'javascript',
  317. language: 'javascript',
  318. code: `const { init, showReportDialog } = require("@sentry/electron");
  319. init({
  320. dsn: "${params.dsn}",
  321. beforeSend(event) {
  322. // Check if it is an exception, if so, show the report dialog
  323. // Note that this only will work in the renderer process, it's a noop on the main process
  324. if (event.exception && event.event_id) {
  325. showReportDialog({ eventId: event_id });
  326. }
  327. return event;
  328. },
  329. });`,
  330. },
  331. ],
  332. },
  333. ],
  334. },
  335. ],
  336. configure: () => [
  337. {
  338. type: StepType.CONFIGURE,
  339. description: getCrashReportModalConfigDescription({
  340. link: 'https://docs.sentry.io/platforms/javascript/guides/electron/user-feedback/configuration/#crash-report-modal',
  341. }),
  342. additionalInfo: widgetCallout({
  343. link: 'https://docs.sentry.io/platforms/javascript/guides/electron/user-feedback/#user-feedback-widget',
  344. }),
  345. },
  346. ],
  347. verify: () => [],
  348. nextSteps: () => [],
  349. };
  350. const docs: Docs = {
  351. onboarding,
  352. feedbackOnboardingNpm: feedbackOnboarding,
  353. replayOnboardingNpm: replayOnboarding,
  354. customMetricsOnboarding,
  355. crashReportOnboarding,
  356. };
  357. export default docs;