electron.tsx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import ExternalLink from 'sentry/components/links/externalLink';
  2. import {Layout, LayoutProps} from 'sentry/components/onboarding/gettingStartedDoc/layout';
  3. import {ModuleProps} from 'sentry/components/onboarding/gettingStartedDoc/sdkDocumentation';
  4. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  5. import {getUploadSourceMapsStep} from 'sentry/components/onboarding/gettingStartedDoc/utils';
  6. import {t, tct} from 'sentry/locale';
  7. import type {Organization, PlatformKey} from 'sentry/types';
  8. type StepProps = {
  9. newOrg: boolean;
  10. organization: Organization;
  11. platformKey: PlatformKey;
  12. projectId: string;
  13. sentryInitContent: string;
  14. };
  15. export const steps = ({
  16. sentryInitContent,
  17. ...props
  18. }: Partial<StepProps> = {}): LayoutProps['steps'] => [
  19. {
  20. type: StepType.INSTALL,
  21. description: t('Add the Sentry Electron SDK package as a dependency:'),
  22. configurations: [
  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. },
  41. {
  42. type: StepType.CONFIGURE,
  43. description: (
  44. <p>
  45. {tct(
  46. `You need to call [codeInit:Sentry.init] in the [codeMain:main] process and in every [codeRenderer:renderer] process you spawn.
  47. For more details about configuring the Electron SDK [docsLink:click here].`,
  48. {
  49. codeInit: <code />,
  50. codeMain: <code />,
  51. codeRenderer: <code />,
  52. docsLink: (
  53. <ExternalLink href="https://docs.sentry.io/platforms/javascript/guides/electron/" />
  54. ),
  55. }
  56. )}
  57. </p>
  58. ),
  59. configurations: [
  60. {
  61. language: 'javascript',
  62. code: `
  63. import * as Sentry from "@sentry/electron";
  64. Sentry.init({
  65. ${sentryInitContent}
  66. });
  67. `,
  68. },
  69. ],
  70. },
  71. getUploadSourceMapsStep({
  72. guideLink: 'https://docs.sentry.io/platforms/javascript/guides/electron/sourcemaps/',
  73. ...props,
  74. }),
  75. {
  76. type: StepType.VERIFY,
  77. description: t(
  78. `One way to verify your setup is by intentionally causing an error that breaks your application.`
  79. ),
  80. configurations: [
  81. {
  82. description: t(
  83. `Calling an undefined function will throw a JavaScript exception:`
  84. ),
  85. language: 'javascript',
  86. code: `
  87. myUndefinedFunction();
  88. `,
  89. },
  90. {
  91. description: t(
  92. `With Electron you can test native crash reporting by triggering a crash:`
  93. ),
  94. language: 'javascript',
  95. code: `
  96. process.crash();
  97. `,
  98. },
  99. ],
  100. additionalInfo: t(
  101. 'You may want to try inserting these code snippets into both your main and any renderer processes to verify Sentry is operational in both.'
  102. ),
  103. },
  104. ];
  105. // Configuration End
  106. export function GettingStartedWithElectron({
  107. dsn,
  108. organization,
  109. platformKey,
  110. projectId,
  111. newOrg,
  112. ...props
  113. }: ModuleProps) {
  114. const sentryInitContent: string[] = [`dsn: "${dsn}",`];
  115. return (
  116. <Layout
  117. steps={steps({
  118. sentryInitContent: sentryInitContent.join('\n'),
  119. organization,
  120. platformKey,
  121. projectId,
  122. newOrg,
  123. })}
  124. nextSteps={[]}
  125. newOrg={newOrg}
  126. platformKey={platformKey}
  127. {...props}
  128. />
  129. );
  130. }
  131. export default GettingStartedWithElectron;