diff --git a/.circleci/config.yml b/.circleci/config.yml index c218cf7e9..efca5acab 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -17,6 +17,12 @@ references: - e2e_ios - e2e_android + dream11_prepare_config: &dream11_prepare_config + prepare_steps: + - prepare_dream11 + requires: + - hold_test_dream11 + commands: install_node_modules: parameters: @@ -36,15 +42,28 @@ commands: parameters: working_directory: type: string + deployment: + type: boolean + default: false steps: - restore_cache: name: Restore Pods Cache keys: - v1-pods-{{ checksum "<< parameters.working_directory >>/Podfile.lock" }} - - run: - name: Install Pods - working_directory: << parameters.working_directory >> - command: pod install --deployment + - when: + condition: << parameters.deployment >> + steps: + - run: + name: Install Pods + working_directory: << parameters.working_directory >> + command: pod install --deployment + - unless: + condition: << parameters.deployment >> + steps: + - run: + name: Install Pods + working_directory: << parameters.working_directory >> + command: pod install - save_cache: name: Save Pods Cache key: v1-pods-{{ checksum "<< parameters.working_directory >>/Podfile.lock" }} @@ -59,10 +78,72 @@ commands: type: string replace: type: string + working_directory: + type: string + default: ~/project steps: - run: name: Find and Replace in << parameters.files >> command: node ~/project/scripts/replace.js << parameters.search >> << parameters.replace >> << parameters.files >> + working_directory: << parameters.working_directory >> + + prepare_custom_package: + parameters: + npm_package: + type: string + android_package: + type: string + api_endpoint: + type: string + working_directory: + type: string + default: ~/project + steps: + - run: + name: Remove README.md file + command: rm README.md + working_directory: << parameters.working_directory >> + - find_and_replace: + files: package.json android/sourcemaps.gradle ios/sourcemaps.sh + search: instabug-reactnative + replace: << parameters.npm_package >> + working_directory: << parameters.working_directory >> + - find_and_replace: + files: cli/upload/uploadSourcemaps.ts cli/upload/uploadSoFiles.ts + search: api.instabug.com + replace: << parameters.api_endpoint >> + working_directory: << parameters.working_directory >> + - find_and_replace: + files: android/native.gradle + search: 'com.instabug.library:instabug:' + replace: 'com.instabug.library-<< parameters.android_package >>:instabug:' + working_directory: << parameters.working_directory >> + + prepare_dream11: + parameters: + working_directory: + type: string + default: ~/project + steps: + - install_node_modules + - prepare_custom_package: + npm_package: '@instabug/instabug-reactnative-dream11' + android_package: dream11 + api_endpoint: st001012dream11.instabug.com + working_directory: << parameters.working_directory >> + - run: + name: Give execute permission to Dream11 script + command: chmod +x ./scripts/dream-11-delete-unused-features.sh + working_directory: << parameters.working_directory >> + - run: + name: Remove unused features + command: ./scripts/dream-11-delete-unused-features.sh + working_directory: << parameters.working_directory >> + # Remove the NDK package to avoid dependency conflicts on Android. + - run: + name: Remove the NDK package + command: yarn remove instabug-reactnative-ndk + working_directory: << parameters.working_directory >>/examples/default notify_github: parameters: @@ -101,20 +182,38 @@ jobs: command: yarn lint:ci test_module: + parameters: + prepare_steps: + type: steps + default: [] + collect_coverage: + type: boolean + default: false executor: name: node/default steps: - advanced-checkout/shallow-checkout + - steps: << parameters.prepare_steps >> - install_node_modules - run: name: Run Tests command: yarn test - - persist_to_workspace: - root: coverage - paths: - - lcov.info + - when: + condition: << parameters.collect_coverage >> + steps: + - persist_to_workspace: + root: coverage + paths: + - lcov.info test_android: + parameters: + prepare_steps: + type: steps + default: [] + collect_coverage: + type: boolean + default: false executor: name: android/android-machine tag: '2024.01.1' @@ -123,15 +222,18 @@ jobs: INSTABUG_SOURCEMAPS_UPLOAD_DISABLE: true steps: - advanced-checkout/shallow-checkout - # - node/install-yarn + - steps: << parameters.prepare_steps >> - install_node_modules - android/run-tests: working-directory: android test-command: ./gradlew test - - persist_to_workspace: - root: ~/project/android/build/reports/jacoco/jacocoTestReport - paths: - - jacocoTestReport.xml + - when: + condition: << parameters.collect_coverage >> + steps: + - persist_to_workspace: + root: ~/project/android/build/reports/jacoco/jacocoTestReport + paths: + - jacocoTestReport.xml validate_shell_files: machine: @@ -160,10 +262,18 @@ jobs: app-dir: examples/default - install_pods: working_directory: examples/default/ios + deployment: true - run: git --no-pager diff - run: git diff-index HEAD --exit-code -p -I EXCLUDED_ARCHS # Ignore Arch Changes test_ios: + parameters: + prepare_steps: + type: steps + default: [] + collect_coverage: + type: boolean + default: false macos: xcode: 13.4.1 resource_class: macos.m1.medium.gen1 @@ -172,6 +282,7 @@ jobs: INSTABUG_SOURCEMAPS_UPLOAD_DISABLE: true steps: - advanced-checkout/shallow-checkout + - steps: << parameters.prepare_steps >> - install_node_modules - install_pods: working_directory: ios @@ -186,16 +297,23 @@ jobs: -sdk iphonesimulator \ -destination 'platform=iOS Simulator,name=iPhone 13 Pro Max,OS=15.5' \ test | xcpretty - - run: - name: Convert xcresult into JSON report - working_directory: ios/coverage - command: xcrun xccov view --report --json result.xcresult > xcode.json - - persist_to_workspace: - root: ios/coverage - paths: - - xcode.json + - when: + condition: << parameters.collect_coverage >> + steps: + - run: + name: Convert xcresult into JSON report + working_directory: ios/coverage + command: xcrun xccov view --report --json result.xcresult > xcode.json + - persist_to_workspace: + root: ios/coverage + paths: + - xcode.json e2e_ios: + parameters: + prepare_steps: + type: steps + default: [] macos: xcode: 13.4.1 resource_class: macos.m1.medium.gen1 @@ -203,6 +321,7 @@ jobs: INSTABUG_SOURCEMAPS_UPLOAD_DISABLE: true steps: - advanced-checkout/shallow-checkout + - steps: << parameters.prepare_steps >> - install_node_modules - node/install-packages: pkg-manager: yarn @@ -219,6 +338,11 @@ jobs: name: Rebuild Detox.framework Cache working_directory: examples/default command: detox clean-framework-cache && detox build-framework-cache + # This is a workaround until the iOS SDK is updated to prioritize the custom + # Instabug.plist over the internal Config.plist. + - run: + name: Customize API Endpoints + command: ./scripts/customize-ios-endpoints.sh - run: name: Detox - Build Release App working_directory: examples/default @@ -229,6 +353,10 @@ jobs: command: detox test --configuration ios.sim.release --cleanup e2e_android: + parameters: + prepare_steps: + type: steps + default: [] executor: name: android/android-machine tag: '2024.01.1' @@ -237,7 +365,7 @@ jobs: INSTABUG_SOURCEMAPS_UPLOAD_DISABLE: true steps: - advanced-checkout/shallow-checkout - # - node/install-yarn + - steps: << parameters.prepare_steps >> - install_node_modules - node/install-packages: pkg-manager: yarn @@ -264,33 +392,16 @@ jobs: release_custom_package: parameters: - npm_package: - type: string - android_package: - type: string - api_endpoint: - type: string + prepare_steps: + type: steps + default: [] working_directory: ~/project executor: name: node/default steps: - advanced-checkout/shallow-checkout + - steps: << parameters.prepare_steps >> - install_node_modules - - run: - name: Remove README.md file - command: rm README.md - - find_and_replace: - files: package.json android/sourcemaps.gradle ios/sourcemaps.sh - search: instabug-reactnative - replace: << parameters.npm_package >> - - find_and_replace: - files: cli/UploadSourcemaps.ts cli/UploadSoFiles.ts - search: api.instabug.com - replace: << parameters.api_endpoint >> - - find_and_replace: - files: android/native.gradle - search: 'com.instabug.library:instabug:' - replace: 'com.instabug.library-<< parameters.android_package >>:instabug:' - run: name: Build the SDK command: yarn build @@ -301,45 +412,6 @@ jobs: name: Publish new enterprise version command: npm publish - # Automate the enterprise D11 sdk changes - release_d11: - working_directory: ~/project - executor: - name: node/default - steps: - - advanced-checkout/shallow-checkout - - install_node_modules - - run: - name: Remove README.md file - command: rm README.md - - find_and_replace: - files: package.json ios/sourcemaps.sh android/sourcemaps.gradle - search: instabug-reactnative - replace: '@instabug/instabug-reactnative-dream11' - - find_and_replace: - files: cli/UploadSourcemaps.ts cli/UploadSoFiles.ts - search: api.instabug.com - replace: st001012dream11.instabug.com - - find_and_replace: - files: android/native.gradle - search: com.instabug.library:instabug - replace: 'com.instabug.library-dream11:instabug' - - run: - name: give exec permssion to d11 script - command: chmod +x ./scripts/dream-11-delete-unused-features.sh - - run: - name: remove un-required features - command: ./scripts/dream-11-delete-unused-features.sh - - run: - name: Build the SDK - command: yarn build - - run: - name: Authorize with npm - command: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc - - run: - name: Publish new enterprise version - command: npm publish - publish: macos: xcode: 13.4.1 @@ -397,35 +469,22 @@ jobs: - run: yarn build - run: yarn remove @instabug/danger-plugin-coverage - run: - name: Remove build files from .gitignore - command: sed -i '/dist/d' .gitignore && sed -i '/bin/d' .gitignore - - run: - name: Get snapshot branch name + name: Get snapshot version command: | - source scripts/snapshot-branch.sh - echo "export SNAPSHOT_BRANCH=$SNAPSHOT_BRANCH" >> "$BASH_ENV" + source scripts/snapshot-version.sh + echo "export SNAPSHOT_VERSION=$SNAPSHOT_VERSION" >> "$BASH_ENV" - run: - name: Setup Git - command: | - git config --global user.name "Instabug-CP-CI" - git config --global user.email github-ci+cp@instabug.com - - run: - name: Create snapshot branch - command: git checkout -b $SNAPSHOT_BRANCH - - run: - name: Commit changes - command: | - git add . - git commit -m "chore: add generate files" - - run: - name: Push snapshot - command: git push --force origin $SNAPSHOT_BRANCH + name: Authorize with NPM + command: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc + - run: npm version $SNAPSHOT_VERSION --no-git-tag-version + - run: npm publish --tag snapshot - run: name: Install jq command: sudo apt-get update && sudo apt-get install -y jq - - run: - name: Replace snapshot branch in comment template - command: sed -i "s|{BRANCH}|$SNAPSHOT_BRANCH|g" scripts/snapshot-comment.md + - find_and_replace: + files: scripts/snapshot-comment.md + search: '{VERSION}' + replace: $SNAPSHOT_VERSION - notify_github: data: "$(jq -Rcs '{ body: . }' scripts/snapshot-comment.md)" @@ -438,11 +497,14 @@ workflows: - test_android - test_ios - lint - - test_module - - test_android + - test_module: + collect_coverage: true + - test_android: + collect_coverage: true + - test_ios: + collect_coverage: true - validate_shell_files - sync_generated_files - - test_ios - e2e_ios - e2e_android - hold_generate_snapshot: @@ -463,12 +525,6 @@ workflows: filters: branches: only: master - - hold_release_d11: - requires: *release_dependencies - type: approval - filters: - branches: - only: dream11 - publish: requires: - hold_publish @@ -481,6 +537,7 @@ workflows: filters: branches: only: master + - hold_release_nn: requires: *release_dependencies type: approval @@ -494,9 +551,12 @@ workflows: filters: branches: only: master - npm_package: '@instabug/react-native-nn' - android_package: nn - api_endpoint: st001009nn.instabug.com + prepare_steps: + - prepare_custom_package: + npm_package: '@instabug/react-native-nn' + android_package: nn + api_endpoint: st001009nn.instabug.com + - hold_release_injazat: requires: *release_dependencies type: approval @@ -510,12 +570,49 @@ workflows: filters: branches: only: master - npm_package: '@instabug/react-native-injazat' - android_package: injazat - api_endpoint: st001013mec1.instabug.com - - release_d11: + prepare_steps: + - prepare_custom_package: + npm_package: '@instabug/react-native-injazat' + android_package: injazat + api_endpoint: st001013mec1.instabug.com + + # Dream11 tests + - hold_test_dream11: + type: approval + - test_module: + name: test_module_dream11 + <<: *dream11_prepare_config + - test_android: + name: test_android_dream11 + <<: *dream11_prepare_config + - test_ios: + name: test_ios_dream11 + <<: *dream11_prepare_config + - e2e_android: + name: e2e_android_dream11 + <<: *dream11_prepare_config + - e2e_ios: + name: e2e_ios_dream11 + <<: *dream11_prepare_config + + # Dream11 release + - hold_release_dream11: + requires: + - test_module_dream11 + - test_android_dream11 + - test_ios_dream11 + - e2e_android_dream11 + - e2e_ios_dream11 + type: approval + filters: + branches: + only: dream11 + - release_custom_package: + name: release_dream11 requires: - - hold_release_d11 + - hold_release_dream11 filters: branches: only: dream11 + prepare_steps: + - prepare_dream11 diff --git a/CHANGELOG.md b/CHANGELOG.md index 940033265..85dd5f063 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,24 @@ # Changelog +## [13.4.0](https://github.com/Instabug/Instabug-React-Native/compare/v13.3.0...v13.4.0) (October 2, 2024) + +### Added + +- Add support for Expo Router navigation tracking ([#1270](https://github.com/Instabug/Instabug-React-Native/pull/1270)). +- Enhance the network interceptor to capture more client error messages ([#1257](https://github.com/Instabug/Instabug-React-Native/pull/1257)). + +### Changed + +- Bump Instabug iOS SDK to v13.4.2 ([#1285](https://github.com/Instabug/Instabug-React-Native/pull/1285)). See release notes for [13.4.0](https://github.com/Instabug/Instabug-iOS/releases/tag/13.4.0), [13.4.1](https://github.com/Instabug/Instabug-iOS/releases/tag/13.4.1) and [13.4.2](https://github.com/Instabug/Instabug-iOS/releases/tag/13.4.2). +- Bump Instabug Android SDK to v13.4.1 ([#1285](https://github.com/Instabug/Instabug-React-Native/pull/1285)). See release notes for [13.4.0](https://github.com/Instabug/Instabug-Android/releases/tag/v13.4.0) and [13.4.1](https://github.com/Instabug/Instabug-Android/releases/tag/v13.4.1). + +### Fixed + +- Fix an issue with JavaScript fatal crashes on iOS causing them to be reported as native iOS crashes instead. ([#1290](https://github.com/Instabug/Instabug-React-Native/pull/1290)). +- Correctly resolve the flavor path when uploading sourcemaps on Android. ([#1225](https://github.com/Instabug/Instabug-React-Native/pull/1225)). +- Drop non-error objects reported as crashes since they don't have a stack trace ([#1279](https://github.com/Instabug/Instabug-React-Native/pull/1279)). +- Fix APM network logging on iOS when the response body is missing or empty. ([#1273](https://github.com/Instabug/Instabug-React-Native/pull/1273)). + ## [13.3.0](https://github.com/Instabug/Instabug-React-Native/compare/v13.2.0...v13.3.0) (August 4, 2024) ### Added diff --git a/android/build.gradle b/android/build.gradle index ffd71b5f8..c85924843 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -57,7 +57,7 @@ android { minSdkVersion getExtOrDefault('minSdkVersion').toInteger() targetSdkVersion getExtOrDefault('targetSdkVersion').toInteger() versionCode 1 - versionName "13.3.0" + versionName "13.4.0" multiDexEnabled true ndk { abiFilters "armeabi-v7a", "x86" diff --git a/android/native.gradle b/android/native.gradle index 0e86a4edf..ad47dccfe 100644 --- a/android/native.gradle +++ b/android/native.gradle @@ -1,5 +1,5 @@ project.ext.instabug = [ - version: '13.3.0' + version: '13.4.1' ] dependencies { diff --git a/android/sourcemaps.gradle b/android/sourcemaps.gradle index 37875e070..f544974d2 100644 --- a/android/sourcemaps.gradle +++ b/android/sourcemaps.gradle @@ -13,12 +13,13 @@ gradle.projectsEvaluated { def start = name.startsWith(prefixes[0]) ? prefixes[0].length() : prefixes[1].length() def end = name.length() - suffix.length() def flavor = name.substring(start, end).uncapitalize() + def defaultVersion = getDefaultVersion(flavor) - task.finalizedBy createUploadSourcemapsTask(flavor) + task.finalizedBy createUploadSourcemapsTask(flavor, defaultVersion.name, defaultVersion.code) } } -Task createUploadSourcemapsTask(String flavor) { +Task createUploadSourcemapsTask(String flavor, String defaultVersionName, String defaultVersionCode) { def name = 'uploadSourcemaps' + flavor.capitalize() // Don't recreate the task if it already exists. @@ -38,13 +39,7 @@ Task createUploadSourcemapsTask(String flavor) { try { def appProject = project(':app') def appDir = appProject.projectDir - def flavorPath = flavor + (flavor.empty ? '' : '/') - def sourceMapDest = "build/generated/sourcemaps/react/${flavorPath}release/index.android.bundle.map" - def sourceMapFile = new File(appDir, sourceMapDest) - - if (!sourceMapFile.exists()) { - throw new InvalidUserDataException("Unable to find source map file at: ${sourceMapFile.absolutePath}") - } + def sourceMapFile = getSourceMapFile(appDir, flavor) def jsProjectDir = rootDir.parentFile def instabugDir = new File(['node', '-p', 'require.resolve("instabug-reactnative/package.json")'].execute(null, rootDir).text.trim()).getParentFile() @@ -53,9 +48,8 @@ Task createUploadSourcemapsTask(String flavor) { def inferredToken = executeShellScript(tokenShellFile, jsProjectDir) def appToken = resolveVar('App Token', 'INSTABUG_APP_TOKEN', inferredToken) - def projectConfig = appProject.android.defaultConfig - def versionName = resolveVar('Version Name', 'INSTABUG_VERSION_NAME', "${projectConfig.versionName}") - def versionCode = resolveVar('Version Code', 'INSTABUG_VERSION_CODE', "${projectConfig.versionCode}") + def versionName = resolveVar('Version Name', 'INSTABUG_VERSION_NAME', defaultVersionName) + def versionCode = resolveVar('Version Code', 'INSTABUG_VERSION_CODE', defaultVersionCode) exec { def osCompatibility = Os.isFamily(Os.FAMILY_WINDOWS) ? ['cmd', '/c'] : [] @@ -80,6 +74,59 @@ Task createUploadSourcemapsTask(String flavor) { return provider.get() } +File getSourceMapFile(File appDir, String flavor) { + def defaultFlavorPath = flavor.empty ? 'release' : "${flavor}Release" + def defaultSourceMapDest = "build/generated/sourcemaps/react/${defaultFlavorPath}/index.android.bundle.map" + def defaultSourceMapFile = new File(appDir, defaultSourceMapDest) + + if (defaultSourceMapFile.exists()) { + return defaultSourceMapFile + } + + if (flavor.empty) { + throw new InvalidUserDataException("Unable to find source map file at: ${defaultSourceMapFile.absolutePath}.") + } + + def fallbackSourceMapDest = "build/generated/sourcemaps/react/${flavor}/release/index.android.bundle.map" + def fallbackSourceMapFile = new File(appDir, fallbackSourceMapDest) + + project.logger.info "Unable to find source map file at: ${defaultSourceMapFile.absolutePath}.\n" + + "Falling back to ${fallbackSourceMapFile.absolutePath}." + + if (!fallbackSourceMapFile.exists()) { + throw new InvalidUserDataException("Unable to find source map file at: ${fallbackSourceMapFile.absolutePath} either.") + } + + return fallbackSourceMapFile +} + +/** + * Infers the app version to use in source map upload based on the flavor. + * This is needed since different flavors may have different version codes and names (e.g. version suffixes). + * + * It checks the version for the flavor's variant. + * If no variant is found it falls back to the app's default config. + * + * + * @param flavor The flavor to get the app version for. + * @return A map containing the version code and version name. + */ +Map getDefaultVersion(String flavor) { + def appProject = project(':app') + def defaultConfig = appProject.android.defaultConfig + + def variants = appProject.android.applicationVariants + + // uncapitalize is used to turn "Release" into "release" if the flavor is empty + def variantName = "${flavor}Release".uncapitalize() + def variant = variants.find { it.name.uncapitalize() == variantName } + + def versionName = variant?.versionName ?: defaultConfig.versionName + def versionCode = variant?.versionCode ?: defaultConfig.versionCode + + return [name: "${versionName}", code: "${versionCode}"] +} + boolean isUploadSourcemapsEnabled() { def envValue = System.getenv('INSTABUG_SOURCEMAPS_UPLOAD_DISABLE')?.toBoolean() def defaultValue = true diff --git a/examples/default/android/app/src/main/java/com/instabug/react/example/RNInstabugExampleReactnativePackage.java b/examples/default/android/app/src/main/java/com/instabug/react/example/RNInstabugExampleReactnativePackage.java index 304ab6870..977afa782 100644 --- a/examples/default/android/app/src/main/java/com/instabug/react/example/RNInstabugExampleReactnativePackage.java +++ b/examples/default/android/app/src/main/java/com/instabug/react/example/RNInstabugExampleReactnativePackage.java @@ -6,14 +6,6 @@ import com.facebook.react.bridge.NativeModule; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.uimanager.ViewManager; -import com.instabug.reactlibrary.RNInstabugAPMModule; -import com.instabug.reactlibrary.RNInstabugBugReportingModule; -import com.instabug.reactlibrary.RNInstabugCrashReportingModule; -import com.instabug.reactlibrary.RNInstabugFeatureRequestsModule; -import com.instabug.reactlibrary.RNInstabugReactnativeModule; -import com.instabug.reactlibrary.RNInstabugRepliesModule; -import com.instabug.reactlibrary.RNInstabugSessionReplayModule; -import com.instabug.reactlibrary.RNInstabugSurveysModule; import java.util.ArrayList; import java.util.Collections; diff --git a/examples/default/android/app/src/main/res/raw/instabug_config.json b/examples/default/android/app/src/main/res/raw/instabug_config.json new file mode 100644 index 000000000..86b3a7a22 --- /dev/null +++ b/examples/default/android/app/src/main/res/raw/instabug_config.json @@ -0,0 +1,4 @@ +{ + "instabug-domain": "api.instabug.com", + "apm-domain": "api-apm.instabug.com" +} diff --git a/examples/default/android/build.gradle b/examples/default/android/build.gradle index 0336ff851..7fa616eb1 100644 --- a/examples/default/android/build.gradle +++ b/examples/default/android/build.gradle @@ -27,5 +27,13 @@ allprojects { maven { url("$rootDir/../node_modules/detox/Detox-android") } + + maven { + credentials { + username System.getenv("DREAM11_MAVEN_USERNAME") + password System.getenv("DREAM11_MAVEN_PASSWORD") + } + url "https://mvn.instabug.com/nexus/repository/dream-11" + } } } diff --git a/examples/default/ios/InstabugExample.xcodeproj/project.pbxproj b/examples/default/ios/InstabugExample.xcodeproj/project.pbxproj index afe4ffe60..3b05a8f1e 100644 --- a/examples/default/ios/InstabugExample.xcodeproj/project.pbxproj +++ b/examples/default/ios/InstabugExample.xcodeproj/project.pbxproj @@ -21,6 +21,7 @@ CC3DF8932A1DFC9A003E9914 /* InstabugSurveysTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CC3DF88B2A1DFC99003E9914 /* InstabugSurveysTests.m */; }; CC3DF8942A1DFC9A003E9914 /* InstabugAPMTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CC3DF88C2A1DFC99003E9914 /* InstabugAPMTests.m */; }; CC3DF8952A1DFC9A003E9914 /* IBGConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = CC3DF88D2A1DFC9A003E9914 /* IBGConstants.m */; }; + CC487A9C2C71FCFC0021F680 /* Instabug.plist in Resources */ = {isa = PBXBuildFile; fileRef = CC487A9B2C71FCFC0021F680 /* Instabug.plist */; }; CCF1E4092B022CF20024802D /* RNInstabugTests.m in Sources */ = {isa = PBXBuildFile; fileRef = CCF1E4082B022CF20024802D /* RNInstabugTests.m */; }; CD36F4707EA1F435D2CC7A15 /* libPods-InstabugExample-InstabugTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3AF7A6E02D40E0CEEA833CC4 /* libPods-InstabugExample-InstabugTests.a */; }; F7BF47401EF3A435254C97BB /* libPods-InstabugExample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BAED0D0441A708AE2390E153 /* libPods-InstabugExample.a */; }; @@ -64,6 +65,7 @@ CC3DF88B2A1DFC99003E9914 /* InstabugSurveysTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = InstabugSurveysTests.m; sourceTree = ""; }; CC3DF88C2A1DFC99003E9914 /* InstabugAPMTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = InstabugAPMTests.m; sourceTree = ""; }; CC3DF88D2A1DFC9A003E9914 /* IBGConstants.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IBGConstants.m; sourceTree = ""; }; + CC487A9B2C71FCFC0021F680 /* Instabug.plist */ = {isa = PBXFileReference; lastKnownFileType = file.bplist; name = Instabug.plist; path = InstabugExample/Instabug.plist; sourceTree = ""; }; CCF1E4082B022CF20024802D /* RNInstabugTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNInstabugTests.m; sourceTree = ""; }; DBCB1B1D023646D84146C91E /* Pods-InstabugExample-InstabugTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-InstabugExample-InstabugTests.release.xcconfig"; path = "Target Support Files/Pods-InstabugExample-InstabugTests/Pods-InstabugExample-InstabugTests.release.xcconfig"; sourceTree = ""; }; ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; }; @@ -120,6 +122,7 @@ 13B07FAE1A68108700A75B9A /* InstabugExample */ = { isa = PBXGroup; children = ( + CC487A9B2C71FCFC0021F680 /* Instabug.plist */, 13B07FAF1A68108700A75B9A /* AppDelegate.h */, 13B07FB01A68108700A75B9A /* AppDelegate.mm */, 13B07FB51A68108700A75B9A /* Images.xcassets */, @@ -296,6 +299,7 @@ buildActionMask = 2147483647; files = ( 81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */, + CC487A9C2C71FCFC0021F680 /* Instabug.plist in Resources */, 13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/examples/default/ios/InstabugExample/Instabug.plist b/examples/default/ios/InstabugExample/Instabug.plist new file mode 100644 index 000000000..24d035f42 Binary files /dev/null and b/examples/default/ios/InstabugExample/Instabug.plist differ diff --git a/examples/default/ios/InstabugTests/InstabugCrashReportingTests.m b/examples/default/ios/InstabugTests/InstabugCrashReportingTests.m index 0d5ac7348..d42e47022 100644 --- a/examples/default/ios/InstabugTests/InstabugCrashReportingTests.m +++ b/examples/default/ios/InstabugTests/InstabugCrashReportingTests.m @@ -26,6 +26,22 @@ - (void)testSetEnabled { XCTAssertFalse(IBGCrashReporting.enabled); } +- (void)testSendJSCrash { + NSDictionary *stackTrace = @{}; + + XCTestExpectation *expectation = [self expectationWithDescription:@"Expected resolve to be called."]; + + RCTPromiseResolveBlock resolve = ^(id result) { + [expectation fulfill]; + }; + RCTPromiseRejectBlock reject = ^(NSString *code, NSString *message, NSError *error) {}; + + [self.bridge sendJSCrash:stackTrace resolver:resolve rejecter:reject]; + + [self waitForExpectations:@[expectation] timeout:1]; + OCMVerify([self.mCrashReporting cp_reportFatalCrashWithStackTrace:stackTrace]); +} + - (void)testSendNonFatalErrorJsonCrash { NSDictionary *jsonCrash = @{}; NSString *fingerPrint = @"fingerprint"; diff --git a/examples/default/ios/InstabugTests/InstabugSampleTests.m b/examples/default/ios/InstabugTests/InstabugSampleTests.m index 565a21b1a..51bbe182c 100644 --- a/examples/default/ios/InstabugTests/InstabugSampleTests.m +++ b/examples/default/ios/InstabugTests/InstabugSampleTests.m @@ -8,7 +8,6 @@ #import #import "OCMock/OCMock.h" #import "Instabug/Instabug.h" -#import "Instabug/IBGSurvey.h" #import "InstabugReactBridge.h" #import #import "IBGConstants.h" @@ -366,7 +365,12 @@ - (void)testNetworkLogIOS { startTime:startTime * 1000 duration:duration * 1000 gqlQueryName:gqlQueryName - serverErrorMessage:serverErrorMessage]); + serverErrorMessage:serverErrorMessage + isW3cCaughted:nil + partialID:nil + timestamp:nil + generatedW3CTraceparent:nil + caughtedW3CTraceparent:nil]); } - (void)testSetFileAttachment { diff --git a/examples/default/ios/InstabugTests/RNInstabugTests.m b/examples/default/ios/InstabugTests/RNInstabugTests.m index 0df2fd843..cde248ad3 100644 --- a/examples/default/ios/InstabugTests/RNInstabugTests.m +++ b/examples/default/ios/InstabugTests/RNInstabugTests.m @@ -1,7 +1,6 @@ #import #import "OCMock/OCMock.h" #import "Instabug/Instabug.h" -#import "Instabug/IBGSurvey.h" #import #import "RNInstabug.h" #import "RNInstabug/Instabug+CP.h" diff --git a/examples/default/ios/Podfile.lock b/examples/default/ios/Podfile.lock index 1da6e558e..e59615769 100644 --- a/examples/default/ios/Podfile.lock +++ b/examples/default/ios/Podfile.lock @@ -38,7 +38,7 @@ PODS: - hermes-engine (0.72.3): - hermes-engine/Pre-built (= 0.72.3) - hermes-engine/Pre-built (0.72.3) - - Instabug (13.3.0) + - Instabug (13.4.2) - instabug-reactnative-ndk (0.1.0): - RCT-Folly (= 2021.07.22.00) - React-Core @@ -475,8 +475,8 @@ PODS: - RNGestureHandler (2.13.4): - RCT-Folly (= 2021.07.22.00) - React-Core - - RNInstabug (13.3.0): - - Instabug (= 13.3.0) + - RNInstabug (13.4.0): + - Instabug (= 13.4.2) - React-Core - RNReanimated (3.5.4): - DoubleConversion @@ -704,7 +704,7 @@ SPEC CHECKSUMS: Google-Maps-iOS-Utils: f77eab4c4326d7e6a277f8e23a0232402731913a GoogleMaps: 032f676450ba0779bd8ce16840690915f84e57ac hermes-engine: 10fbd3f62405c41ea07e71973ea61e1878d07322 - Instabug: 4f26295103a330ec0236918359eef7ccaa74e2fa + Instabug: 7a71890217b97b1e32dbca96661845396b66da2f instabug-reactnative-ndk: 960119a69380cf4cbe47ccd007c453f757927d17 libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913 OCMock: 300b1b1b9155cb6378660b981c2557448830bdc6 @@ -748,7 +748,7 @@ SPEC CHECKSUMS: ReactCommon: 3ccb8fb14e6b3277e38c73b0ff5e4a1b8db017a9 RNCClipboard: 41d8d918092ae8e676f18adada19104fa3e68495 RNGestureHandler: 6e46dde1f87e5f018a54fe5d40cd0e0b942b49ee - RNInstabug: a4ac0bd09123f6be7d58be541dc220acbaff8dc3 + RNInstabug: 8e7eb1df3f35b935dda661f5bb475f37cef595e6 RNReanimated: ab2e96c6d5591c3dfbb38a464f54c8d17fb34a87 RNScreens: b21dc57dfa2b710c30ec600786a3fc223b1b92e7 RNSVG: 80584470ff1ffc7994923ea135a3e5ad825546b9 diff --git a/examples/default/package.json b/examples/default/package.json index 529521802..a618c2811 100644 --- a/examples/default/package.json +++ b/examples/default/package.json @@ -16,6 +16,7 @@ "@react-navigation/native": "^6.1.6", "@react-navigation/native-stack": "^6.9.12", "graphql": "^16.8.1", + "axios": "^1.7.4", "graphql-request": "^6.1.0", "instabug-reactnative": "link:../..", "instabug-reactnative-ndk": "github:https://github.com/Instabug/Instabug-React-Native-NDK", diff --git a/examples/default/src/App.tsx b/examples/default/src/App.tsx index d92db633c..33a3c34f9 100644 --- a/examples/default/src/App.tsx +++ b/examples/default/src/App.tsx @@ -2,7 +2,7 @@ import React, { useEffect } from 'react'; import { StyleSheet } from 'react-native'; import { GestureHandlerRootView } from 'react-native-gesture-handler'; -import { NavigationContainer } from '@react-navigation/native'; +import { NavigationContainer, useNavigationContainerRef } from '@react-navigation/native'; import Instabug, { CrashReporting, InvocationEvent, @@ -20,6 +20,7 @@ import { QueryClient, QueryClientProvider } from 'react-query'; const queryClient = new QueryClient(); export const App: React.FC = () => { + const navigationRef = useNavigationContainerRef(); useEffect(() => { Instabug.init({ token: 'deb1910a7342814af4e4c9210c786f35', @@ -33,11 +34,17 @@ export const App: React.FC = () => { }); }, []); + useEffect(() => { + const unregisterListener = Instabug.setNavigationListener(navigationRef); + + return unregisterListener; + }, [navigationRef]); + return ( - + diff --git a/examples/default/src/screens/apm/NetworkScreen.tsx b/examples/default/src/screens/apm/NetworkScreen.tsx index 467a621f2..40ad2b5fa 100644 --- a/examples/default/src/screens/apm/NetworkScreen.tsx +++ b/examples/default/src/screens/apm/NetworkScreen.tsx @@ -7,6 +7,7 @@ import { useQuery } from 'react-query'; import { HStack, VStack } from 'native-base'; import { gql, request } from 'graphql-request'; import { CustomButton } from '../../components/CustomButton'; +import axios from 'axios'; export const NetworkScreen: React.FC = () => { const [endpointUrl, setEndpointUrl] = useState(''); @@ -45,6 +46,32 @@ export const NetworkScreen: React.FC = () => { } } + async function sendRequestToUrlUsingAxios() { + let urlToSend = ''; + + if (endpointUrl.trim() !== '') { + urlToSend = endpointUrl; + console.log('Sending request to: ', endpointUrl); + } else { + // Use json placeholder URL as a default if endpointUrl is empty + console.log('sending request to default json placeholder'); + urlToSend = defaultRequestUrl; + } + + try { + // Perform the request using the urlToSend + const response = await axios.get(urlToSend); + // Format the JSON response for better logging + const formattedData = JSON.stringify(response.data, null, 2); + + // Log the formatted response + console.log('Response:', formattedData); + } catch (error) { + // Handle errors appropriately + console.error('Error:', error); + } + } + const fetchGraphQlData = async () => { const document = gql` query { @@ -75,6 +102,11 @@ export const NetworkScreen: React.FC = () => { value={endpointUrl} /> + + refetch} title="Reload GraphQL" /> {isLoading && Loading...} diff --git a/examples/default/yarn.lock b/examples/default/yarn.lock index 74f7ce0e3..10aaed1cd 100644 --- a/examples/default/yarn.lock +++ b/examples/default/yarn.lock @@ -3239,11 +3239,25 @@ async@^3.2.2: resolved "https://registry.yarnpkg.com/async/-/async-3.2.4.tgz#2d22e00f8cddeb5fde5dd33522b56d1cf569a81c" integrity sha512-iAB+JbDEGXhyIUavoDl9WP/Jj106Kz9DEn1DPgYw5ruDn0e3Wgi3sKFm55sASdGBNOQB8F59d9qQ7deqrHA8wQ== +asynckit@^0.4.0: + version "0.4.0" + resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" + integrity sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q== + at-least-node@^1.0.0: version "1.0.0" resolved "https://registry.npmjs.org/at-least-node/-/at-least-node-1.0.0.tgz#602cd4b46e844ad4effc92a8011a3c46e0238dc2" integrity sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg== +axios@^1.7.4: + version "1.7.4" + resolved "https://registry.yarnpkg.com/axios/-/axios-1.7.4.tgz#4c8ded1b43683c8dd362973c393f3ede24052aa2" + integrity sha512-DukmaFRnY6AzAALSH4J2M3k6PkaC+MfaAGdEERRWcC9q3/TWQwLpHR8ZRLKTdQ3aBDL64EdluRDjJqKw+BPZEw== + dependencies: + follow-redirects "^1.15.6" + form-data "^4.0.0" + proxy-from-env "^1.1.0" + babel-core@^7.0.0-bridge.0: version "7.0.0-bridge.0" resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-7.0.0-bridge.0.tgz#95a492ddd90f9b4e9a4a1da14eb335b87b634ece" @@ -3729,6 +3743,13 @@ colorette@^1.0.7: resolved "https://registry.yarnpkg.com/colorette/-/colorette-1.4.0.tgz#5190fbb87276259a86ad700bff2c6d6faa3fca40" integrity sha512-Y2oEozpomLn7Q3HFP7dpww7AtMJplbM9lGZP6RDfHqmbeRjiwRg4n6VM6j4KLmRke85uWEI7JqF17f3pqdRA0g== +combined-stream@^1.0.8: + version "1.0.8" + resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f" + integrity sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg== + dependencies: + delayed-stream "~1.0.0" + command-exists@^1.2.8: version "1.2.9" resolved "https://registry.yarnpkg.com/command-exists/-/command-exists-1.2.9.tgz#c50725af3808c8ab0260fd60b01fbfa25b954f69" @@ -3941,6 +3962,11 @@ define-data-property@^1.1.1: gopd "^1.0.1" has-property-descriptors "^1.0.0" +delayed-stream@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619" + integrity sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ== + denodeify@^1.2.1: version "1.2.1" resolved "https://registry.yarnpkg.com/denodeify/-/denodeify-1.2.1.tgz#3a36287f5034e699e7577901052c2e6c94251631" @@ -4329,6 +4355,20 @@ flow-parser@^0.206.0: resolved "https://registry.yarnpkg.com/flow-parser/-/flow-parser-0.206.0.tgz#f4f794f8026535278393308e01ea72f31000bfef" integrity sha512-HVzoK3r6Vsg+lKvlIZzaWNBVai+FXTX1wdYhz/wVlH13tb/gOdLXmlTqy6odmTBhT5UoWUbq0k8263Qhr9d88w== +follow-redirects@^1.15.6: + version "1.15.6" + resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.15.6.tgz#7f815c0cda4249c74ff09e95ef97c23b5fd0399b" + integrity sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA== + +form-data@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.0.tgz#93919daeaf361ee529584b9b31664dc12c9fa452" + integrity sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww== + dependencies: + asynckit "^0.4.0" + combined-stream "^1.0.8" + mime-types "^2.1.12" + fresh@0.5.2: version "0.5.2" resolved "https://registry.yarnpkg.com/fresh/-/fresh-0.5.2.tgz#3d8cadd90d976569fa835ab1f8e4b23a105605a7" @@ -4650,7 +4690,8 @@ inline-style-prefixer@^6.0.1: resolved "https://codeload.github.com/Instabug/Instabug-React-Native-NDK/tar.gz/3b0bac281253133852d32f52aa50cc805dd0b570" "instabug-reactnative@link:../..": - version "13.0.5" + version "0.0.0" + uid "" intl-messageformat@^10.1.0: version "10.5.0" @@ -6105,7 +6146,7 @@ mime-db@1.52.0, "mime-db@>= 1.43.0 < 2": resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.52.0.tgz#bbabcdc02859f4987301c856e3387ce5ec43bf70" integrity sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg== -mime-types@^2.1.27, mime-types@~2.1.34: +mime-types@^2.1.12, mime-types@^2.1.27, mime-types@~2.1.34: version "2.1.35" resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.35.tgz#381a871b62a734450660ae3deee44813f70d959a" integrity sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw== @@ -6664,6 +6705,11 @@ proper-lockfile@^3.0.2: retry "^0.12.0" signal-exit "^3.0.2" +proxy-from-env@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2" + integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg== + pseudomap@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3" diff --git a/ios/RNInstabug/InstabugCrashReportingBridge.m b/ios/RNInstabug/InstabugCrashReportingBridge.m index 9d878854f..c73a85d5b 100644 --- a/ios/RNInstabug/InstabugCrashReportingBridge.m +++ b/ios/RNInstabug/InstabugCrashReportingBridge.m @@ -29,12 +29,9 @@ + (BOOL)requiresMainQueueSetup RCT_EXPORT_METHOD(sendJSCrash:(NSDictionary *)stackTrace resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) { - dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul); + dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul); dispatch_async(queue, ^{ - SEL reportCrashWithStackTraceSEL = NSSelectorFromString(@"reportCrashWithStackTrace:handled:"); - if ([[Instabug class] respondsToSelector:reportCrashWithStackTraceSEL]) { - [[Instabug class] performSelector:reportCrashWithStackTraceSEL withObject:stackTrace withObject:@(NO)]; - } + [IBGCrashReporting cp_reportFatalCrashWithStackTrace:stackTrace]; resolve([NSNull null]); }); } @@ -45,8 +42,6 @@ + (BOOL)requiresMainQueueSetup rejecter:(RCTPromiseRejectBlock)reject) { dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul); dispatch_async(queue, ^{ - - [IBGCrashReporting cp_reportNonFatalCrashWithStackTrace:stackTrace level:nonFatalExceptionLevel groupingString:fingerprint userAttributes:userAttributes]; resolve([NSNull null]); diff --git a/ios/RNInstabug/InstabugReactBridge.h b/ios/RNInstabug/InstabugReactBridge.h index c2accc995..a3cfc21c1 100644 --- a/ios/RNInstabug/InstabugReactBridge.h +++ b/ios/RNInstabug/InstabugReactBridge.h @@ -12,7 +12,6 @@ #import #import #import -#import #import #import #import "ArgsRegistry.h" diff --git a/ios/RNInstabug/InstabugReactBridge.m b/ios/RNInstabug/InstabugReactBridge.m index a6f56109c..534b84908 100644 --- a/ios/RNInstabug/InstabugReactBridge.m +++ b/ios/RNInstabug/InstabugReactBridge.m @@ -8,7 +8,6 @@ #import #import #import -#import #import #import #import @@ -315,7 +314,12 @@ - (dispatch_queue_t)methodQueue { startTime:startTime * 1000 duration:duration * 1000 gqlQueryName:gqlQueryName - serverErrorMessage:serverErrorMessage]; + serverErrorMessage:serverErrorMessage + isW3cCaughted:nil + partialID:nil + timestamp:nil + generatedW3CTraceparent:nil + caughtedW3CTraceparent:nil]; } RCT_EXPORT_METHOD(addPrivateView: (nonnull NSNumber *)reactTag) { diff --git a/ios/RNInstabug/Util/IBGNetworkLogger+CP.h b/ios/RNInstabug/Util/IBGNetworkLogger+CP.h index 5ae464785..436553620 100644 --- a/ios/RNInstabug/Util/IBGNetworkLogger+CP.h +++ b/ios/RNInstabug/Util/IBGNetworkLogger+CP.h @@ -5,22 +5,27 @@ NS_ASSUME_NONNULL_BEGIN @interface IBGNetworkLogger (CP) + (void)disableAutomaticCapturingOfNetworkLogs; -+ (void)addNetworkLogWithUrl:(NSString *)url - method:(NSString *)method - requestBody:(NSString *)request ++ (void)addNetworkLogWithUrl:(NSString *_Nonnull)url + method:(NSString *_Nonnull)method + requestBody:(NSString *_Nonnull)request requestBodySize:(int64_t)requestBodySize - responseBody:(NSString *)response + responseBody:(NSString *_Nonnull)response responseBodySize:(int64_t)responseBodySize responseCode:(int32_t)code - requestHeaders:(NSDictionary *)requestHeaders - responseHeaders:(NSDictionary *)responseHeaders - contentType:(NSString *)contentType - errorDomain:(NSString *)errorDomain + requestHeaders:(NSDictionary *_Nonnull)requestHeaders + responseHeaders:(NSDictionary *_Nonnull)responseHeaders + contentType:(NSString *_Nonnull)contentType + errorDomain:(NSString *_Nullable)errorDomain errorCode:(int32_t)errorCode startTime:(int64_t)startTime duration:(int64_t) duration gqlQueryName:(NSString * _Nullable)gqlQueryName - serverErrorMessage:(NSString * _Nullable)serverErrorMessage; + serverErrorMessage:(NSString * _Nullable)serverErrorMessage + isW3cCaughted:(NSNumber * _Nullable)isW3cCaughted + partialID:(NSNumber * _Nullable)partialID + timestamp:(NSNumber * _Nullable)timestamp + generatedW3CTraceparent:(NSString * _Nullable)generatedW3CTraceparent + caughtedW3CTraceparent:(NSString * _Nullable)caughtedW3CTraceparent; @end diff --git a/ios/native.rb b/ios/native.rb index c5188a3a7..f4f01e1ae 100644 --- a/ios/native.rb +++ b/ios/native.rb @@ -1,4 +1,4 @@ -$instabug = { :version => '13.3.0' } +$instabug = { :version => '13.4.2' } def use_instabug! (spec = nil) version = $instabug[:version] diff --git a/package.json b/package.json index d641ecad6..ee890e470 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "instabug-reactnative", "description": "React Native plugin for integrating the Instabug SDK", - "version": "13.3.0", + "version": "13.4.0", "author": "Instabug (https://instabug.com)", "repository": "github:Instabug/Instabug-React-Native", "homepage": "https://www.instabug.com/platforms/react-native", diff --git a/scripts/customize-ios-endpoints.sh b/scripts/customize-ios-endpoints.sh new file mode 100755 index 000000000..2fecd9d72 --- /dev/null +++ b/scripts/customize-ios-endpoints.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# Replaces the internal Config.plist file inside the Instabug iOS SDK with the +# Instabug.plist file in the example app. +# +# This is a workaround until the iOS SDK is updated to prioritize the custom +# Instabug.plist over the internal Config.plist. + +instabug_plist=examples/default/ios/InstabugExample/Instabug.plist + +if [ ! -f $instabug_plist ]; then + echo "Instabug.plist not found" + exit 1 +fi + +for dir in examples/default/ios/Pods/Instabug/Instabug.xcframework/ios-*/ +do + echo "Replacing Config.plist in $dir" + + config_path=$dir/Instabug.framework/InstabugResources.bundle/Config.plist + + if [ ! -f $config_path ]; then + echo "Config.plist not found in $dir" + exit 1 + fi + + cp -f $instabug_plist $config_path +done diff --git a/scripts/dream-11-delete-unused-features.sh b/scripts/dream-11-delete-unused-features.sh old mode 100644 new mode 100755 index 58ab39288..fa10a9181 --- a/scripts/dream-11-delete-unused-features.sh +++ b/scripts/dream-11-delete-unused-features.sh @@ -2,47 +2,61 @@ # remove survey and featureRequest features in JavaScript files deletedFeaturesFilesInJavaScript=("Surveys" "FeatureRequests" "Survey") -for feature in "${deletedFeaturesFilesInJavaScript[@]}"; - do - echo "$feature" -rm -f src/modules/"$feature".ts -rm -f test/mocks/mock"$feature".ts -sed -i "s/import..*$feature';//g" src/index.ts -sed -i "s/$feature,//g" src/index.ts - +for feature in "${deletedFeaturesFilesInJavaScript[@]}"; do + echo "$feature" + + rm -f src/modules/"$feature".ts + rm -f src/native/Native"$feature".ts + rm -f test/mocks/mock"$feature".ts + rm -f test/modules/"$feature".spec.ts + + node scripts/replace.js --pattern "import.+$feature';" "" src/index.ts + node scripts/replace.js --pattern "$feature," "" src/index.ts + node scripts/replace.js --pattern ".*$feature.*" "" src/native/NativePackage.ts + node scripts/replace.js --pattern ".*$feature.*" "" test/mocks/mockNativeModules.ts done -npx eslint src/index.ts --fix + +npx eslint src/index.ts --fix # remove survey and featureRequest features in Android files deletedFeaturesFilesInAndroidApp=("RNInstabugSurveysModule" "RNInstabugFeatureRequestsModule") -for feature in "${deletedFeaturesFilesInAndroidApp[@]}"; - do - echo "$feature" - -rm -f android/src/main/java/com/instabug/reactlibrary/"$feature".java -rm -f android/src/test/java/com/instabug/reactlibrary/"$feature"Test.java -sed -i "s/modules.add(new $feature(reactContext));//g" android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativePackage.java +for feature in "${deletedFeaturesFilesInAndroidApp[@]}"; do + echo "$feature" + rm -f android/src/main/java/com/instabug/reactlibrary/"$feature".java + rm -f android/src/test/java/com/instabug/reactlibrary/"$feature"Test.java + node scripts/replace.js "modules.add(new $feature(reactContext));" "" android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativePackage.java done # remove survey and featureRequest features in IOS files deletedFeaturesFilesInIosApp=("InstabugSurveysBridge" "InstabugFeatureRequestsBridge") -for feature in "${deletedFeaturesFilesInIosApp[@]}"; - do - echo "$feature" -rm -f ios/RNInstabug/"$feature".h -rm -f ios/RNInstabug/"$feature".m +for feature in "${deletedFeaturesFilesInIosApp[@]}"; do + echo "$feature" + rm -f ios/RNInstabug/"$feature".h + rm -f ios/RNInstabug/"$feature".m done -sed -i "s/\#import //g" ios/RNInstabug/InstabugReactBridge.m -sed -i "s/\#import //g" ios/RNInstabug/InstabugReactBridge.h +# Remove unused features iOS test files +iosTestFiles=("InstabugSurveysTests.m" "InstabugFeatureRequestsTests.m") +for file in "${iosTestFiles[@]}"; do + echo "Deleting $file" + + rm -f examples/default/ios/InstabugTests/"$file" + node scripts/replace.js --pattern ".*$file.*" "" examples/default/ios/InstabugExample.xcodeproj/project.pbxproj +done -# remove all locales except English locale -sed -i -E '/english/!s/.*constants.locale.*//g' src/utils/Enums.ts -npx eslint src/index.ts --fix src/utils/Enums.ts +node scripts/replace.js "#import " "" ios/RNInstabug/InstabugReactBridge.m +node scripts/replace.js "#import " "" ios/RNInstabug/InstabugReactBridge.h -sed -i "s/return (major == 7 && minor >= 3) || major >= 8/return false/g" android/build.gradle +# Remove all locales except for English +# This ugly regular expression matches all lines not containing "english" and containing "constants.locale" +node scripts/replace.js --pattern "^(?!.*english).+constants\.locale.*" "" src/utils/Enums.ts +npx eslint src/index.ts --fix src/utils/Enums.ts -sed -i "s/static boolean supportsNamespace() {/static boolean supportsNamespace() { \n return false/g" android/build.gradle +node scripts/replace.js "return (major == 7 && minor >= 3) || major >= 8" "return false" android/build.gradle +# Note: printf is used here as the string contains a newline character which would be escaped otherwise. +node scripts/replace.js "static boolean supportsNamespace() {" "$(printf "static boolean supportsNamespace() {\n return false")" android/build.gradle +# Add Dream11 custom iOS build podspec to Podfile +node scripts/replace.js "target 'InstabugExample' do" "$(printf "target 'InstabugExample' do\n pod 'Instabug', :podspec => 'https://ios-releases.instabug.com/custom/dream11/Instabug.podspec'")" examples/default/ios/Podfile diff --git a/scripts/replace.js b/scripts/replace.js index 5682b4726..aeb483ae8 100644 --- a/scripts/replace.js +++ b/scripts/replace.js @@ -10,10 +10,25 @@ const fs = require('fs'); const path = require('path'); +const { parseArgs } = require('util'); -const [search, replace, ...files] = process.argv.slice(2); +const { values, positionals } = parseArgs({ + allowPositionals: true, + options: { + pattern: { + type: 'boolean', + default: false, + short: 'p', + }, + }, +}); -if (!search || !replace || !files.length) { +const [search, replace, ...files] = positionals; + +/** Whether to replace the search string as a regular expression or as a literal string. */ +const isPattern = values.pattern; + +if (search == null || replace == null || !files.length) { // The path of the script relative to the directory where the user ran the // script to be used in the error message demonstrating the usage. const scriptPath = path.relative(process.cwd(), __filename); @@ -21,7 +36,7 @@ if (!search || !replace || !files.length) { console.error('Missing arguments.'); console.table({ search, replace, files }); - console.error(`Usage: node ${scriptPath} `); + console.error(`Usage: node ${scriptPath} [-p | --pattern] `); process.exit(1); } @@ -31,7 +46,8 @@ for (const file of files) { const fileContent = fs.readFileSync(filePath, 'utf8'); - const newContent = fileContent.replaceAll(search, replace); + const searchPattern = isPattern ? new RegExp(search, 'gm') : search; + const newContent = fileContent.replaceAll(searchPattern, replace); fs.writeFileSync(filePath, newContent); } catch (error) { diff --git a/scripts/snapshot-branch.sh b/scripts/snapshot-branch.sh deleted file mode 100755 index 652dd1bb9..000000000 --- a/scripts/snapshot-branch.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/bash - -pr_url="https://api.github.com/repos/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/pulls?head=$CIRCLE_PROJECT_USERNAME:$CIRCLE_BRANCH&state=open" -pr_response=$(curl --location --request GET "$pr_url" --header "Authorization: Bearer $RELEASE_GITHUB_TOKEN") - -if [ $(echo "$pr_response" | jq length) -eq 0 ]; then - echo "No PR found, proceeding with branch name instead" - - SNAPSHOT_BRANCH="snapshot/$CIRCLE_BRANCH" -else - pr_description=$(echo "$pr_response" | jq -r '.[].body') - - # The `sed "s/\r//g"` is used to remove the carriage return character \r from the end of the string - SNAPSHOT_BRANCH=$(echo -E "$pr_description" | grep 'Snapshot name:' | cut -d ':' -f 2 | xargs echo -n | sed "s/\r//g" || echo -n) - - if [ -z "$SNAPSHOT_BRANCH" ]; then - echo "No custom snapshot name found, proceeding with default snapshot naming convention" - - version=$(jq -r '.version' package.json) - jira_id=$(echo -E "$pr_description" | grep 'Jira ID:' | grep -Eo '[A-Z]+-[0-9]+' || echo -n) - - if [ -z "$jira_id" ]; then - echo "No Jira ID found, proceeding with branch name instead" - - SNAPSHOT_BRANCH="snapshot/$CIRCLE_BRANCH" - else - SNAPSHOT_BRANCH="snapshot/$version-$jira_id" - fi - fi -fi diff --git a/scripts/snapshot-comment.md b/scripts/snapshot-comment.md index 25ee16227..6acb6d726 100644 --- a/scripts/snapshot-comment.md +++ b/scripts/snapshot-comment.md @@ -5,11 +5,11 @@ Your snapshot has been generated! :rocket: You can install the snapshot through NPM: ```sh -npm install https://github.com/Instabug/Instabug-React-Native\#{BRANCH} +npm install instabug-reactnative@{VERSION} ``` or Yarn: ```sh -yarn add https://github.com/Instabug/Instabug-React-Native\#{BRANCH} +yarn add instabug-reactnative@{VERSION} ``` diff --git a/scripts/snapshot-version.sh b/scripts/snapshot-version.sh new file mode 100755 index 000000000..7ba0a0fd5 --- /dev/null +++ b/scripts/snapshot-version.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +# Generates a snapshot version following the format {version}-{pr}{random-3-digit}-SNAPSHOT +# Example: 13.3.0-502861-SNAPSHOT + +pr=$(basename $CIRCLE_PULL_REQUEST) +random=$(($RANDOM % 900 + 100)) +version=$(jq -r '.version' package.json) +suffix="SNAPSHOT" + +SNAPSHOT_VERSION="$version-$pr$random-$suffix" diff --git a/src/modules/CrashReporting.ts b/src/modules/CrashReporting.ts index 9ae743cad..c374c7d77 100644 --- a/src/modules/CrashReporting.ts +++ b/src/modules/CrashReporting.ts @@ -21,18 +21,25 @@ export const setEnabled = (isEnabled: boolean) => { * @param nonFatalOptions extra config for the non-fatal error sent with Error Object */ export const reportError = (error: ExtendedError, nonFatalOptions: NonFatalOptions = {}) => { - let level = NonFatalErrorLevel.error; - if (nonFatalOptions.level != null) { - level = nonFatalOptions.level; + if (error instanceof Error) { + let level = NonFatalErrorLevel.error; + if (nonFatalOptions.level != null) { + level = nonFatalOptions.level; + } + return InstabugUtils.sendCrashReport(error, (data) => + NativeCrashReporting.sendHandledJSCrash( + data, + nonFatalOptions.userAttributes, + nonFatalOptions.fingerprint, + level, + ), + ); + } else { + console.warn( + `IBG-RN: The error ${error} has been omitted because only error type is supported.`, + ); + return; } - return InstabugUtils.sendCrashReport(error, (data) => - NativeCrashReporting.sendHandledJSCrash( - data, - nonFatalOptions.userAttributes, - nonFatalOptions.fingerprint, - level, - ), - ); }; /** diff --git a/src/modules/Instabug.ts b/src/modules/Instabug.ts index baec7660a..29ff1d27c 100644 --- a/src/modules/Instabug.ts +++ b/src/modules/Instabug.ts @@ -1,7 +1,10 @@ import type React from 'react'; import { Platform, findNodeHandle, processColor } from 'react-native'; -import type { NavigationState as NavigationStateV5 } from '@react-navigation/native'; +import type { + NavigationContainerRefWithCurrent, + NavigationState as NavigationStateV5, +} from '@react-navigation/native'; import type { ComponentDidAppearEvent } from 'react-native-navigation'; import type { NavigationAction, NavigationState as NavigationStateV4 } from 'react-navigation'; @@ -533,6 +536,19 @@ export const onStateChange = (state?: NavigationStateV5) => { }, 1000); }; +/** + * Sets a listener for screen change + * @param navigationRef a refrence of a navigation container + * + */ +export const setNavigationListener = ( + navigationRef: NavigationContainerRefWithCurrent, +) => { + return navigationRef.addListener('state', () => { + onStateChange(navigationRef.getRootState()); + }); +}; + export const reportScreenChange = (screenName: string) => { NativeInstabug.reportScreenChange(screenName); }; diff --git a/src/utils/XhrNetworkInterceptor.ts b/src/utils/XhrNetworkInterceptor.ts index 701533f15..98c5ef9cc 100644 --- a/src/utils/XhrNetworkInterceptor.ts +++ b/src/utils/XhrNetworkInterceptor.ts @@ -72,7 +72,8 @@ export default { originalXHROpen = XMLHttpRequest.prototype.open; originalXHRSend = XMLHttpRequest.prototype.send; originalXHRSetRequestHeader = XMLHttpRequest.prototype.setRequestHeader; - + // An error code that signifies an issue with the RN client. + const clientErrorCode = 9876; XMLHttpRequest.prototype.open = function (method, url, ...args) { _reset(); network.url = url; @@ -145,14 +146,24 @@ export default { // @ts-ignore if (this._hasError) { - cloneNetwork.errorCode = 0; + cloneNetwork.errorCode = clientErrorCode; cloneNetwork.errorDomain = 'ClientError'; // @ts-ignore const _response = this._response; cloneNetwork.requestBody = typeof _response === 'string' ? _response : JSON.stringify(_response); - cloneNetwork.responseBody = null; + cloneNetwork.responseBody = ''; + + // Detect a more descriptive error message. + if (typeof _response === 'string' && _response.length > 0) { + cloneNetwork.errorDomain = _response; + } + + // @ts-ignore + } else if (this._timedOut) { + cloneNetwork.errorCode = clientErrorCode; + cloneNetwork.errorDomain = 'TimeOutError'; } if (this.response) { @@ -162,6 +173,9 @@ export default { } else if (['text', '', 'json'].includes(this.responseType)) { cloneNetwork.responseBody = JSON.stringify(this.response); } + } else { + cloneNetwork.responseBody = ''; + cloneNetwork.contentType = 'text/plain'; } cloneNetwork.requestBodySize = cloneNetwork.requestBody.length; diff --git a/test/modules/Instabug.spec.ts b/test/modules/Instabug.spec.ts index fdbdcae64..fdc1b91b2 100644 --- a/test/modules/Instabug.spec.ts +++ b/test/modules/Instabug.spec.ts @@ -2,6 +2,7 @@ import '../mocks/mockInstabugUtils'; import '../mocks/mockNetworkLogger'; import { Platform, findNodeHandle, processColor } from 'react-native'; +import type { NavigationContainerRefWithCurrent } from '@react-navigation/native'; // Import the hook import { mocked } from 'jest-mock'; import waitForExpect from 'wait-for-expect'; @@ -236,6 +237,42 @@ describe('Instabug Module', () => { await waitForExpect(() => expect(NativeInstabug.reportScreenChange).toBeCalledTimes(2)); }); + it('setNavigationListener should call the onStateChange on a screen change', async () => { + const mockedState = { routes: [{ name: 'ScreenName' }], index: 0 }; + + const mockNavigationContainerRef = { + current: null, + navigate: jest.fn(), + reset: jest.fn(), + goBack: jest.fn(), + dispatch: jest.fn(), + getRootState: () => mockedState, + canGoBack: jest.fn(), + + addListener: jest.fn((event, callback) => { + expect(event).toBe('state'); + callback(mockedState); + return jest.fn(); + }), + removeListener: jest.fn(), + } as unknown as NavigationContainerRefWithCurrent; + + const onStateChangeMock = jest.fn(); + + jest.spyOn(Instabug, 'onStateChange').mockImplementation(onStateChangeMock); + + Instabug.setNavigationListener(mockNavigationContainerRef); + + expect(mockNavigationContainerRef.addListener).toBeCalledTimes(1); + expect(mockNavigationContainerRef.addListener).toHaveBeenCalledWith( + 'state', + expect.any(Function), + ); + + expect(onStateChangeMock).toBeCalledTimes(1); + expect(onStateChangeMock).toHaveBeenCalledWith(mockNavigationContainerRef.getRootState()); + }); + it('should call the native method init', () => { const instabugConfig = { token: 'some-token', diff --git a/test/utils/XhrNetworkInterceptor.spec.ts b/test/utils/XhrNetworkInterceptor.spec.ts index b014bc9d9..10a8f1abb 100644 --- a/test/utils/XhrNetworkInterceptor.spec.ts +++ b/test/utils/XhrNetworkInterceptor.spec.ts @@ -235,8 +235,8 @@ describe('Network Interceptor', () => { expect(callback).toBeCalledWith( expect.objectContaining({ errorDomain: 'ClientError', - errorCode: 0, - responseBody: null, + errorCode: 9876, + responseBody: '', }), ); });