electron.tsx 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. import ExternalLink from 'sentry/components/links/externalLink';
  2. import crashReportCallout from 'sentry/components/onboarding/gettingStartedDoc/feedback/crashReportCallout';
  3. import tracePropagationMessage from 'sentry/components/onboarding/gettingStartedDoc/replay/tracePropagationMessage';
  4. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  5. import type {
  6. Docs,
  7. DocsParams,
  8. OnboardingConfig,
  9. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  10. import {getUploadSourceMapsStep} from 'sentry/components/onboarding/gettingStartedDoc/utils';
  11. import {
  12. getFeedbackConfigureDescription,
  13. getFeedbackSDKSetupSnippet,
  14. } from 'sentry/components/onboarding/gettingStartedDoc/utils/feedbackOnboarding';
  15. import {
  16. getReplayConfigureDescription,
  17. getReplaySDKSetupSnippet,
  18. } from 'sentry/components/onboarding/gettingStartedDoc/utils/replayOnboarding';
  19. import {t, tct} from 'sentry/locale';
  20. type Params = DocsParams;
  21. const getConfigureSnippet = (params: Params) => `
  22. import * as Sentry from "@sentry/electron";
  23. Sentry.init({
  24. dsn: "${params.dsn}",
  25. });`;
  26. const getMetricsConfigureSnippet = (params: Params) => `
  27. import * as Sentry from '@sentry/electron/main';
  28. // main process init
  29. Sentry.init({
  30. dsn: "${params.dsn}",
  31. _experiments: {
  32. metricsAggregator: true,
  33. },
  34. });`;
  35. const getMetricsVerifySnippet = () => `
  36. // Add 4 to a counter named 'hits'
  37. Sentry.metrics.increment('hits', 4);`;
  38. const getInstallConfig = () => [
  39. {
  40. code: [
  41. {
  42. label: 'npm',
  43. value: 'npm',
  44. language: 'bash',
  45. code: 'npm install --save @sentry/electron',
  46. },
  47. {
  48. label: 'yarn',
  49. value: 'yarn',
  50. language: 'bash',
  51. code: 'yarn add @sentry/electron',
  52. },
  53. ],
  54. },
  55. ];
  56. const onboarding: OnboardingConfig = {
  57. install: () => [
  58. {
  59. type: StepType.INSTALL,
  60. description: t('Add the Sentry Electron SDK package as a dependency:'),
  61. configurations: getInstallConfig(),
  62. },
  63. ],
  64. configure: params => [
  65. {
  66. type: StepType.CONFIGURE,
  67. description: tct(
  68. `You need to call [codeInit:Sentry.init] in the [codeMain:main] process and in every [codeRenderer:renderer] process you spawn.
  69. For more details about configuring the Electron SDK [docsLink:click here].`,
  70. {
  71. codeInit: <code />,
  72. codeMain: <code />,
  73. codeRenderer: <code />,
  74. docsLink: (
  75. <ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/electron/" />
  76. ),
  77. }
  78. ),
  79. configurations: [
  80. {
  81. language: 'javascript',
  82. code: getConfigureSnippet(params),
  83. },
  84. ],
  85. },
  86. getUploadSourceMapsStep({
  87. guideLink:
  88. 'https://docs.sentry.io/platforms/javascript/guides/electron/sourcemaps/',
  89. ...params,
  90. }),
  91. ],
  92. verify: () => [
  93. {
  94. type: StepType.VERIFY,
  95. description: t(
  96. `One way to verify your setup is by intentionally causing an error that breaks your application.`
  97. ),
  98. configurations: [
  99. {
  100. description: t(
  101. `Calling an undefined function will throw a JavaScript exception:`
  102. ),
  103. language: 'javascript',
  104. code: 'myUndefinedFunction();',
  105. },
  106. {
  107. description: t(
  108. `With Electron you can test native crash reporting by triggering a crash:`
  109. ),
  110. language: 'javascript',
  111. code: 'process.crash();',
  112. },
  113. ],
  114. additionalInfo: t(
  115. 'You may want to try inserting these code snippets into both your main and any renderer processes to verify Sentry is operational in both.'
  116. ),
  117. },
  118. ],
  119. };
  120. const replayOnboarding: OnboardingConfig = {
  121. install: () => [
  122. {
  123. type: StepType.INSTALL,
  124. description: tct(
  125. 'For the Session Replay to work, you must have the framework SDK (e.g. [code:@sentry/electron]) installed, minimum version 4.2.0.',
  126. {
  127. code: <code />,
  128. }
  129. ),
  130. configurations: getInstallConfig(),
  131. },
  132. ],
  133. configure: (params: Params) => [
  134. {
  135. type: StepType.CONFIGURE,
  136. description: getReplayConfigureDescription({
  137. link: 'https://docs.sentry.io/platforms/javascript/guides/electron/session-replay/',
  138. }),
  139. configurations: [
  140. {
  141. code: [
  142. {
  143. label: 'JavaScript',
  144. value: 'javascript',
  145. language: 'javascript',
  146. code: getReplaySDKSetupSnippet({
  147. importStatement: `import * as Sentry from "@sentry/electron/renderer";`,
  148. dsn: params.dsn,
  149. mask: params.replayOptions?.mask,
  150. block: params.replayOptions?.block,
  151. }),
  152. },
  153. ],
  154. additionalInfo: tracePropagationMessage,
  155. },
  156. ],
  157. },
  158. ],
  159. verify: () => [],
  160. nextSteps: () => [],
  161. };
  162. const customMetricsOnboarding: OnboardingConfig = {
  163. install: () => [
  164. {
  165. type: StepType.INSTALL,
  166. description: tct(
  167. 'You need a minimum version [codeVersion:4.17.0] of [codePackage:@sentry/electron].',
  168. {
  169. codeVersion: <code />,
  170. codePackage: <code />,
  171. }
  172. ),
  173. configurations: getInstallConfig(),
  174. },
  175. ],
  176. configure: params => [
  177. {
  178. type: StepType.CONFIGURE,
  179. description: tct(
  180. 'To enable capturing metrics, you first need to add the [codeIntegration:metricsAggregator] experiment to your [codeNamespace:Sentry.init] call in your main process.',
  181. {
  182. codeIntegration: <code />,
  183. codeNamespace: <code />,
  184. }
  185. ),
  186. configurations: [
  187. {
  188. code: [
  189. {
  190. label: 'JavaScript',
  191. value: 'javascript',
  192. language: 'javascript',
  193. code: getMetricsConfigureSnippet(params),
  194. },
  195. ],
  196. },
  197. ],
  198. },
  199. ],
  200. verify: () => [
  201. {
  202. type: StepType.VERIFY,
  203. description: tct(
  204. "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:",
  205. {
  206. codeCounters: <code />,
  207. codeSets: <code />,
  208. codeDistribution: <code />,
  209. codeGauge: <code />,
  210. codeNamespace: <code />,
  211. }
  212. ),
  213. configurations: [
  214. {
  215. code: [
  216. {
  217. label: 'JavaScript',
  218. value: 'javascript',
  219. language: 'javascript',
  220. code: getMetricsVerifySnippet(),
  221. },
  222. ],
  223. },
  224. {
  225. description: t(
  226. 'With a bit of delay you can see the data appear in the Sentry UI.'
  227. ),
  228. },
  229. {
  230. description: tct(
  231. 'Learn more about metrics and how to configure them, by reading the [docsLink:docs].',
  232. {
  233. docsLink: (
  234. <ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/electron/metrics/" />
  235. ),
  236. }
  237. ),
  238. },
  239. ],
  240. },
  241. ],
  242. };
  243. const feedbackOnboarding: OnboardingConfig = {
  244. install: () => [
  245. {
  246. type: StepType.INSTALL,
  247. description: tct(
  248. '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.',
  249. {
  250. code: <code />,
  251. }
  252. ),
  253. configurations: getInstallConfig(),
  254. },
  255. ],
  256. configure: (params: Params) => [
  257. {
  258. type: StepType.CONFIGURE,
  259. description: getFeedbackConfigureDescription({
  260. link: 'https://docs.sentry.io/platforms/javascript/guides/electron/user-feedback/',
  261. }),
  262. configurations: [
  263. {
  264. code: [
  265. {
  266. label: 'JavaScript',
  267. value: 'javascript',
  268. language: 'javascript',
  269. code: getFeedbackSDKSetupSnippet({
  270. importStatement: `import * as Sentry from "@sentry/electron/renderer";`,
  271. dsn: params.dsn,
  272. }),
  273. },
  274. ],
  275. },
  276. ],
  277. additionalInfo: crashReportCallout({
  278. link: 'https://docs.sentry.io/platforms/javascript/guides/electron/user-feedback/#crash-report-modal',
  279. }),
  280. },
  281. ],
  282. verify: () => [],
  283. nextSteps: () => [],
  284. };
  285. const docs: Docs = {
  286. onboarding,
  287. feedbackOnboardingNpm: feedbackOnboarding,
  288. replayOnboardingNpm: replayOnboarding,
  289. customMetricsOnboarding,
  290. };
  291. export default docs;