electron.tsx 6.9 KB

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