electron.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 {getJSMetricsOnboarding} from 'sentry/components/onboarding/gettingStartedDoc/utils/metricsOnboarding';
  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 getInstallConfig = () => [
  22. {
  23. code: [
  24. {
  25. label: 'npm',
  26. value: 'npm',
  27. language: 'bash',
  28. code: 'npm install --save @sentry/electron',
  29. },
  30. {
  31. label: 'yarn',
  32. value: 'yarn',
  33. language: 'bash',
  34. code: 'yarn add @sentry/electron',
  35. },
  36. ],
  37. },
  38. ];
  39. const onboarding: OnboardingConfig = {
  40. install: () => [
  41. {
  42. type: StepType.INSTALL,
  43. description: t('Add the Sentry Electron SDK package as a dependency:'),
  44. configurations: getInstallConfig(),
  45. },
  46. ],
  47. configure: params => [
  48. {
  49. type: StepType.CONFIGURE,
  50. description: tct(
  51. `You need to call [codeInit:Sentry.init] in the [codeMain:main] process and in every [codeRenderer:renderer] process you spawn.
  52. For more details about configuring the Electron SDK [docsLink:click here].`,
  53. {
  54. codeInit: <code />,
  55. codeMain: <code />,
  56. codeRenderer: <code />,
  57. docsLink: (
  58. <ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/electron/" />
  59. ),
  60. }
  61. ),
  62. configurations: [
  63. {
  64. language: 'javascript',
  65. code: getConfigureSnippet(params),
  66. },
  67. ],
  68. },
  69. getUploadSourceMapsStep({
  70. guideLink:
  71. 'https://docs.sentry.io/platforms/javascript/guides/electron/sourcemaps/',
  72. ...params,
  73. }),
  74. ],
  75. verify: () => [
  76. {
  77. type: StepType.VERIFY,
  78. description: t(
  79. `One way to verify your setup is by intentionally causing an error that breaks your application.`
  80. ),
  81. configurations: [
  82. {
  83. description: t(
  84. `Calling an undefined function will throw a JavaScript exception:`
  85. ),
  86. language: 'javascript',
  87. code: 'myUndefinedFunction();',
  88. },
  89. {
  90. description: t(
  91. `With Electron you can test native crash reporting by triggering a crash:`
  92. ),
  93. language: 'javascript',
  94. code: 'process.crash();',
  95. },
  96. ],
  97. additionalInfo: t(
  98. 'You may want to try inserting these code snippets into both your main and any renderer processes to verify Sentry is operational in both.'
  99. ),
  100. },
  101. ],
  102. };
  103. const replayOnboarding: OnboardingConfig = {
  104. install: () => [
  105. {
  106. type: StepType.INSTALL,
  107. description: tct(
  108. 'For the Session Replay to work, you must have the framework SDK (e.g. [code:@sentry/electron]) installed, minimum version 4.2.0.',
  109. {
  110. code: <code />,
  111. }
  112. ),
  113. configurations: getInstallConfig(),
  114. },
  115. ],
  116. configure: (params: Params) => [
  117. {
  118. type: StepType.CONFIGURE,
  119. isReplayConfigStep: true,
  120. description: getReplayConfigureDescription({
  121. link: 'https://docs.sentry.io/platforms/javascript/guides/electron/session-replay/',
  122. }),
  123. configurations: [
  124. {
  125. code: [
  126. {
  127. label: 'JavaScript',
  128. value: 'javascript',
  129. language: 'javascript',
  130. code: getReplaySDKSetupSnippet({
  131. importStatement: `import * as Sentry from "@sentry/electron";`,
  132. dsn: params.dsn,
  133. mask: params.mask,
  134. block: params.block,
  135. }),
  136. },
  137. ],
  138. },
  139. ],
  140. },
  141. ],
  142. verify: () => [],
  143. nextSteps: () => [],
  144. };
  145. const docs: Docs = {
  146. onboarding,
  147. replayOnboardingNpm: replayOnboarding,
  148. customMetricsOnboarding: getJSMetricsOnboarding({getInstallConfig}),
  149. };
  150. export default docs;