electron.tsx 8.1 KB

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