electron.tsx 4.4 KB

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