react-native.tsx 11 KB

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