react-native.tsx 11 KB

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