|
| 1 | +--- |
| 2 | +title: Migrate to 5.x |
| 3 | +sidebar_order: 200 |
| 4 | +description: "Learn how to migrate to version 5 of the SDK ." |
| 5 | +--- |
| 6 | + |
| 7 | +## From 4.x to 5.x |
| 8 | + |
| 9 | +The React Native SDK version 5 supports both Legacy (from RN 0.65 and above) and New Architecture (from RN 0.69 and above) as well as the new React Native Gradle Plugin (introduced in RN 0.71). |
| 10 | + |
| 11 | +### Naming and behavior changes |
| 12 | + |
| 13 | +Rename the following `Sentry.init` options: |
| 14 | + |
| 15 | +- `enableAutoPerformanceTracking` to `enableAutoPerformanceTracing` |
| 16 | +- `enableOutOfMemoryTracking` to `enableWatchdogTerminationTracking` |
| 17 | +- `ReactNativeTracingOptions.idleTimeout` to `ReactNativeTracingOptions.idleTimeoutMs` |
| 18 | +- `ReactNativeTracingOptions.maxTransactionDuration` to `ReactNativeTracingOptions.finalTimeoutMs` |
| 19 | + |
| 20 | +If you're using `TouchEventBoundary` and `accessibilityLabel` set the following: |
| 21 | + |
| 22 | +```javascript |
| 23 | +Sentry.wrap(App, { |
| 24 | + touchEventBoundaryProps: { labelName: "accessibilityLabel" }, |
| 25 | +}); |
| 26 | +``` |
| 27 | + |
| 28 | +The current stack trace for `Sentry.captureMessage` has been moved from `event.exception` to `event.threads`. |
| 29 | + |
| 30 | +The default `breadcrumb.level` is `info`, value `critical` has been removed and `log` has been transformed to `debug` on iOS and Android. |
| 31 | + |
| 32 | +The bundled `sentry-cli` version has been bumped to [v2.10.0](https://github.com/getsentry/sentry-cli/releases/tag/2.10.0). Check your usage of `sentry-cli` to reflect [breaking changes](https://github.com/getsentry/sentry-cli/releases/tag/2.0.0). Note, that `upload-dsym` has been replaced by `debug-files upload` and requires a path. Make sure to check your `Upload Debug Symbols` build step in your Xcode project. The command should look like the example below: |
| 33 | + |
| 34 | +```bash |
| 35 | +# Before |
| 36 | +../node_modules/@sentry/cli/bin/sentry-cli upload-dsym |
| 37 | + |
| 38 | +# After |
| 39 | +../node_modules/@sentry/cli/bin/sentry-cli debug-files upload "$DWARF_DSYM_FOLDER_PATH" |
| 40 | +``` |
| 41 | + |
| 42 | +### iOS specific changes |
| 43 | + |
| 44 | +The following metadata are synchronized from `sentry-cocoa` to `react-native`: |
| 45 | + |
| 46 | +- `tags` |
| 47 | +- `extra` |
| 48 | +- `fingerprint` |
| 49 | +- `level` |
| 50 | +- `environment` |
| 51 | +- `breadcrumbs` |
| 52 | + |
| 53 | +The synchronized `fingerprint` might affect issue grouping in Sentry. React Native `event.fingerprint` is merged with iOS `fingerprint` without duplicates with RN items being first in the order. |
| 54 | + |
| 55 | +`sentry-cocoa` has been bumped to v8.0.0, please follow the related migration [here](/platforms/apple/migration/#migrating-from-7x-to-8x). |
| 56 | + |
| 57 | +`sentry-wizard` doesn't patch iOS projects for React Native 0.65 to 0.68. These versions have to be [patched manually](/platforms/react-native/manual-setup/manual-setup/#bundle-react-native-code-and-images). |
| 58 | + |
| 59 | +### Changes to Minimum Supported Versions |
| 60 | + |
| 61 | +The minimum supported iOS version has been bumped to iOS 11. The minimum Android API has been bumped to 21. The minimum supported React Native version is 0.65.0. |
| 62 | + |
| 63 | +## From 4.8.x to 4.9.x |
| 64 | + |
| 65 | +A new feature that enables sending runtime JavaScript dependencies in events for React Native apps was added in release `4.9.0`. No manual steps are required to enable this on Android builds. For iOS, you need to patch the `shellScript` in the `ios/$projectName.xcodeproj/project.pbxproj` file, where `$projectName` is likely your project's name. To do this, search for the `Bundle React Native code and images` phase and patch the `shellScript`. |
| 66 | + |
| 67 | +React Native 0.69.0 and above: |
| 68 | + |
| 69 | +_Old_: |
| 70 | + |
| 71 | +```bash |
| 72 | +shellScript = "export SENTRY_PROPERTIES=sentry.properties\nexport EXTRA_PACKAGER_ARGS=\"--sourcemap-output $DERIVED_FILE_DIR/main.jsbundle.map\"\nset -e\n\nWITH_ENVIRONMENT=\"../node_modules/react-native/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"../node_modules/react-native/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT \\\"../node_modules/@sentry/cli/bin/sentry-cli react-native xcode $REACT_NATIVE_XCODE\\\"\"\n"; |
| 73 | +``` |
| 74 | + |
| 75 | +_New_: |
| 76 | + |
| 77 | +```bash |
| 78 | +shellScript = "export SENTRY_PROPERTIES=sentry.properties\nexport EXTRA_PACKAGER_ARGS=\"--sourcemap-output $DERIVED_FILE_DIR/main.jsbundle.map\"\nset -e\n\nWITH_ENVIRONMENT=\"../node_modules/react-native/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"../node_modules/react-native/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT \\\"../node_modules/@sentry/cli/bin/sentry-cli react-native xcode $REACT_NATIVE_XCODE\\\"\"\n\n/bin/sh ../node_modules/@sentry/react-native/scripts/collect-modules.sh\n"; |
| 79 | +``` |
| 80 | + |
| 81 | +React Native 0.56.0 to 0.68.0: |
| 82 | + |
| 83 | +_Old_: |
| 84 | + |
| 85 | +```bash |
| 86 | +shellScript = "export NODE_BINARY=node\nexport EXTRA_PACKAGER_ARGS=\"--sourcemap-output $DERIVED_FILE_DIR/main.jsbundle.map\"\nexport SENTRY_PROPERTIES=../sentry.properties\n\n../node_modules/@sentry/cli/bin/sentry-cli react-native xcode \\\n ../node_modules/react-native/scripts/react-native-xcode.sh\n"; |
| 87 | +``` |
| 88 | + |
| 89 | +_New_: |
| 90 | + |
| 91 | +```bash |
| 92 | +shellScript = "export NODE_BINARY=node\nexport EXTRA_PACKAGER_ARGS=\"--sourcemap-output $DERIVED_FILE_DIR/main.jsbundle.map\"\nexport SENTRY_PROPERTIES=../sentry.properties\n\n../node_modules/@sentry/cli/bin/sentry-cli react-native xcode \\\n ../node_modules/react-native/scripts/react-native-xcode.sh\n\n/bin/sh ../node_modules/@sentry/react-native/scripts/collect-modules.sh\n"; |
| 93 | +``` |
| 94 | + |
| 95 | +See the [JS SDK migration guide](https://github.com/getsentry/sentry-javascript/blob/f4861f8c3eab1181ab8e7544402b23770a992d6e/MIGRATION.md?plain=1#L81) for changes related to the upgrade to version `7.19.0`. |
| 96 | + |
| 97 | +## From 4.6.x to 4.7.x |
| 98 | + |
| 99 | +See the JS SDK migration guide [here](https://github.com/getsentry/sentry-javascript/blob/f4861f8c3eab1181ab8e7544402b23770a992d6e/MIGRATION.md?plain=1#L89) and [here](https://github.com/getsentry/sentry-javascript/blob/f4861f8c3eab1181ab8e7544402b23770a992d6e/MIGRATION.md?plain=1#L93) for changes related to the upgrade to version `7.16.0`. |
| 100 | + |
| 101 | +## From 3.x to 4.x |
| 102 | + |
| 103 | +By bumping Sentry JavaScript to v7, new breaking changes were introduced, to learn more about what was changed, check out the [breaking changes changelog](https://github.com/getsentry/sentry-javascript/blob/7.0.0/CHANGELOG.md#breaking-changes) from Sentry Javascript. |
| 104 | + |
| 105 | +By bumping Sentry Android to v6, new breaking changes were introduced, to learn more about what was changed, check out the [migration guide](/platforms/android/migration/#migrating-from-iosentrysentry-android-5x-to-iosentrysentry-android-600). |
| 106 | + |
| 107 | +## From 3.0.x to 3.1.x |
| 108 | + |
| 109 | +`ReactNavigationV5Instrumentation` was renamed to `ReactNavigationInstrumentation` and supports every version of React Navigation from v5 onwards, including v6. You only need to change the name wherever you call the constructor for the instrumentation: |
| 110 | + |
| 111 | +```javascript |
| 112 | +// Old |
| 113 | +const routingInstrumentation = new Sentry.ReactNavigationV5Instrumentation(); |
| 114 | +// New |
| 115 | +const routingInstrumentation = new Sentry.ReactNavigationInstrumentation(); |
| 116 | +``` |
| 117 | + |
| 118 | +## From 2.x to 3.x |
| 119 | + |
| 120 | +There are no changes needed when migrating from versions `2.x` to `3.x`, although you will need to make sure that you run `pod install` on iOS and that you rebuild your app on both platforms. |
| 121 | + |
| 122 | +### Event Origin and Environment Tags |
| 123 | + |
| 124 | +When upgrading from prior versions to `3.x`, you may see a mismatch in the values of the `event.environment` tag compared to events sent from the SDK prior to this version. Events that originate from native iOS code will now have the `event.environment` tag set to `native`. Read more about these tags on the [event information guide](/platforms/react-native/usage/event-information/#event-origin-and-environment-tags). |
| 125 | + |
| 126 | +## From 2.4.x to 2.5.x |
| 127 | + |
| 128 | +The breaking changes are relevant only to Android. There are no breaking changes for other platforms. |
| 129 | + |
| 130 | +### Android Specific Changes |
| 131 | + |
| 132 | +Sentry React Native version `2.5.0` depends on Sentry Android `5.0.0`. Please [refer to the Android migration guide for Android-specific changes](/platforms/android/migration/#migrating-from-iosentrysentry-android-430-to-iosentrysentry-android-500). |
| 133 | + |
| 134 | +`Settings.Secure.ANDROID_ID` has been removed and replaced with a randomly-generated `installationId`. This may affect the number of unique users displayed on the the Issues page and Alerts. If you've always set a custom user using `Sentry.setUser(customUser)`, the behavior hasn't changed. While you don't have to make any updates, if you want to maintain the old behavior, use the following code snippet which makes use of the [react-native-device-info](https://github.com/react-native-device-info/react-native-device-info) library. |
| 135 | + |
| 136 | +```javascript |
| 137 | +import { Platform } from "react-native"; |
| 138 | +import DeviceInfo from "react-native-device-info"; |
| 139 | + |
| 140 | +import * as Sentry from "@sentry/react-native"; |
| 141 | + |
| 142 | +Sentry.init({ |
| 143 | + // ... |
| 144 | +}); |
| 145 | + |
| 146 | +// Only add the event processor on Android |
| 147 | +if (Platform.OS === "android") { |
| 148 | + Sentry.addGlobalEventProcessor((event) => { |
| 149 | + // Get the ANDROID_ID |
| 150 | + const id = DeviceInfo.getUniqueId(); |
| 151 | + |
| 152 | + // If the user does not exist, set the id to be the unique id. |
| 153 | + if (!event.user) { |
| 154 | + event.user = { id }; |
| 155 | + } |
| 156 | + |
| 157 | + return event; |
| 158 | + }); |
| 159 | +} |
| 160 | +``` |
| 161 | + |
| 162 | +## React Navigation Instrumentation from <2.3.0 |
| 163 | + |
| 164 | +We changed the initialization method for the React Navigation v5 and above, routing instrumentation to avoid a potential issue when using linking. You now register the navigation container inside the `onReady` prop passed to the `NavigationContainer`. |
| 165 | + |
| 166 | +From: |
| 167 | + |
| 168 | +```javascript |
| 169 | +// Old Functional Component Example |
| 170 | +const App = () => { |
| 171 | + const navigation = React.useRef(); |
| 172 | + |
| 173 | + React.useEffect(() => { |
| 174 | + routingInstrumentation.registerNavigationContainer(navigation); |
| 175 | + }, []); |
| 176 | + |
| 177 | + return <NavigationContainer ref={navigation}>...</NavigationContainer>; |
| 178 | +}; |
| 179 | + |
| 180 | +// Old Class Component Example |
| 181 | +class App extends React.Component { |
| 182 | + navigation = React.createRef(); |
| 183 | + |
| 184 | + componentDidMount() { |
| 185 | + routingInstrumentation.registerNavigationContainer(navigation); |
| 186 | + } |
| 187 | + |
| 188 | + render() { |
| 189 | + return <NavigationContainer ref={this.navigation}>...</NavigationContainer>; |
| 190 | + } |
| 191 | +} |
| 192 | +``` |
| 193 | + |
| 194 | +To: |
| 195 | + |
| 196 | +```javascript |
| 197 | +// Functional Component Example |
| 198 | +const App = () => { |
| 199 | + const navigation = React.useRef(); |
| 200 | + |
| 201 | + return ( |
| 202 | + <NavigationContainer |
| 203 | + ref={navigation} |
| 204 | + onReady={() => { |
| 205 | + // Register the navigation container with the instrumentation inside onReady |
| 206 | + routingInstrumentation.registerNavigationContainer(navigation); |
| 207 | + }} |
| 208 | + > |
| 209 | + ... |
| 210 | + </NavigationContainer> |
| 211 | + ); |
| 212 | +}; |
| 213 | + |
| 214 | +// Class Component Example |
| 215 | +class App extends React.Component { |
| 216 | + navigation = React.createRef(); |
| 217 | + |
| 218 | + render() { |
| 219 | + return ( |
| 220 | + <NavigationContainer |
| 221 | + ref={this.navigation} |
| 222 | + onReady={() => { |
| 223 | + // Register the navigation container with the instrumentation inside onReady |
| 224 | + routingInstrumentation.registerNavigationContainer(navigation); |
| 225 | + }} |
| 226 | + > |
| 227 | + ... |
| 228 | + </NavigationContainer> |
| 229 | + ); |
| 230 | + } |
| 231 | +} |
| 232 | +``` |
| 233 | + |
| 234 | +## From 1.x to 2.x |
| 235 | + |
| 236 | +Sentry's most recent version of our React Native SDK enables release health tracking and native stack traces by default. |
| 237 | + |
| 238 | +This version of the SDK uses the [envelope endpoint](https://develop.sentry.dev/sdk/envelopes/). If you're using self-hosted Sentry, the SDK requires Sentry version 20.6.0 and above. If you're using our SaaS product ([sentry.io](https://sentry.io)), no changes or actions are needed. |
| 239 | + |
| 240 | +### iOS/MacOS |
| 241 | + |
| 242 | +While the migration doesn't introduce breaking changes for iOS/MacOS on the React Native side, we recommend running `pod install` after the upgrade. |
| 243 | + |
| 244 | +<Note> |
| 245 | + |
| 246 | +If you're using our Cocoa SDK directly, follow the [migration guide for 5.x to 6.x](/platforms/apple/migration/#migrating-from-5x-to-6x). |
| 247 | + |
| 248 | +</Note> |
| 249 | + |
| 250 | +On iOS/MacOS, we now cache events in envelopes on the disk. As a result, you might lose a few cached events during the migration. Due to the high level of effort involved, the migration from 5.x to 6.x won't move these few cached events into envelopes. |
| 251 | + |
| 252 | +### Android |
| 253 | + |
| 254 | +If you're on React Native <0.60, you'll need to update this line in your `MainApplication.java`: |
| 255 | + |
| 256 | +From (earlier version): |
| 257 | + |
| 258 | +```java |
| 259 | +import io.sentry.RNSentryPackage; |
| 260 | +``` |
| 261 | + |
| 262 | +```kotlin |
| 263 | +import io.sentry.RNSentryPackage |
| 264 | +``` |
| 265 | + |
| 266 | +New: |
| 267 | + |
| 268 | +```java |
| 269 | +import io.sentry.react.RNSentryPackage; |
| 270 | +``` |
| 271 | + |
| 272 | +```kotlin |
| 273 | +import io.sentry.react.RNSentryPackage |
| 274 | +``` |
| 275 | + |
| 276 | +Other than the one line change noted above, the migration shouldn't cause breaking changes on the React Native side. |
| 277 | + |
| 278 | +<Note> |
| 279 | +<markdown> |
| 280 | + |
| 281 | +If you use our Android SDK directly, you should follow its [migration guide for 2.x to 3.x](/platforms/android/migration/#migrating-from-iosentrysentry-android-2x-to-iosentrysentry-android-3x). |
| 282 | + |
| 283 | +</markdown> |
| 284 | +</Note> |
| 285 | + |
| 286 | +## From 0.x to 1.x |
| 287 | + |
| 288 | +If you're upgrading from an earlier version of Sentry's React Native SDK, you should unlink the package to ensure the generated code is updated to the latest version: |
| 289 | + |
| 290 | +```bash |
| 291 | +react-native unlink react-native-sentry |
| 292 | +``` |
| 293 | + |
| 294 | +After that remove `react-native-sentry` from your `package.json`: |
| 295 | + |
| 296 | +```bash |
| 297 | +npm uninstall react-native-sentry --save |
| 298 | +# or |
| 299 | +yarn remove react-native-sentry |
| 300 | +``` |
| 301 | + |
| 302 | +From there, you can follow the standard installation instructions for `@sentry/react-native`. |
0 commit comments