capacitor.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 {t, tct} from 'sentry/locale';
  6. import type {Organization, PlatformKey} from 'sentry/types';
  7. type StepProps = {
  8. newOrg: boolean;
  9. organization: Organization;
  10. platformKey: PlatformKey;
  11. projectId: string;
  12. sentryInitContent: string;
  13. };
  14. // Configuration Start
  15. const replayIntegration = `
  16. new Sentry.Replay(),
  17. `;
  18. const replayOtherConfig = `
  19. // This sets the sample rate to be 10%. You may want this to be 100% while
  20. // in development and sample at a lower rate in production.
  21. replaysSessionSampleRate: 0.1,
  22. // If the entire session is not sampled, use the below sample rate to sample
  23. // sessions when an error occurs.
  24. replaysOnErrorSampleRate: 1.0,
  25. `;
  26. export const steps = ({
  27. sentryInitContent,
  28. }: Partial<StepProps> = {}): LayoutProps['steps'] => [
  29. {
  30. type: StepType.INSTALL,
  31. description: t(
  32. 'Install the Sentry Capacitor SDK alongside the corresponding Sentry SDK for the framework you are using.'
  33. ),
  34. configurations: [
  35. {
  36. language: 'bash',
  37. header: tct('Using [code:NPM:]', {code: <code />}),
  38. code: [
  39. {
  40. label: 'Angular',
  41. value: 'angular',
  42. language: 'bash',
  43. code: `npm install --save @sentry/capacitor @sentry/angular-ivy`,
  44. },
  45. {
  46. label: 'React',
  47. value: 'react',
  48. language: 'bash',
  49. code: `npm install --save @sentry/capacitor @sentry/react`,
  50. },
  51. {
  52. label: 'Vue',
  53. value: 'vue',
  54. language: 'bash',
  55. code: `npm install --save @sentry/capacitor @sentry/vue`,
  56. },
  57. {
  58. label: 'Other',
  59. value: 'other',
  60. language: 'bash',
  61. code: `npm install --save @sentry/capacitor @sentry/browser`,
  62. },
  63. ],
  64. },
  65. {
  66. language: 'bash',
  67. header: tct('Using [code:Yarn:]', {code: <code />}),
  68. code: [
  69. {
  70. label: 'Angular',
  71. value: 'angular',
  72. language: 'bash',
  73. code: `yarn add @sentry/capacitor @sentry/angular-ivy`,
  74. },
  75. {
  76. label: 'React',
  77. value: 'react',
  78. language: 'bash',
  79. code: `yarn add @sentry/capacitor @sentry/react`,
  80. },
  81. {
  82. label: 'Vue',
  83. value: 'vue',
  84. language: 'bash',
  85. code: `yarn add @sentry/capacitor @sentry/vue`,
  86. },
  87. {
  88. label: 'Other',
  89. value: 'other',
  90. language: 'bash',
  91. code: `yarn add @sentry/capacitor @sentry/browser`,
  92. },
  93. ],
  94. },
  95. ],
  96. },
  97. {
  98. type: StepType.CONFIGURE,
  99. description: tct(
  100. 'Add the following to your SDK config. There are several privacy and sampling options available, all of which can be set using the [code:integrations] constructor. Learn more about configuring Session Replay by reading the [link:configuration docs].',
  101. {
  102. code: <code />,
  103. link: (
  104. <ExternalLink href="https://docs.sentry.io/platforms/javascript/session-replay/" />
  105. ),
  106. }
  107. ),
  108. configurations: [
  109. {
  110. language: 'javascript',
  111. code: `
  112. import * as Sentry from "@sentry/capacitor";
  113. Sentry.init({
  114. ${sentryInitContent}
  115. });
  116. `,
  117. },
  118. ],
  119. },
  120. ];
  121. // Configuration End
  122. export function GettingStartedWithCapacitorReplay({
  123. dsn,
  124. organization,
  125. newOrg,
  126. platformKey,
  127. projectId,
  128. ...props
  129. }: ModuleProps) {
  130. const integrations = replayIntegration.trim();
  131. const otherConfigs = replayOtherConfig.trim();
  132. let sentryInitContent: string[] = [`dsn: "${dsn}",`];
  133. sentryInitContent = sentryInitContent.concat('integrations: [', integrations, '],');
  134. sentryInitContent = sentryInitContent.concat(otherConfigs);
  135. return (
  136. <Layout
  137. steps={steps({
  138. sentryInitContent: sentryInitContent.join('\n'),
  139. organization,
  140. newOrg,
  141. platformKey,
  142. projectId,
  143. })}
  144. platformKey={platformKey}
  145. newOrg={newOrg}
  146. hideHeader
  147. {...props}
  148. />
  149. );
  150. }
  151. export default GettingStartedWithCapacitorReplay;