electron.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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. getReplayVerifyStep,
  25. } from 'sentry/components/onboarding/gettingStartedDoc/utils/replayOnboarding';
  26. import {t, tct} from 'sentry/locale';
  27. type Params = DocsParams;
  28. const getConfigureSnippet = (params: Params) => `
  29. import * as Sentry from "@sentry/electron";
  30. Sentry.init({
  31. dsn: "${params.dsn.public}",
  32. });`;
  33. const getMetricsConfigureSnippet = (params: Params) => `
  34. import * as Sentry from '@sentry/electron/main';
  35. // main process init
  36. Sentry.init({
  37. dsn: "${params.dsn.public}",
  38. // Only needed for SDK versions < 8.0.0
  39. // _experiments: {
  40. // metricsAggregator: true,
  41. // },
  42. });`;
  43. const getInstallConfig = () => [
  44. {
  45. code: [
  46. {
  47. label: 'npm',
  48. value: 'npm',
  49. language: 'bash',
  50. code: 'npm install --save @sentry/electron',
  51. },
  52. {
  53. label: 'yarn',
  54. value: 'yarn',
  55. language: 'bash',
  56. code: 'yarn add @sentry/electron',
  57. },
  58. ],
  59. },
  60. ];
  61. const onboarding: OnboardingConfig = {
  62. install: () => [
  63. {
  64. type: StepType.INSTALL,
  65. description: t('Add the Sentry Electron SDK package as a dependency:'),
  66. configurations: getInstallConfig(),
  67. },
  68. ],
  69. configure: params => [
  70. {
  71. type: StepType.CONFIGURE,
  72. description: tct(
  73. `You need to call [code:Sentry.init] in the [code:main] process and in every [code:renderer] process you spawn.
  74. For more details about configuring the Electron SDK [docsLink:click here].`,
  75. {
  76. code: <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.public,
  152. mask: params.replayOptions?.mask,
  153. block: params.replayOptions?.block,
  154. }),
  155. },
  156. ],
  157. additionalInfo: <TracePropagationMessage />,
  158. },
  159. ],
  160. },
  161. ],
  162. verify: getReplayVerifyStep(),
  163. nextSteps: () => [],
  164. };
  165. const customMetricsOnboarding: OnboardingConfig = {
  166. install: () => [
  167. {
  168. type: StepType.INSTALL,
  169. description: tct(
  170. 'You need a minimum version [code:4.17.0] of [code:@sentry/electron].',
  171. {
  172. code: <code />,
  173. }
  174. ),
  175. configurations: getInstallConfig(),
  176. },
  177. ],
  178. configure: params => [
  179. {
  180. type: StepType.CONFIGURE,
  181. description: t(
  182. 'With the default snippet in place, there is no need for any further configuration.'
  183. ),
  184. configurations: [
  185. {
  186. code: getMetricsConfigureSnippet(params),
  187. language: 'javascript',
  188. },
  189. ],
  190. },
  191. ],
  192. verify: () => [
  193. {
  194. type: StepType.VERIFY,
  195. description: tct(
  196. "Then you'll be able to add metrics as [code:counters], [code:sets], [code:distributions], and [code:gauges]. These are available under the [code:Sentry.metrics] namespace. This API is available in both renderer and main processes.",
  197. {
  198. code: <code />,
  199. }
  200. ),
  201. configurations: [
  202. {
  203. description: metricTagsExplanation,
  204. },
  205. {
  206. description: t('Try out these examples:'),
  207. code: [
  208. {
  209. label: 'Counter',
  210. value: 'counter',
  211. language: 'javascript',
  212. code: exampleSnippets.javascript.counter,
  213. },
  214. {
  215. label: 'Distribution',
  216. value: 'distribution',
  217. language: 'javascript',
  218. code: exampleSnippets.javascript.distribution,
  219. },
  220. {
  221. label: 'Set',
  222. value: 'set',
  223. language: 'javascript',
  224. code: exampleSnippets.javascript.set,
  225. },
  226. {
  227. label: 'Gauge',
  228. value: 'gauge',
  229. language: 'javascript',
  230. code: exampleSnippets.javascript.gauge,
  231. },
  232. ],
  233. },
  234. {
  235. description: t(
  236. 'It can take up to 3 minutes for the data to appear in the Sentry UI.'
  237. ),
  238. },
  239. {
  240. description: tct(
  241. 'Learn more about metrics and how to configure them, by reading the [docsLink:docs].',
  242. {
  243. docsLink: (
  244. <ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/electron/metrics/" />
  245. ),
  246. }
  247. ),
  248. },
  249. ],
  250. },
  251. ],
  252. };
  253. const feedbackOnboarding: OnboardingConfig = {
  254. install: () => [
  255. {
  256. type: StepType.INSTALL,
  257. description: tct(
  258. '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.',
  259. {
  260. code: <code />,
  261. }
  262. ),
  263. configurations: getInstallConfig(),
  264. },
  265. ],
  266. configure: (params: Params) => [
  267. {
  268. type: StepType.CONFIGURE,
  269. description: getFeedbackConfigureDescription({
  270. linkConfig:
  271. 'https://docs.sentry.io/platforms/javascript/guides/electron/user-feedback/configuration/',
  272. linkButton:
  273. 'https://docs.sentry.io/platforms/javascript/guides/electron/user-feedback/configuration/#bring-your-own-button',
  274. }),
  275. configurations: [
  276. {
  277. code: [
  278. {
  279. label: 'JavaScript',
  280. value: 'javascript',
  281. language: 'javascript',
  282. code: getFeedbackSDKSetupSnippet({
  283. importStatement: `import * as Sentry from "@sentry/electron/renderer";`,
  284. dsn: params.dsn.public,
  285. feedbackOptions: params.feedbackOptions,
  286. }),
  287. },
  288. ],
  289. },
  290. ],
  291. additionalInfo: crashReportCallout({
  292. link: 'https://docs.sentry.io/platforms/javascript/guides/electron/user-feedback/#crash-report-modal',
  293. }),
  294. },
  295. ],
  296. verify: () => [],
  297. nextSteps: () => [],
  298. };
  299. const crashReportOnboarding: OnboardingConfig = {
  300. introduction: () => getCrashReportModalIntroduction(),
  301. install: (params: Params) => [
  302. {
  303. type: StepType.INSTALL,
  304. description: getCrashReportModalInstallDescriptionJavaScript(),
  305. configurations: [
  306. {
  307. code: [
  308. {
  309. label: 'JavaScript',
  310. value: 'javascript',
  311. language: 'javascript',
  312. code: `const { init, showReportDialog } = require("@sentry/electron");
  313. init({
  314. dsn: "${params.dsn.public}",
  315. beforeSend(event) {
  316. // Check if it is an exception, if so, show the report dialog
  317. // Note that this only will work in the renderer process, it's a noop on the main process
  318. if (event.exception && event.event_id) {
  319. showReportDialog({ eventId: event_id });
  320. }
  321. return event;
  322. },
  323. });`,
  324. },
  325. ],
  326. },
  327. ],
  328. },
  329. ],
  330. configure: () => [
  331. {
  332. type: StepType.CONFIGURE,
  333. description: getCrashReportModalConfigDescription({
  334. link: 'https://docs.sentry.io/platforms/javascript/guides/electron/user-feedback/configuration/#crash-report-modal',
  335. }),
  336. additionalInfo: widgetCallout({
  337. link: 'https://docs.sentry.io/platforms/javascript/guides/electron/user-feedback/#user-feedback-widget',
  338. }),
  339. },
  340. ],
  341. verify: () => [],
  342. nextSteps: () => [],
  343. };
  344. const docs: Docs = {
  345. onboarding,
  346. feedbackOnboardingNpm: feedbackOnboarding,
  347. replayOnboarding,
  348. customMetricsOnboarding,
  349. crashReportOnboarding,
  350. };
  351. export default docs;