ionic.tsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. new SentrySibling.BrowserTracing({
  24. // Set "tracePropagationTargets" to control for which URLs distributed tracing should be enabled
  25. tracePropagationTargets: [
  26. "localhost",
  27. /^https:\/\/yourserver\.io\/api/,
  28. ],
  29. routingInstrumentation: SentrySibling.routingInstrumentation,
  30. }),
  31. ],
  32. },
  33. // Forward the init method to the sibling Framework.
  34. SentrySibling.init
  35. );`;
  36. const getConfigureAngularSnippet = () => `
  37. @NgModule({
  38. providers: [
  39. {
  40. provide: ErrorHandler,
  41. // Attach the Sentry ErrorHandler
  42. useValue: SentrySibling.createErrorHandler(),
  43. },
  44. {
  45. provide: SentrySibling.TraceService,
  46. deps: [Router],
  47. },
  48. {
  49. provide: APP_INITIALIZER,
  50. useFactory: () => () => {},
  51. deps: [SentrySibling.TraceService],
  52. multi: true,
  53. },
  54. ],
  55. })`;
  56. const onboarding: OnboardingConfig = {
  57. install: () => [
  58. {
  59. type: StepType.INSTALL,
  60. description: tct(
  61. "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].",
  62. {
  63. sentryAngularIvyCode: <code />,
  64. sentryReactCode: <code />,
  65. sentryVueCode: <code />,
  66. }
  67. ),
  68. configurations: [
  69. {
  70. language: 'bash',
  71. description: t(
  72. 'Heres an example of installing Sentry Capacitor along with Sentry Angular:'
  73. ),
  74. code: [
  75. {
  76. language: 'bash',
  77. label: 'npm',
  78. value: 'npm',
  79. code: 'npm install --save @sentry/capacitor @sentry/angular',
  80. },
  81. {
  82. language: 'bash',
  83. label: 'yarn',
  84. value: 'yarn',
  85. code: 'yarn add @sentry/capacitor @sentry/angular',
  86. },
  87. ],
  88. },
  89. ],
  90. additionalInfo: tct(
  91. '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.',
  92. {code: <code />}
  93. ),
  94. },
  95. ],
  96. configure: params => [
  97. {
  98. type: StepType.CONFIGURE,
  99. description: tct('You must initialize the Sentry SDK as early as you can:', {
  100. code: <code />,
  101. }),
  102. configurations: [
  103. {
  104. language: 'javascript',
  105. code: getConfigureSnippet(params),
  106. },
  107. {
  108. language: 'javascript',
  109. description: tct(
  110. "Additionally for Angular, you will also need to configure your root [code:app.module.ts] (same code doesn't apply to other siblings):",
  111. {
  112. code: <code />,
  113. }
  114. ),
  115. code: getConfigureAngularSnippet(),
  116. },
  117. ],
  118. },
  119. ],
  120. verify: () => [
  121. {
  122. type: StepType.VERIFY,
  123. description: t(
  124. 'This snippet includes an intentional error, so you can test that everything is working as soon as you set it up:'
  125. ),
  126. configurations: [
  127. {
  128. language: 'javascript',
  129. code: `
  130. import * as Sentry from "@sentry/capacitor";
  131. Sentry.captureException("Test Captured Exception");`,
  132. },
  133. {
  134. language: 'javascript',
  135. description: t('You can also throw an error anywhere in your application:'),
  136. code: `
  137. // Must be thrown after Sentry.init is called to be captured.
  138. throw new Error("Test Thrown Error");`,
  139. },
  140. {
  141. language: 'javascript',
  142. description: t('Or trigger a native crash:'),
  143. code: `
  144. import * as Sentry from "@sentry/capacitor";
  145. Sentry.nativeCrash();`,
  146. },
  147. ],
  148. },
  149. ],
  150. nextSteps: () => [
  151. {
  152. id: 'capacitor-android-setup',
  153. name: t('Capacitor 2 Setup'),
  154. description: t(
  155. 'If you are using Capacitor 2 or older, follow this step to add required changes in order to initialize the Capacitor SDK on Android.'
  156. ),
  157. link: 'https://docs.sentry.io/platforms/javascript/guides/capacitor/ionic/#capacitor-2---android-specifics',
  158. },
  159. ],
  160. };
  161. const docs: Docs = {
  162. onboarding,
  163. };
  164. export default docs;