react-native.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. import {Fragment} from 'react';
  2. import ExternalLink from 'sentry/components/links/externalLink';
  3. import List from 'sentry/components/list/';
  4. import ListItem from 'sentry/components/list/listItem';
  5. import {StepType} from 'sentry/components/onboarding/gettingStartedDoc/step';
  6. import type {
  7. Docs,
  8. DocsParams,
  9. OnboardingConfig,
  10. } from 'sentry/components/onboarding/gettingStartedDoc/types';
  11. import {t, tct} from 'sentry/locale';
  12. type Params = DocsParams;
  13. const getConfigureSnippet = (params: Params) => `
  14. import * as Sentry from "@sentry/react-native";
  15. Sentry.init({
  16. dsn: "${params.dsn}",
  17. // Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring.
  18. // We recommend adjusting this value in production.
  19. tracesSampleRate: 1.0,
  20. });`;
  21. const getPerformanceSnippet = () => `
  22. // Let's say this function is invoked when a user clicks on the checkout button of your shop
  23. shopCheckout() {
  24. // This will create a new Transaction for you
  25. const transaction = Sentry.startTransaction({ name: "shopCheckout" });
  26. // Set transaction on scope to associate with errors and get included span instrumentation
  27. // If there's currently an unfinished transaction, it may be dropped
  28. Sentry.getCurrentHub().configureScope(scope => scope.setSpan(transaction));
  29. // Assume this function makes an xhr/fetch call
  30. const result = validateShoppingCartOnServer();
  31. const span = transaction.startChild({
  32. data: {
  33. result
  34. },
  35. op: 'task',
  36. description: "processing shopping cart result",
  37. });
  38. try {
  39. processAndValidateShoppingCart(result);
  40. span.setStatus(SpanStatus.Ok);
  41. } catch (err) {
  42. span.setStatus(SpanStatus.UnknownError);
  43. throw err;
  44. } finally {
  45. span.finish();
  46. transaction.finish();
  47. }
  48. }`;
  49. const onboarding: OnboardingConfig = {
  50. install: () => [
  51. {
  52. type: StepType.INSTALL,
  53. description: tct(
  54. 'Sentry captures data by using an SDK within your application’s runtime. If you are using Expo, see [expoLink:How to Add Sentry to Your Expo Project]. This SDK works for both managed and bare projects.',
  55. {expoLink: <ExternalLink href="https://docs.expo.dev/guides/using-sentry/" />}
  56. ),
  57. configurations: [
  58. {
  59. language: 'bash',
  60. description: <div>{tct('Run [code:@sentry/wizard]:', {code: <code />})}</div>,
  61. code: 'npx @sentry/wizard@latest -s -i reactNative',
  62. additionalInfo: (
  63. <Fragment>
  64. <p>
  65. {tct(
  66. '[wizardLink:Sentry Wizard] will patch your project accordingly, though you can [setupManuallyLink:setup manually] if you prefer.',
  67. {
  68. wizardLink: (
  69. <ExternalLink href="https://github.com/getsentry/sentry-wizard" />
  70. ),
  71. setupManuallyLink: (
  72. <ExternalLink href="https://docs.sentry.io/platforms/react-native/manual-setup/manual-setup/" />
  73. ),
  74. }
  75. )}
  76. </p>
  77. <List symbol="bullet">
  78. <ListItem>
  79. {t(
  80. 'iOS Specifics: When you use Xcode, you can hook directly into the build process to upload debug symbols and source maps.'
  81. )}
  82. </ListItem>
  83. <ListItem>
  84. {tct(
  85. "Android Specifics: We hook into Gradle for the source map build process. When you run [gradLewCode:./gradlew] assembleRelease, source maps are automatically built and uploaded to Sentry. If you have enabled Gradle's [orgGradleCode:org.gradle.configureondemand] feature, you'll need a clean build, or you'll need to disable this feature to upload the source map on every build by setting [orgGradleCodeConfigureCode:org.gradle.configureondemand=false] or remove it.",
  86. {
  87. gradLewCode: <code />,
  88. orgGradleCode: <code />,
  89. orgGradleCodeConfigureCode: <code />,
  90. }
  91. )}
  92. </ListItem>
  93. </List>
  94. </Fragment>
  95. ),
  96. },
  97. ],
  98. },
  99. ],
  100. configure: params => [
  101. {
  102. type: StepType.CONFIGURE,
  103. configurations: [
  104. {
  105. language: 'javascript',
  106. code: getConfigureSnippet(params),
  107. additionalInfo: tct(
  108. 'The "sentry-wizard" will try to add it to your [code:App.tsx]',
  109. {
  110. code: <code />,
  111. }
  112. ),
  113. },
  114. {
  115. language: 'javascript',
  116. description: tct(
  117. 'Wrap your app with Sentry to automatically instrument it with [touchEventTrakingLink:touch event tracking] and [automaticPerformanceMonitoringLink:automatic performance monitoring]:',
  118. {
  119. touchEventTrakingLink: (
  120. <ExternalLink href="https://docs.sentry.io/platforms/react-native/touchevents/" />
  121. ),
  122. automaticPerformanceMonitoringLink: (
  123. <ExternalLink href="https://docs.sentry.io/platforms/react-native/performance/instrumentation/automatic-instrumentation/" />
  124. ),
  125. }
  126. ),
  127. code: 'export default Sentry.wrap(App);',
  128. additionalInfo: t(
  129. 'You do not need to do this for Sentry to work or if your app does not have a single parent "App" component.'
  130. ),
  131. },
  132. ],
  133. },
  134. ],
  135. verify: () => [
  136. {
  137. type: StepType.VERIFY,
  138. description: t(
  139. 'Then create an intentional error, so you can test that everything is working:'
  140. ),
  141. configurations: [
  142. {
  143. language: 'javascript',
  144. code: "throw new Error('My first Sentry error!');",
  145. },
  146. {
  147. language: 'javascript',
  148. description: t('Or, try a native crash with:'),
  149. code: 'Sentry.nativeCrash();',
  150. additionalInfo: (
  151. <Fragment>
  152. {t(
  153. "If you're new to Sentry, use the email alert to access your account and complete a product tour."
  154. )}
  155. {t(
  156. "If you're an existing user and have disabled alerts, you won't receive this email."
  157. )}
  158. </Fragment>
  159. ),
  160. },
  161. ],
  162. },
  163. {
  164. title: t('Performance'),
  165. description: (
  166. <Fragment>
  167. {t(
  168. 'Sentry can measure the performance of your app automatically when instrumented with the following routers:'
  169. )}
  170. <List symbol="bullet">
  171. <ListItem>
  172. <ExternalLink href="https://docs.sentry.io/platforms/react-native/performance/instrumentation/automatic-instrumentation/#react-navigation">
  173. {t('React Navigation')}
  174. </ExternalLink>
  175. </ListItem>
  176. <ListItem>
  177. <ExternalLink href="https://docs.sentry.io/platforms/react-native/performance/instrumentation/automatic-instrumentation/#react-navigation-v4">
  178. {t('React Navigation V4 and prior')}
  179. </ExternalLink>
  180. </ListItem>
  181. <ListItem>
  182. <ExternalLink href="https://docs.sentry.io/platforms/react-native/performance/instrumentation/automatic-instrumentation/#react-native-navigation">
  183. {t('React Native Navigation')}
  184. </ExternalLink>
  185. </ListItem>
  186. </List>
  187. {t('Additionally, you can create transactions and spans programatically:')}
  188. </Fragment>
  189. ),
  190. configurations: [
  191. {
  192. description: t('For example:'),
  193. language: 'javascript',
  194. code: getPerformanceSnippet(),
  195. additionalInfo: tct(
  196. 'For more information, please refer to the [docLink: Sentry React Native documentation].',
  197. {
  198. docLink: (
  199. <ExternalLink href="https://docs.sentry.io/platforms/react-native/performance/instrumentation/" />
  200. ),
  201. }
  202. ),
  203. },
  204. ],
  205. },
  206. {
  207. title: t('Debug Symbols'),
  208. description: (
  209. <Fragment>
  210. {t(
  211. 'We offer a range of methods to provide Sentry with debug symbols so that you can see symbolicated stack traces and triage issues faster.'
  212. )}
  213. <p>
  214. {tct(
  215. "Complete stack traces will be shown for React Native Javascript errors by default using Sentry's [automaticSourceMapsUploadLink:automatic source maps upload]. To set up manual source maps upload follow [guideLink:this guide].",
  216. {
  217. automaticSourceMapsUploadLink: (
  218. <ExternalLink href="https://docs.sentry.io/platforms/react-native/sourcemaps/" />
  219. ),
  220. guideLink: (
  221. <ExternalLink href="https://docs.sentry.io/platforms/react-native/sourcemaps/" />
  222. ),
  223. }
  224. )}
  225. </p>
  226. <p>
  227. {tct(
  228. "You'll also need to upload [debugSymbolsLink:Debug Symbols] generated by the native iOS and Android tooling for native crashes.",
  229. {
  230. debugSymbolsLink: (
  231. <ExternalLink href="https://docs.sentry.io/platforms/react-native/upload-debug/" />
  232. ),
  233. }
  234. )}
  235. </p>
  236. </Fragment>
  237. ),
  238. },
  239. {
  240. title: t('Source Context'),
  241. description: (
  242. <Fragment>
  243. <p>
  244. {tct(
  245. "If Sentry has access to your application's source code, it can show snippets of code [italic:(source context)] around the location of stack frames, which helps to quickly pinpoint problematic code.",
  246. {
  247. italic: <i />,
  248. }
  249. )}
  250. </p>
  251. <p>
  252. {tct(
  253. 'Source Context will be shown for React Native Javascript error by default if source maps are uploaded. To set up source maps upload, follow the [sourceMapsGuideLink:Source Maps guide].',
  254. {
  255. sourceMapsGuideLink: (
  256. <ExternalLink href="https://docs.sentry.io/platforms/react-native/sourcemaps/" />
  257. ),
  258. }
  259. )}
  260. </p>
  261. <p>
  262. {tct(
  263. "To enable source context for native errors, you'll need to upload native debug symbols to Sentry by following the instructions at [uploadWithGradleLink:Uploading Source Code Context With Sentry Gradle Plugin] and Uploading Source Context With Xcode.",
  264. {
  265. uploadWithGradleLink: (
  266. <ExternalLink href="https://docs.sentry.io/platforms/react-native/upload-debug/#uploading-source-context-with-sentry-gradle-plugin" />
  267. ),
  268. uploadWithXCodeLink: (
  269. <ExternalLink href="https://docs.sentry.io/platforms/react-native/upload-debug/#uploading-source-context-with-xcode" />
  270. ),
  271. }
  272. )}
  273. </p>
  274. </Fragment>
  275. ),
  276. },
  277. ],
  278. };
  279. const docs: Docs = {
  280. onboarding,
  281. };
  282. export default docs;