ionic.tsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  2. import type {
  3. Docs,
  4. DocsParams,
  5. OnboardingConfig,
  6. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  7. import {t, tct} from 'sentry/locale';
  8. type Params = DocsParams;
  9. const getConfigureSnippet = (params: Params) => `
  10. import * as Sentry from "@sentry/capacitor";
  11. // The example is using Angular 12+. Import '@sentry/angular' for Angular 10 and 11. Import '@sentry/vue' or '@sentry/react' when using a Sibling different than Angular.
  12. import * as SentrySibling from "@sentry/angular-ivy";
  13. Sentry.init(
  14. {
  15. dsn: "${params.dsn}",
  16. // To set your release and dist versions
  17. release: "my-project-name@" + process.env.npm_package_version,
  18. dist: "1",
  19. // Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
  20. // We recommend adjusting this value in production.
  21. tracesSampleRate: 1.0,
  22. integrations: [
  23. SentrySibling.browserTracingIntegration(),
  24. ],
  25. // Set "tracePropagationTargets" to control for which URLs distributed tracing should be enabled
  26. tracePropagationTargets: [
  27. "localhost",
  28. /^https:\/\/yourserver\.io\/api/,
  29. ],
  30. },
  31. // Forward the init method to the sibling Framework.
  32. SentrySibling.init
  33. );`;
  34. const getConfigureAngularSnippet = () => `
  35. @NgModule({
  36. providers: [
  37. {
  38. provide: ErrorHandler,
  39. // Attach the Sentry ErrorHandler
  40. useValue: SentrySibling.createErrorHandler(),
  41. },
  42. {
  43. provide: SentrySibling.TraceService,
  44. deps: [Router],
  45. },
  46. {
  47. provide: APP_INITIALIZER,
  48. useFactory: () => () => {},
  49. deps: [SentrySibling.TraceService],
  50. multi: true,
  51. },
  52. ],
  53. })`;
  54. const onboarding: OnboardingConfig = {
  55. install: () => [
  56. {
  57. type: StepType.INSTALL,
  58. description: tct(
  59. "To use Sentry in your Ionic app, install the Sentry Capacitor SDK alongside the sibling Sentry SDK related to the Web framework you're using with Ionic. The supported siblings are: Angular [sentryAngularIvyCode:@sentry/angular-ivy], React [sentryReactCode:@sentry/react] and Vue [sentryVueCode:@sentry/vue].",
  60. {
  61. sentryAngularIvyCode: <code />,
  62. sentryReactCode: <code />,
  63. sentryVueCode: <code />,
  64. }
  65. ),
  66. configurations: [
  67. {
  68. language: 'bash',
  69. description: t(
  70. 'Heres an example of installing Sentry Capacitor along with Sentry Angular:'
  71. ),
  72. code: [
  73. {
  74. language: 'bash',
  75. label: 'npm',
  76. value: 'npm',
  77. code: 'npm install --save @sentry/capacitor @sentry/angular',
  78. },
  79. {
  80. language: 'bash',
  81. label: 'yarn',
  82. value: 'yarn',
  83. code: 'yarn add @sentry/capacitor @sentry/angular',
  84. },
  85. ],
  86. },
  87. ],
  88. additionalInfo: tct(
  89. 'The same installation process applies to the other siblings, all you need to do is to replace [code:@sentry/angular-ivy] by the desired sibling.',
  90. {code: <code />}
  91. ),
  92. },
  93. ],
  94. configure: params => [
  95. {
  96. type: StepType.CONFIGURE,
  97. description: tct('You must initialize the Sentry SDK as early as you can:', {
  98. code: <code />,
  99. }),
  100. configurations: [
  101. {
  102. language: 'javascript',
  103. code: getConfigureSnippet(params),
  104. },
  105. {
  106. language: 'javascript',
  107. description: tct(
  108. "Additionally for Angular, you will also need to configure your root [code:app.module.ts] (same code doesn't apply to other siblings):",
  109. {
  110. code: <code />,
  111. }
  112. ),
  113. code: getConfigureAngularSnippet(),
  114. },
  115. ],
  116. },
  117. ],
  118. verify: () => [
  119. {
  120. type: StepType.VERIFY,
  121. description: t(
  122. 'This snippet includes an intentional error, so you can test that everything is working as soon as you set it up:'
  123. ),
  124. configurations: [
  125. {
  126. language: 'javascript',
  127. code: `
  128. import * as Sentry from "@sentry/capacitor";
  129. Sentry.captureException("Test Captured Exception");`,
  130. },
  131. {
  132. language: 'javascript',
  133. description: t('You can also throw an error anywhere in your application:'),
  134. code: `
  135. // Must be thrown after Sentry.init is called to be captured.
  136. throw new Error("Test Thrown Error");`,
  137. },
  138. {
  139. language: 'javascript',
  140. description: t('Or trigger a native crash:'),
  141. code: `
  142. import * as Sentry from "@sentry/capacitor";
  143. Sentry.nativeCrash();`,
  144. },
  145. ],
  146. },
  147. ],
  148. nextSteps: () => [
  149. {
  150. id: 'capacitor-android-setup',
  151. name: t('Capacitor 2 Setup'),
  152. description: t(
  153. 'If you are using Capacitor 2 or older, follow this step to add required changes in order to initialize the Capacitor SDK on Android.'
  154. ),
  155. link: 'https://docs.sentry.io/platforms/javascript/guides/capacitor/ionic/#capacitor-2---android-specifics',
  156. },
  157. ],
  158. };
  159. const docs: Docs = {
  160. onboarding,
  161. };
  162. export default docs;