ionic.tsx 6.0 KB

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