From f3fe5bca90ce92ca00816a360a1d79e04121f6c4 Mon Sep 17 00:00:00 2001 From: kholood Date: Tue, 27 May 2025 12:36:51 +0300 Subject: [PATCH 1/9] chore(ios): add respect BE network body limit custom build --- RNInstabug.podspec | 3 ++- examples/default/ios/Podfile | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/RNInstabug.podspec b/RNInstabug.podspec index af69112cc..b571a6c68 100644 --- a/RNInstabug.podspec +++ b/RNInstabug.podspec @@ -16,6 +16,7 @@ Pod::Spec.new do |s| s.source_files = "ios/**/*.{h,m,mm}" s.dependency 'React-Core' - use_instabug!(s) + # use_instabug!(s) + s.dependency 'Instabug' end diff --git a/examples/default/ios/Podfile b/examples/default/ios/Podfile index 10b2cc5b7..ef9550e04 100644 --- a/examples/default/ios/Podfile +++ b/examples/default/ios/Podfile @@ -16,8 +16,7 @@ target 'InstabugExample' do rn_maps_path = '../node_modules/react-native-maps' pod 'react-native-google-maps', :path => rn_maps_path # add this line - pod 'Instabug', :podspec => 'https://ios-releases.instabug.com/custom/fix-main-thread-warning/15.0.0/Instabug.podspec' - + pod 'Instabug', :podspec => 'https://ios-releases.instabug.com/custom/feature-expose_network_limit-expose_body_limit/15.0.1/Instabug.podspec' # Flags change depending on the env values. flags = get_default_flags() From 4465e017417abff7e42f405ef9724b28ddb7feb6 Mon Sep 17 00:00:00 2001 From: kholood Date: Tue, 27 May 2025 12:37:56 +0300 Subject: [PATCH 2/9] feat(ios): add getNetworkBodyMaxSize API --- .../ios/InstabugTests/InstabugSampleTests.m | 19 +++++++++++++++++++ ios/RNInstabug/InstabugReactBridge.h | 1 + ios/RNInstabug/InstabugReactBridge.m | 4 ++++ ios/RNInstabug/Util/IBGNetworkLogger+CP.h | 8 ++++++++ 4 files changed, 32 insertions(+) diff --git a/examples/default/ios/InstabugTests/InstabugSampleTests.m b/examples/default/ios/InstabugTests/InstabugSampleTests.m index 76b4cbc0c..ded37c3af 100644 --- a/examples/default/ios/InstabugTests/InstabugSampleTests.m +++ b/examples/default/ios/InstabugTests/InstabugSampleTests.m @@ -634,4 +634,23 @@ - (void)testSetNetworkLogBodyEnabled { OCMVerify([mock setLogBodyEnabled:isEnabled]); } +- (void)testGetNetworkBodyMaxSize { + id mock = OCMClassMock([IBGNetworkLogger class]); + double expectedValue = 10240.0; + + OCMStub([mock getNetworkBodyMaxSize]).andReturn(expectedValue); + + XCTestExpectation *expectation = [self expectationWithDescription:@"Call resolve block"]; + RCTPromiseResolveBlock resolve = ^(NSNumber *result) { + XCTAssertEqual(result.doubleValue, expectedValue); + [expectation fulfill]; + }; + + [self.instabugBridge getNetworkBodyMaxSize:resolve :nil]; + [self waitForExpectationsWithTimeout:1.0 handler:nil]; + + OCMVerify(ClassMethod([mock getNetworkBodyMaxSize])); +} + + @end diff --git a/ios/RNInstabug/InstabugReactBridge.h b/ios/RNInstabug/InstabugReactBridge.h index 8d6efcf69..1fe5505d3 100644 --- a/ios/RNInstabug/InstabugReactBridge.h +++ b/ios/RNInstabug/InstabugReactBridge.h @@ -140,5 +140,6 @@ w3cExternalTraceAttributes:(NSDictionary * _Nullable)w3cExternalTraceAttributes; - (void)removeAllFeatureFlags; - (void)setNetworkLogBodyEnabled:(BOOL)isEnabled; - (void)enableAutoMasking:(NSArray *)autoMaskingTypes; +- (void)getNetworkBodyMaxSize:(RCTPromiseResolveBlock)resolve :(RCTPromiseRejectBlock)reject; @end diff --git a/ios/RNInstabug/InstabugReactBridge.m b/ios/RNInstabug/InstabugReactBridge.m index 04d1c7ede..68f3fe85a 100644 --- a/ios/RNInstabug/InstabugReactBridge.m +++ b/ios/RNInstabug/InstabugReactBridge.m @@ -456,4 +456,8 @@ + (BOOL)iOSVersionIsLessThan:(NSString *)iOSVersion { [Instabug setAutoMaskScreenshots: autoMaskingOptions]; }; + +RCT_EXPORT_METHOD(getNetworkBodyMaxSize:(RCTPromiseResolveBlock)resolve :(RCTPromiseRejectBlock)reject) { + resolve(@(IBGNetworkLogger.getNetworkBodyMaxSize)); +} @end diff --git a/ios/RNInstabug/Util/IBGNetworkLogger+CP.h b/ios/RNInstabug/Util/IBGNetworkLogger+CP.h index a1e208e88..29cb8f62e 100644 --- a/ios/RNInstabug/Util/IBGNetworkLogger+CP.h +++ b/ios/RNInstabug/Util/IBGNetworkLogger+CP.h @@ -54,6 +54,14 @@ NS_ASSUME_NONNULL_BEGIN generatedW3CTraceparent:(NSString * _Nullable)generatedW3CTraceparent caughtedW3CTraceparent:(NSString * _Nullable)caughtedW3CTraceparent; ++ (void)forceStartNetworkLogging; ++ (void)forceStopNetworkLogging; + ++ (void)setCPRequestAsyncObfuscationHandler:(void (^)(NSURLRequest * requestToBeObfuscated, void (^ completion)(NSURLRequest * obfuscatedRequest)))asyncObfuscationHandler; ++ (void)setCPRequestFilteringHandler:(void (^)(NSURLRequest * request, void (^completion)(BOOL keep)))requestFilteringHandler; ++ (void)setCPResponseFilteringHandler:(void (^)(NSURLResponse * response, void (^comppletion)(BOOL keep)))responseFilteringHandler; ++ (double)getNetworkBodyMaxSize; + @end NS_ASSUME_NONNULL_END From 2ed2182aecbbe27e3d2c66e52301efae1653d09c Mon Sep 17 00:00:00 2001 From: kholood Date: Tue, 27 May 2025 12:39:05 +0300 Subject: [PATCH 3/9] feat:add getNetworkBodyMaxSize API --- src/modules/NetworkLogger.ts | 28 ++++++++++--- src/native/NativeInstabug.ts | 1 + src/utils/FeatureFlags.ts | 1 + src/utils/InstabugConstants.ts | 4 +- test/mocks/mockInstabug.ts | 1 + test/modules/NetworkLogger.spec.ts | 67 +++++++++++++++++------------- 6 files changed, 66 insertions(+), 36 deletions(-) diff --git a/src/modules/NetworkLogger.ts b/src/modules/NetworkLogger.ts index 4e6b6d379..1cc20aed6 100644 --- a/src/modules/NetworkLogger.ts +++ b/src/modules/NetworkLogger.ts @@ -29,7 +29,9 @@ export const setEnabled = (isEnabled: boolean) => { xhr.setOnDoneCallback(async (network) => { // eslint-disable-next-line no-new-func const predicate = Function('network', 'return ' + _requestFilterExpression); + if (!predicate(network)) { + const MAX_NETWORK_BODY_SIZE_IN_BYTES = await NativeInstabug.getNetworkBodyMaxSize(); try { if (_networkDataObfuscationHandler) { network = await _networkDataObfuscationHandler(network); @@ -41,14 +43,28 @@ export const setEnabled = (isEnabled: boolean) => { return; } } - if (network.requestBodySize > InstabugConstants.MAX_NETWORK_BODY_SIZE_IN_BYTES) { - network.requestBody = InstabugConstants.MAX_REQUEST_BODY_SIZE_EXCEEDED_MESSAGE; - Logger.warn('IBG-RN:', InstabugConstants.MAX_REQUEST_BODY_SIZE_EXCEEDED_MESSAGE); + if (network.requestBodySize > MAX_NETWORK_BODY_SIZE_IN_BYTES) { + network.requestBody = `${InstabugConstants.MAX_REQUEST_BODY_SIZE_EXCEEDED_MESSAGE}${ + MAX_NETWORK_BODY_SIZE_IN_BYTES / 1024 + } Kb`; + Logger.warn( + 'IBG-RN:', + `${InstabugConstants.MAX_REQUEST_BODY_SIZE_EXCEEDED_MESSAGE}${ + MAX_NETWORK_BODY_SIZE_IN_BYTES / 1024 + } Kb`, + ); } - if (network.responseBodySize > InstabugConstants.MAX_NETWORK_BODY_SIZE_IN_BYTES) { - network.responseBody = InstabugConstants.MAX_RESPONSE_BODY_SIZE_EXCEEDED_MESSAGE; - Logger.warn('IBG-RN:', InstabugConstants.MAX_RESPONSE_BODY_SIZE_EXCEEDED_MESSAGE); + if (network.responseBodySize > MAX_NETWORK_BODY_SIZE_IN_BYTES) { + network.responseBody = `${InstabugConstants.MAX_RESPONSE_BODY_SIZE_EXCEEDED_MESSAGE}${ + MAX_NETWORK_BODY_SIZE_IN_BYTES / 1024 + } Kb`; + Logger.warn( + 'IBG-RN:', + `${InstabugConstants.MAX_RESPONSE_BODY_SIZE_EXCEEDED_MESSAGE}${ + MAX_NETWORK_BODY_SIZE_IN_BYTES / 1024 + } Kb`, + ); } if (network.requestBody && isContentTypeNotAllowed(network.requestContentType)) { diff --git a/src/native/NativeInstabug.ts b/src/native/NativeInstabug.ts index 6b915e7f9..95c955959 100644 --- a/src/native/NativeInstabug.ts +++ b/src/native/NativeInstabug.ts @@ -155,6 +155,7 @@ export interface InstabugNativeModule extends NativeModule { // W3C Feature Flags Listener for Android registerW3CFlagsChangeListener(): void; enableAutoMasking(autoMaskingTypes: AutoMaskingType[]): void; + getNetworkBodyMaxSize(): Promise; } export const NativeInstabug = NativeModules.Instabug; diff --git a/src/utils/FeatureFlags.ts b/src/utils/FeatureFlags.ts index 479ab7ba4..950d12ac8 100644 --- a/src/utils/FeatureFlags.ts +++ b/src/utils/FeatureFlags.ts @@ -5,6 +5,7 @@ export const FeatureFlags = { isW3ExternalTraceID: () => NativeInstabug.isW3ExternalTraceIDEnabled(), isW3ExternalGeneratedHeader: () => NativeInstabug.isW3ExternalGeneratedHeaderEnabled(), isW3CaughtHeader: () => NativeInstabug.isW3CaughtHeaderEnabled(), + networkLogLimit: () => NativeInstabug.getNetworkBodyMaxSize(), }; export const registerW3CFlagsListener = () => { diff --git a/src/utils/InstabugConstants.ts b/src/utils/InstabugConstants.ts index aedc84070..bda90592b 100644 --- a/src/utils/InstabugConstants.ts +++ b/src/utils/InstabugConstants.ts @@ -4,9 +4,9 @@ const InstabugConstants = { // TODO: dyanmically get the max size from the native SDK and update the error message to reflect the dynamic size. MAX_NETWORK_BODY_SIZE_IN_BYTES: 1024 * 10, // 10 KB MAX_RESPONSE_BODY_SIZE_EXCEEDED_MESSAGE: - 'The response body has not been logged because it exceeds the maximum size of 10 Kb', + 'The response body has not been logged because it exceeds the maximum size of ', MAX_REQUEST_BODY_SIZE_EXCEEDED_MESSAGE: - 'The request body has not been logged because it exceeds the maximum size of 10 Kb', + 'The request body has not been logged because it exceeds the maximum size of ', SET_USER_ATTRIBUTES_ERROR_TYPE_MESSAGE: 'IBG-RN: Expected key and value passed to setUserAttribute to be of type string', REMOVE_USER_ATTRIBUTES_ERROR_TYPE_MESSAGE: diff --git a/test/mocks/mockInstabug.ts b/test/mocks/mockInstabug.ts index 04203a307..cc7d47bf9 100644 --- a/test/mocks/mockInstabug.ts +++ b/test/mocks/mockInstabug.ts @@ -75,6 +75,7 @@ const mockInstabug: InstabugNativeModule = { registerW3CFlagsChangeListener: jest.fn(), setNetworkLogBodyEnabled: jest.fn(), enableAutoMasking: jest.fn(), + getNetworkBodyMaxSize: jest.fn().mockResolvedValue(10240), // 10 KB }; export default mockInstabug; diff --git a/test/modules/NetworkLogger.spec.ts b/test/modules/NetworkLogger.spec.ts index d46b10aff..5888b477e 100644 --- a/test/modules/NetworkLogger.spec.ts +++ b/test/modules/NetworkLogger.spec.ts @@ -65,22 +65,23 @@ describe('NetworkLogger Module', () => { expect(Interceptor.disableInterception).toBeCalledTimes(1); }); - it('should report the network log', () => { + it('should report the network log', async () => { Interceptor.setOnDoneCallback = jest .fn() - .mockImplementation((callback) => callback(clone(network))); + .mockImplementation(async (callback) => await callback(clone(network))); - NetworkLogger.setEnabled(true); + await NetworkLogger.setEnabled(true); expect(reportNetworkLog).toBeCalledTimes(1); expect(reportNetworkLog).toBeCalledWith(network); + expect(NativeInstabug.getNetworkBodyMaxSize).toBeCalledTimes(1); }); it('should send log network when setNetworkDataObfuscationHandler is set', async () => { const randomString = '28930q938jqhd'; Interceptor.setOnDoneCallback = jest .fn() - .mockImplementation((callback) => callback(clone(network))); + .mockImplementation(async (callback) => await callback(clone(network))); NetworkLogger.setNetworkDataObfuscationHandler((networkData) => { networkData.requestHeaders.token = randomString; return Promise.resolve(networkData); @@ -156,7 +157,7 @@ describe('NetworkLogger Module', () => { consoleSpy.mockRestore(); }); - it('should omit request body if its content type is not allowed', () => { + it('should omit request body if its content type is not allowed', async () => { const consoleWarn = jest.spyOn(Logger, 'warn').mockImplementation(); jest.mocked(isContentTypeNotAllowed).mockReturnValueOnce(true); @@ -167,9 +168,9 @@ describe('NetworkLogger Module', () => { Interceptor.setOnDoneCallback = jest .fn() - .mockImplementation((callback) => callback(networkData)); + .mockImplementation(async (callback) => await callback(networkData)); - NetworkLogger.setEnabled(true); + await NetworkLogger.setEnabled(true); expect(reportNetworkLog).toHaveBeenCalledWith({ ...networkData, @@ -181,7 +182,7 @@ describe('NetworkLogger Module', () => { consoleWarn.mockRestore(); }); - it('should omit response body if its content type is not allowed', () => { + it('should omit response body if its content type is not allowed', async () => { const consoleWarn = jest.spyOn(Logger, 'warn').mockImplementation(); jest.mocked(isContentTypeNotAllowed).mockReturnValueOnce(true); @@ -192,9 +193,9 @@ describe('NetworkLogger Module', () => { Interceptor.setOnDoneCallback = jest .fn() - .mockImplementation((callback) => callback(networkData)); + .mockImplementation(async (callback) => await callback(networkData)); - NetworkLogger.setEnabled(true); + await NetworkLogger.setEnabled(true); expect(reportNetworkLog).toHaveBeenCalledWith({ ...networkData, @@ -206,23 +207,26 @@ describe('NetworkLogger Module', () => { consoleWarn.mockRestore(); }); - it('should omit request body if its size exceeds the maximum allowed size', () => { + it('should omit request body if its size exceeds the maximum allowed size', async () => { const consoleWarn = jest.spyOn(Logger, 'warn').mockImplementation(); + const MAX_NETWORK_BODY_SIZE_IN_BYTES = await NativeInstabug.getNetworkBodyMaxSize(); const networkData = { ...network, - requestBodySize: InstabugConstants.MAX_NETWORK_BODY_SIZE_IN_BYTES + 1, + requestBodySize: MAX_NETWORK_BODY_SIZE_IN_BYTES + 1, }; Interceptor.setOnDoneCallback = jest .fn() - .mockImplementation((callback) => callback(networkData)); + .mockImplementation(async (callback) => await callback(networkData)); - NetworkLogger.setEnabled(true); + await NetworkLogger.setEnabled(true); expect(reportNetworkLog).toHaveBeenCalledWith({ ...networkData, - requestBody: InstabugConstants.MAX_REQUEST_BODY_SIZE_EXCEEDED_MESSAGE, + requestBody: `${InstabugConstants.MAX_REQUEST_BODY_SIZE_EXCEEDED_MESSAGE}${ + MAX_NETWORK_BODY_SIZE_IN_BYTES / 1024 + } Kb`, }); expect(consoleWarn).toBeCalledTimes(1); @@ -230,38 +234,43 @@ describe('NetworkLogger Module', () => { consoleWarn.mockRestore(); }); - it('should not omit request body if its size does not exceed the maximum allowed size', () => { + it('should not omit request body if its size does not exceed the maximum allowed size', async () => { + const MAX_NETWORK_BODY_SIZE_IN_BYTES = await NativeInstabug.getNetworkBodyMaxSize(); + const networkData = { ...network, - requestBodySize: InstabugConstants.MAX_NETWORK_BODY_SIZE_IN_BYTES, + requestBodySize: MAX_NETWORK_BODY_SIZE_IN_BYTES, }; Interceptor.setOnDoneCallback = jest .fn() - .mockImplementation((callback) => callback(networkData)); + .mockImplementation(async (callback) => await callback(networkData)); - NetworkLogger.setEnabled(true); + await NetworkLogger.setEnabled(true); expect(reportNetworkLog).toHaveBeenCalledWith(networkData); }); - it('should omit response body if its size exceeds the maximum allowed size', () => { + it('should omit response body if its size exceeds the maximum allowed size', async () => { const consoleWarn = jest.spyOn(Logger, 'warn').mockImplementation(); + const MAX_NETWORK_BODY_SIZE_IN_BYTES = await NativeInstabug.getNetworkBodyMaxSize(); const networkData = { ...network, - responseBodySize: InstabugConstants.MAX_NETWORK_BODY_SIZE_IN_BYTES + 1, + responseBodySize: MAX_NETWORK_BODY_SIZE_IN_BYTES + 1, }; Interceptor.setOnDoneCallback = jest .fn() - .mockImplementation((callback) => callback(networkData)); + .mockImplementation(async (callback) => await callback(networkData)); - NetworkLogger.setEnabled(true); + await NetworkLogger.setEnabled(true); expect(reportNetworkLog).toHaveBeenCalledWith({ ...networkData, - responseBody: InstabugConstants.MAX_RESPONSE_BODY_SIZE_EXCEEDED_MESSAGE, + responseBody: `${InstabugConstants.MAX_RESPONSE_BODY_SIZE_EXCEEDED_MESSAGE}${ + MAX_NETWORK_BODY_SIZE_IN_BYTES / 1024 + } Kb`, }); expect(consoleWarn).toBeCalledTimes(1); @@ -269,17 +278,19 @@ describe('NetworkLogger Module', () => { consoleWarn.mockRestore(); }); - it('should not omit response body if its size does not exceed the maximum allowed size', () => { + it('should not omit response body if its size does not exceed the maximum allowed size', async () => { + const MAX_NETWORK_BODY_SIZE_IN_BYTES = await NativeInstabug.getNetworkBodyMaxSize(); + const networkData = { ...network, - responseBodySize: InstabugConstants.MAX_NETWORK_BODY_SIZE_IN_BYTES, + responseBodySize: MAX_NETWORK_BODY_SIZE_IN_BYTES, }; Interceptor.setOnDoneCallback = jest .fn() - .mockImplementation((callback) => callback(networkData)); + .mockImplementation(async (callback) => await callback(networkData)); - NetworkLogger.setEnabled(true); + await NetworkLogger.setEnabled(true); expect(reportNetworkLog).toHaveBeenCalledWith(networkData); }); From e59c7eff39b1b9909e0a463175b6a818222ab5d9 Mon Sep 17 00:00:00 2001 From: kholood Date: Tue, 27 May 2025 12:40:22 +0300 Subject: [PATCH 4/9] chore(android): add respect network body limit snapshot --- android/native.gradle | 2 +- examples/default/android/build.gradle | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/android/native.gradle b/android/native.gradle index 7177b8c27..b7790876e 100644 --- a/android/native.gradle +++ b/android/native.gradle @@ -1,5 +1,5 @@ project.ext.instabug = [ - version: '14.3.0.6752106-SNAPSHOT' + version: '14.3.0.6760192-SNAPSHOT' ] dependencies { diff --git a/examples/default/android/build.gradle b/examples/default/android/build.gradle index 72cc6f93b..52c0ddd02 100644 --- a/examples/default/android/build.gradle +++ b/examples/default/android/build.gradle @@ -17,6 +17,7 @@ buildscript { classpath("com.android.tools.build:gradle:8.1.0") classpath("com.facebook.react:react-native-gradle-plugin") classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion") + classpath("com.instabug.library:instabug-plugin:14.3.0.6760192-SNAPSHOT") } } From a15f210f2b0819df53fc407363d4cf25c19fbc3b Mon Sep 17 00:00:00 2001 From: kholood Date: Tue, 27 May 2025 12:43:11 +0300 Subject: [PATCH 5/9] chore(ios): sync pdfile.lock --- examples/default/ios/Podfile.lock | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/default/ios/Podfile.lock b/examples/default/ios/Podfile.lock index 55b2b299a..f6ad6e423 100644 --- a/examples/default/ios/Podfile.lock +++ b/examples/default/ios/Podfile.lock @@ -31,7 +31,7 @@ PODS: - hermes-engine (0.75.4): - hermes-engine/Pre-built (= 0.75.4) - hermes-engine/Pre-built (0.75.4) - - Instabug (15.0.0) + - Instabug (15.0.1) - instabug-reactnative-ndk (0.1.0): - DoubleConversion - glog @@ -1626,7 +1626,7 @@ PODS: - ReactCommon/turbomodule/core - Yoga - RNInstabug (14.3.0): - - Instabug (= 15.0.0) + - Instabug - React-Core - RNReanimated (3.16.1): - DoubleConversion @@ -1770,7 +1770,7 @@ DEPENDENCIES: - fmt (from `../node_modules/react-native/third-party-podspecs/fmt.podspec`) - glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`) - hermes-engine (from `../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec`) - - Instabug (from `https://ios-releases.instabug.com/custom/fix-main-thread-warning/15.0.0/Instabug.podspec`) + - Instabug (from `https://ios-releases.instabug.com/custom/feature-expose_network_limit-expose_body_limit/15.0.1/Instabug.podspec`) - instabug-reactnative-ndk (from `../node_modules/instabug-reactnative-ndk`) - OCMock - RCT-Folly (from `../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`) @@ -1869,7 +1869,7 @@ EXTERNAL SOURCES: :podspec: "../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec" :tag: hermes-2024-08-15-RNv0.75.1-4b3bf912cc0f705b51b71ce1a5b8bd79b93a451b Instabug: - :podspec: https://ios-releases.instabug.com/custom/fix-main-thread-warning/15.0.0/Instabug.podspec + :podspec: https://ios-releases.instabug.com/custom/feature-expose_network_limit-expose_body_limit/15.0.1/Instabug.podspec instabug-reactnative-ndk: :path: "../node_modules/instabug-reactnative-ndk" RCT-Folly: @@ -2024,7 +2024,7 @@ SPEC CHECKSUMS: Google-Maps-iOS-Utils: f77eab4c4326d7e6a277f8e23a0232402731913a GoogleMaps: 032f676450ba0779bd8ce16840690915f84e57ac hermes-engine: ea92f60f37dba025e293cbe4b4a548fd26b610a0 - Instabug: 3b1db5a683e85ec5a02946aa2b3314036f9022be + Instabug: ba6587d15ad5e3ffa265afc8174ff83af4eed29d instabug-reactnative-ndk: d765ac289d56e8896398d02760d9abf2562fc641 OCMock: 589f2c84dacb1f5aaf6e4cec1f292551fe748e74 RCT-Folly: 4464f4d875961fce86008d45f4ecf6cef6de0740 From 5a858dd182818373861c3112b669c418f8c929ce Mon Sep 17 00:00:00 2001 From: kholood Date: Tue, 27 May 2025 13:26:17 +0300 Subject: [PATCH 6/9] Revert "Merge pull request #1388 from Instabug/refactor/replace-reflection" This reverts commit 256e72abd36e1315bd4d5053ec4be379367e489d, reversing changes made to 196b481b53051e02dabb060d7acba39d122bb063. --- android/native.gradle | 2 +- .../networking/ApmNetworkLoggerHelper.java | 89 ------- .../reactlibrary/RNInstabugAPMModule.java | 230 +++++++++++------- 3 files changed, 143 insertions(+), 178 deletions(-) delete mode 100644 android/src/main/java/com/instabug/apm/networking/ApmNetworkLoggerHelper.java diff --git a/android/native.gradle b/android/native.gradle index 7177b8c27..3241dc5f2 100644 --- a/android/native.gradle +++ b/android/native.gradle @@ -1,5 +1,5 @@ project.ext.instabug = [ - version: '14.3.0.6752106-SNAPSHOT' + version: '14.3.0' ] dependencies { diff --git a/android/src/main/java/com/instabug/apm/networking/ApmNetworkLoggerHelper.java b/android/src/main/java/com/instabug/apm/networking/ApmNetworkLoggerHelper.java deleted file mode 100644 index 73befdad1..000000000 --- a/android/src/main/java/com/instabug/apm/networking/ApmNetworkLoggerHelper.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.instabug.apm.networking; - -import androidx.annotation.Nullable; - -import com.facebook.react.bridge.ReadableMap; -import com.instabug.apm.networking.mapping.NetworkRequestAttributes; -import com.instabug.apm.networkinterception.cp.APMCPNetworkLog; - -public class ApmNetworkLoggerHelper { - - /// Log network request to the Android SDK using a package private API [APMNetworkLogger.log] - static public void log(final double requestStartTime, - final double requestDuration, - final String requestHeaders, - final String requestBody, - final double requestBodySize, - final String requestMethod, - final String requestUrl, - final String requestContentType, - final String responseHeaders, - final String responseBody, - final double responseBodySize, - final double statusCode, - final String responseContentType, - @Nullable final String errorDomain, - @Nullable final ReadableMap w3cAttributes, - @Nullable final String gqlQueryName, - @Nullable final String serverErrorMessage - ) { - try { - final APMNetworkLogger apmNetworkLogger = new APMNetworkLogger(); - final boolean hasError = errorDomain != null && !errorDomain.isEmpty(); - final String errorMessage = hasError ? errorDomain : null; - boolean isW3cHeaderFound = false; - Long partialId = null; - Long networkStartTimeInSeconds = null; - - - try { - if (!w3cAttributes.isNull("isW3cHeaderFound")) { - isW3cHeaderFound = w3cAttributes.getBoolean("isW3cHeaderFound"); - } - - if (!w3cAttributes.isNull("partialId")) { - partialId = (long) w3cAttributes.getDouble("partialId"); - networkStartTimeInSeconds = (long) w3cAttributes.getDouble("networkStartTimeInSeconds"); - } - - } catch (Exception e) { - e.printStackTrace(); - } - APMCPNetworkLog.W3CExternalTraceAttributes w3cExternalTraceAttributes = - new APMCPNetworkLog.W3CExternalTraceAttributes( - isW3cHeaderFound, - partialId, - networkStartTimeInSeconds, - w3cAttributes.getString("w3cGeneratedHeader"), - w3cAttributes.getString("w3cCaughtHeader") - ); - NetworkRequestAttributes requestAttributes = new NetworkRequestAttributes( - (long) requestStartTime * 1000, - (long) requestDuration, - requestHeaders, - requestBody, - (long) requestBodySize, - requestMethod, - requestUrl, - requestContentType, - responseHeaders, - responseBody, - (long) responseBodySize, - (int) statusCode, - responseContentType, - gqlQueryName, - errorMessage, - serverErrorMessage - ); - - apmNetworkLogger.log( - requestAttributes, - w3cExternalTraceAttributes - ); - } catch (Throwable e) { - e.printStackTrace(); - } - - } - -} diff --git a/android/src/main/java/com/instabug/reactlibrary/RNInstabugAPMModule.java b/android/src/main/java/com/instabug/reactlibrary/RNInstabugAPMModule.java index f68f212b1..d75b4f75b 100644 --- a/android/src/main/java/com/instabug/reactlibrary/RNInstabugAPMModule.java +++ b/android/src/main/java/com/instabug/reactlibrary/RNInstabugAPMModule.java @@ -2,6 +2,7 @@ package com.instabug.reactlibrary; import android.os.SystemClock; +import android.util.Log; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -12,14 +13,20 @@ import com.facebook.react.bridge.ReadableMap; import com.instabug.apm.APM; import com.instabug.apm.model.ExecutionTrace; -import com.instabug.apm.networking.ApmNetworkLoggerHelper; +import com.instabug.apm.networking.APMNetworkLogger; +import com.instabug.apm.networkinterception.cp.APMCPNetworkLog; import com.instabug.reactlibrary.utils.EventEmitterModule; +import com.instabug.apm.networkinterception.cp.APMCPNetworkLog; import com.instabug.reactlibrary.utils.MainThreadHandler; +import java.lang.reflect.Method; + import java.util.HashMap; import javax.annotation.Nonnull; +import static com.instabug.reactlibrary.utils.InstabugUtil.getMethod; + public class RNInstabugAPMModule extends EventEmitterModule { public RNInstabugAPMModule(ReactApplicationContext reactApplicationContext) { @@ -204,6 +211,7 @@ public void run() { * Starts an execution trace * * @param name string name of the trace. + * * @deprecated see {@link #startFlow(String)} */ @Deprecated @@ -234,6 +242,7 @@ public void run() { * @param id String id of the trace. * @param key attribute key * @param value attribute value. Null to remove attribute + * * @deprecated see {@link #setFlowAttribute} */ @Deprecated @@ -255,6 +264,7 @@ public void run() { * Ends a trace * * @param id string id of the trace. + * * @deprecated see {@link #endFlow} */ @Deprecated @@ -308,73 +318,73 @@ public void run() { }); } - /** - * The `networkLogAndroid` function logs network-related information using APMNetworkLogger in a React - * Native module. - * - * @param requestStartTime The `requestStartTime` parameter in the `networkLogAndroid` method - * represents the timestamp when the network request started. It is of type `double` and is passed as - * a parameter to log network-related information. - * @param requestDuration The `requestDuration` parameter in the `networkLogAndroid` method represents - * the duration of the network request in milliseconds. It indicates the time taken for the request to - * complete from the moment it was initiated until the response was received. This parameter helps in - * measuring the performance of network requests and identifying any potential - * @param requestHeaders requestHeaders is a string parameter that contains the headers of the network - * request. It typically includes information such as the content type, authorization token, and any - * other headers that were sent with the request. - * @param requestBody The `requestBody` parameter in the `networkLogAndroid` method represents the - * body of the HTTP request being logged. It contains the data that is sent as part of the request to - * the server. This could include form data, JSON payload, XML data, or any other content that is - * being transmitted - * @param requestBodySize The `requestBodySize` parameter in the `networkLogAndroid` method represents - * the size of the request body in bytes. It is a double value that indicates the size of the request - * body being sent in the network request. This parameter is used to log information related to the - * network request, including details - * @param requestMethod The `requestMethod` parameter in the `networkLogAndroid` method represents the - * HTTP method used in the network request, such as GET, POST, PUT, DELETE, etc. It indicates the type - * of operation that the client is requesting from the server. - * @param requestUrl The `requestUrl` parameter in the `networkLogAndroid` method represents the URL - * of the network request being logged. It typically contains the address of the server to which the - * request is being made, along with any additional path or query parameters required for the request. - * This URL is essential for identifying the - * @param requestContentType The `requestContentType` parameter in the `networkLogAndroid` method - * represents the content type of the request being made. This could be values like - * "application/json", "application/xml", "text/plain", etc., indicating the format of the data being - * sent in the request body. It helps in specifying - * @param responseHeaders The `responseHeaders` parameter in the `networkLogAndroid` method represents - * the headers of the response received from a network request. These headers typically include - * information such as content type, content length, server information, and any other metadata - * related to the response. The `responseHeaders` parameter is expected to - * @param responseBody The `responseBody` parameter in the `networkLogAndroid` method represents the - * body of the response received from a network request. It contains the data or content sent back by - * the server in response to the request made by the client. This could be in various formats such as - * JSON, XML, HTML - * @param responseBodySize The `responseBodySize` parameter in the `networkLogAndroid` method - * represents the size of the response body in bytes. It is a double value that indicates the size of - * the response body received from the network request. This parameter is used to log information - * related to the network request and response, including - * @param statusCode The `statusCode` parameter in the `networkLogAndroid` method represents the HTTP - * status code of the network request/response. It indicates the status of the HTTP response, such as - * success (200), redirection (3xx), client errors (4xx), or server errors (5xx). This parameter is - * @param responseContentType The `responseContentType` parameter in the `networkLogAndroid` method - * represents the content type of the response received from the network request. It indicates the - * format of the data in the response, such as JSON, XML, HTML, etc. This information is useful for - * understanding how to parse and handle the - * @param errorDomain The `errorDomain` parameter in the `networkLogAndroid` method is used to specify - * the domain of an error, if any occurred during the network request. If there was no error, this - * parameter will be `null`. - * @param w3cAttributes The `w3cAttributes` parameter in the `networkLogAndroid` method is a - * ReadableMap object that contains additional attributes related to W3C external trace. It may - * include the following key-value pairs: - * @param gqlQueryName The `gqlQueryName` parameter in the `networkLogAndroid` method represents the - * name of the GraphQL query being executed. It is a nullable parameter, meaning it can be null if no - * GraphQL query name is provided. This parameter is used to log information related to GraphQL - * queries in the network logging - * @param serverErrorMessage The `serverErrorMessage` parameter in the `networkLogAndroid` method is - * used to pass any error message received from the server during network communication. This message - * can provide additional details about any errors that occurred on the server side, helping in - * debugging and troubleshooting network-related issues. - */ + /** + * The `networkLogAndroid` function logs network-related information using APMNetworkLogger in a React + * Native module. + * + * @param requestStartTime The `requestStartTime` parameter in the `networkLogAndroid` method + * represents the timestamp when the network request started. It is of type `double` and is passed as + * a parameter to log network-related information. + * @param requestDuration The `requestDuration` parameter in the `networkLogAndroid` method represents + * the duration of the network request in milliseconds. It indicates the time taken for the request to + * complete from the moment it was initiated until the response was received. This parameter helps in + * measuring the performance of network requests and identifying any potential + * @param requestHeaders requestHeaders is a string parameter that contains the headers of the network + * request. It typically includes information such as the content type, authorization token, and any + * other headers that were sent with the request. + * @param requestBody The `requestBody` parameter in the `networkLogAndroid` method represents the + * body of the HTTP request being logged. It contains the data that is sent as part of the request to + * the server. This could include form data, JSON payload, XML data, or any other content that is + * being transmitted + * @param requestBodySize The `requestBodySize` parameter in the `networkLogAndroid` method represents + * the size of the request body in bytes. It is a double value that indicates the size of the request + * body being sent in the network request. This parameter is used to log information related to the + * network request, including details + * @param requestMethod The `requestMethod` parameter in the `networkLogAndroid` method represents the + * HTTP method used in the network request, such as GET, POST, PUT, DELETE, etc. It indicates the type + * of operation that the client is requesting from the server. + * @param requestUrl The `requestUrl` parameter in the `networkLogAndroid` method represents the URL + * of the network request being logged. It typically contains the address of the server to which the + * request is being made, along with any additional path or query parameters required for the request. + * This URL is essential for identifying the + * @param requestContentType The `requestContentType` parameter in the `networkLogAndroid` method + * represents the content type of the request being made. This could be values like + * "application/json", "application/xml", "text/plain", etc., indicating the format of the data being + * sent in the request body. It helps in specifying + * @param responseHeaders The `responseHeaders` parameter in the `networkLogAndroid` method represents + * the headers of the response received from a network request. These headers typically include + * information such as content type, content length, server information, and any other metadata + * related to the response. The `responseHeaders` parameter is expected to + * @param responseBody The `responseBody` parameter in the `networkLogAndroid` method represents the + * body of the response received from a network request. It contains the data or content sent back by + * the server in response to the request made by the client. This could be in various formats such as + * JSON, XML, HTML + * @param responseBodySize The `responseBodySize` parameter in the `networkLogAndroid` method + * represents the size of the response body in bytes. It is a double value that indicates the size of + * the response body received from the network request. This parameter is used to log information + * related to the network request and response, including + * @param statusCode The `statusCode` parameter in the `networkLogAndroid` method represents the HTTP + * status code of the network request/response. It indicates the status of the HTTP response, such as + * success (200), redirection (3xx), client errors (4xx), or server errors (5xx). This parameter is + * @param responseContentType The `responseContentType` parameter in the `networkLogAndroid` method + * represents the content type of the response received from the network request. It indicates the + * format of the data in the response, such as JSON, XML, HTML, etc. This information is useful for + * understanding how to parse and handle the + * @param errorDomain The `errorDomain` parameter in the `networkLogAndroid` method is used to specify + * the domain of an error, if any occurred during the network request. If there was no error, this + * parameter will be `null`. + * @param w3cAttributes The `w3cAttributes` parameter in the `networkLogAndroid` method is a + * ReadableMap object that contains additional attributes related to W3C external trace. It may + * include the following key-value pairs: + * @param gqlQueryName The `gqlQueryName` parameter in the `networkLogAndroid` method represents the + * name of the GraphQL query being executed. It is a nullable parameter, meaning it can be null if no + * GraphQL query name is provided. This parameter is used to log information related to GraphQL + * queries in the network logging + * @param serverErrorMessage The `serverErrorMessage` parameter in the `networkLogAndroid` method is + * used to pass any error message received from the server during network communication. This message + * can provide additional details about any errors that occurred on the server side, helping in + * debugging and troubleshooting network-related issues. + */ @ReactMethod private void networkLogAndroid(final double requestStartTime, final double requestDuration, @@ -393,25 +403,69 @@ private void networkLogAndroid(final double requestStartTime, @Nullable final ReadableMap w3cAttributes, @Nullable final String gqlQueryName, @Nullable final String serverErrorMessage - ) { - ApmNetworkLoggerHelper.log( - requestStartTime, - requestDuration, - requestHeaders, - requestBody, - requestBodySize, - requestMethod, - requestUrl, - requestContentType, - responseHeaders, - responseBody, - responseBodySize, - statusCode, - responseContentType, - errorDomain, - w3cAttributes, - gqlQueryName, - serverErrorMessage - ); + ) { + try { + APMNetworkLogger networkLogger = new APMNetworkLogger(); + + final boolean hasError = errorDomain != null && !errorDomain.isEmpty(); + final String errorMessage = hasError ? errorDomain : null; + Boolean isW3cHeaderFound=false; + Long partialId=null; + Long networkStartTimeInSeconds=null; + + + try { + if (!w3cAttributes.isNull("isW3cHeaderFound")) { + isW3cHeaderFound = w3cAttributes.getBoolean("isW3cHeaderFound"); + } + + if (!w3cAttributes.isNull("partialId")) { + partialId =(long) w3cAttributes.getDouble("partialId"); + networkStartTimeInSeconds = (long) w3cAttributes.getDouble("networkStartTimeInSeconds"); + } + + } catch (Exception e) { + e.printStackTrace(); + } + APMCPNetworkLog.W3CExternalTraceAttributes w3cExternalTraceAttributes = + new APMCPNetworkLog.W3CExternalTraceAttributes( + isW3cHeaderFound, + partialId, + networkStartTimeInSeconds, + w3cAttributes.getString("w3cGeneratedHeader"), + w3cAttributes.getString("w3cCaughtHeader") + ); + try { + Method method = getMethod(Class.forName("com.instabug.apm.networking.APMNetworkLogger"), "log", long.class, long.class, String.class, String.class, long.class, String.class, String.class, String.class, String.class, String.class, long.class, int.class, String.class, String.class, String.class, String.class, APMCPNetworkLog.W3CExternalTraceAttributes.class); + if (method != null) { + method.invoke( + networkLogger, + (long) requestStartTime * 1000, + (long) requestDuration, + requestHeaders, + requestBody, + (long) requestBodySize, + requestMethod, + requestUrl, + requestContentType, + responseHeaders, + responseBody, + (long)responseBodySize, + (int) statusCode, + responseContentType, + errorMessage, + gqlQueryName, + serverErrorMessage, + w3cExternalTraceAttributes + ); + } else { + Log.e("IB-CP-Bridge", "APMNetworkLogger.log was not found by reflection"); + } + } catch (Throwable e) { + e.printStackTrace(); + } + } catch(Throwable e) { + e.printStackTrace(); + } } } From a19abb96ab344067de5f2e4fc93b1a8e6a3d90ef Mon Sep 17 00:00:00 2001 From: kholood Date: Tue, 27 May 2025 18:21:32 +0300 Subject: [PATCH 7/9] feat(android): add getNetworkBodyMaxSize API --- .../com/instabug/reactlibrary/Constants.java | 2 +- .../RNInstabugReactnativeModule.java | 28 ++++++++++++++++--- .../RNInstabugReactnativeModuleTest.java | 17 +++++++++-- 3 files changed, 40 insertions(+), 7 deletions(-) diff --git a/android/src/main/java/com/instabug/reactlibrary/Constants.java b/android/src/main/java/com/instabug/reactlibrary/Constants.java index 9f1a0cf35..f5b584700 100644 --- a/android/src/main/java/com/instabug/reactlibrary/Constants.java +++ b/android/src/main/java/com/instabug/reactlibrary/Constants.java @@ -13,7 +13,7 @@ final class Constants { final static String IBG_ON_FEATURES_UPDATED_CALLBACK = "IBGOnFeatureUpdatedCallback"; final static String IBG_NETWORK_LOGGER_HANDLER = "IBGNetworkLoggerHandler"; - final static String IBG_ON_NEW_W3C_FLAGS_UPDATE_RECEIVED_CALLBACK = "IBGOnNewW3CFlagsUpdateReceivedCallback"; + final static String IBG_ON_FEATURE_FLAGS_UPDATE_RECEIVED_CALLBACK = "IBGOnNewFeatureFlagsUpdateReceivedCallback"; final static String IBG_SESSION_REPLAY_ON_SYNC_CALLBACK_INVOCATION = "IBGSessionReplayOnSyncCallback"; diff --git a/android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java b/android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java index 991dc9725..17f48656f 100644 --- a/android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java +++ b/android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java @@ -1159,10 +1159,10 @@ public void run() { } /** - * Register a listener for W3C flags value change + * Register a listener for feature flags value change */ @ReactMethod - public void registerW3CFlagsChangeListener() { + public void registerFeatureFlagsChangeListener() { MainThreadHandler.runOnMainThread(new Runnable() { @Override @@ -1175,8 +1175,9 @@ public void invoke(@NonNull CoreFeaturesState featuresState) { params.putBoolean("isW3ExternalTraceIDEnabled", featuresState.isW3CExternalTraceIdEnabled()); params.putBoolean("isW3ExternalGeneratedHeaderEnabled", featuresState.isAttachingGeneratedHeaderEnabled()); params.putBoolean("isW3CaughtHeaderEnabled", featuresState.isAttachingCapturedHeaderEnabled()); + params.putInt("networkBodyLimit",featuresState.getNetworkLogCharLimit()); - sendEvent(Constants.IBG_ON_NEW_W3C_FLAGS_UPDATE_RECEIVED_CALLBACK, params); + sendEvent(Constants.IBG_ON_FEATURE_FLAGS_UPDATE_RECEIVED_CALLBACK, params); } }); } catch (Exception e) { @@ -1306,7 +1307,7 @@ public void run() { } }); } - /** + /** * Sets the auto mask screenshots types. * @@ -1331,4 +1332,23 @@ public void run() { }); } + + /** + * Get network body size limit + */ + @ReactMethod + public void getNetworkBodyMaxSize(Promise promise) { + + MainThreadHandler.runOnMainThread(new Runnable() { + @Override + public void run() { + try { + promise.resolve(InternalCore.INSTANCE.get_networkLogCharLimit()); + } catch (Exception e) { + e.printStackTrace(); + promise.resolve(false); + } + } + }); + } } diff --git a/android/src/test/java/com/instabug/reactlibrary/RNInstabugReactnativeModuleTest.java b/android/src/test/java/com/instabug/reactlibrary/RNInstabugReactnativeModuleTest.java index 3083410f3..f4f6f9bc1 100644 --- a/android/src/test/java/com/instabug/reactlibrary/RNInstabugReactnativeModuleTest.java +++ b/android/src/test/java/com/instabug/reactlibrary/RNInstabugReactnativeModuleTest.java @@ -686,9 +686,22 @@ public void testEnableAutoMasking(){ String maskTextInputs = "textInputs"; String maskMedia = "media"; String maskNone = "none"; - + rnModule.enableAutoMasking(JavaOnlyArray.of(maskLabel, maskMedia, maskTextInputs,maskNone)); - + mockInstabug.verify(() -> Instabug.setAutoMaskScreenshotsTypes(MaskingType.LABELS,MaskingType.MEDIA,MaskingType.TEXT_INPUTS,MaskingType.MASK_NOTHING)); } + + @Test + public void testGetNetworkBodyMaxSize_resolvesPromiseWithExpectedValue() { + Promise promise = mock(Promise.class); + InternalCore internalAPM = mock(InternalCore.class); + int expected = 10240; + when(internalAPM.get_networkLogCharLimit()).thenReturn(expected); + + rnModule.getNetworkBodyMaxSize(promise); + + verify(promise).resolve(expected); + } + } From fe52845681bec9abea21d0e7cf4b04f3eb491c3d Mon Sep 17 00:00:00 2001 From: kholood Date: Tue, 27 May 2025 18:22:24 +0300 Subject: [PATCH 8/9] feat:add feature flag change listener for android --- examples/default/src/App.tsx | 2 +- src/modules/Instabug.ts | 13 +++++++------ src/native/NativeInstabug.ts | 6 +++--- src/utils/FeatureFlags.ts | 10 +++++++--- test/mocks/mockInstabug.ts | 2 +- test/modules/Instabug.spec.ts | 10 +++++----- 6 files changed, 24 insertions(+), 19 deletions(-) diff --git a/examples/default/src/App.tsx b/examples/default/src/App.tsx index 122002857..ceef8bc19 100644 --- a/examples/default/src/App.tsx +++ b/examples/default/src/App.tsx @@ -50,7 +50,7 @@ export const App: React.FC = () => { token: 'deb1910a7342814af4e4c9210c786f35', invocationEvents: [InvocationEvent.floatingButton], debugLogsLevel: LogLevel.verbose, - networkInterceptionMode: NetworkInterceptionMode.native, + networkInterceptionMode: NetworkInterceptionMode.javascript, }); CrashReporting.setNDKCrashesEnabled(true); diff --git a/src/modules/Instabug.ts b/src/modules/Instabug.ts index 1bcd5bf8b..f7d582e70 100644 --- a/src/modules/Instabug.ts +++ b/src/modules/Instabug.ts @@ -16,7 +16,7 @@ import type { NavigationAction, NavigationState as NavigationStateV4 } from 'rea import type { InstabugConfig } from '../models/InstabugConfig'; import Report from '../models/Report'; import { emitter, NativeEvents, NativeInstabug } from '../native/NativeInstabug'; -import { registerW3CFlagsListener } from '../utils/FeatureFlags'; +import { registerFeatureFlagsListener } from '../utils/FeatureFlags'; import { AutoMaskingType, ColorTheme, @@ -87,7 +87,7 @@ function reportCurrentViewForAndroid(screenName: string | null) { export const init = async (config: InstabugConfig) => { if (Platform.OS === 'android') { // Add android feature flags listener for android - registerW3CFlagsListener(); + registerFeatureFlagsListener(); addOnFeatureUpdatedListener(config); } else { isNativeInterceptionFeatureEnabled = await NativeNetworkLogger.isNativeInterceptionEnabled(); @@ -871,20 +871,21 @@ export const componentDidAppearListener = (event: ComponentDidAppearEvent) => { }; /** - * Sets listener to W3ExternalTraceID flag changes + * Sets listener to feature flag changes * @param handler A callback that gets the update value of the flag */ -export const _registerW3CFlagsChangeListener = ( +export const _registerFeatureFlagsChangeListener = ( handler: (payload: { isW3ExternalTraceIDEnabled: boolean; isW3ExternalGeneratedHeaderEnabled: boolean; isW3CaughtHeaderEnabled: boolean; + networkBodyLimit: number; }) => void, ) => { - emitter.addListener(NativeEvents.ON_W3C_FLAGS_CHANGE, (payload) => { + emitter.addListener(NativeEvents.ON_FEATURE_FLAGS_CHANGE, (payload) => { handler(payload); }); - NativeInstabug.registerW3CFlagsChangeListener(); + NativeInstabug.registerFeatureFlagsChangeListener(); }; /** diff --git a/src/native/NativeInstabug.ts b/src/native/NativeInstabug.ts index 36dc55b75..7032bbc07 100644 --- a/src/native/NativeInstabug.ts +++ b/src/native/NativeInstabug.ts @@ -152,8 +152,8 @@ export interface InstabugNativeModule extends NativeModule { isW3CaughtHeaderEnabled(): Promise; - // W3C Feature Flags Listener for Android - registerW3CFlagsChangeListener(): void; + // Feature Flags Listener for Android + registerFeatureFlagsChangeListener(): void; setOnFeaturesUpdatedListener(handler?: (params: any) => void): void; // android only enableAutoMasking(autoMaskingTypes: AutoMaskingType[]): void; @@ -165,7 +165,7 @@ export const NativeInstabug = NativeModules.Instabug; export enum NativeEvents { PRESENDING_HANDLER = 'IBGpreSendingHandler', IBG_ON_FEATURES_UPDATED_CALLBACK = 'IBGOnFeatureUpdatedCallback', - ON_W3C_FLAGS_CHANGE = 'IBGOnNewW3CFlagsUpdateReceivedCallback', + ON_FEATURE_FLAGS_CHANGE = 'IBGOnNewFeatureFlagsUpdateReceivedCallback', } export const emitter = new NativeEventEmitter(NativeInstabug); diff --git a/src/utils/FeatureFlags.ts b/src/utils/FeatureFlags.ts index 950d12ac8..f9c644e99 100644 --- a/src/utils/FeatureFlags.ts +++ b/src/utils/FeatureFlags.ts @@ -1,5 +1,5 @@ import { NativeInstabug } from '../native/NativeInstabug'; -import { _registerW3CFlagsChangeListener } from '../modules/Instabug'; +import { _registerFeatureFlagsChangeListener } from '../modules/Instabug'; export const FeatureFlags = { isW3ExternalTraceID: () => NativeInstabug.isW3ExternalTraceIDEnabled(), @@ -8,12 +8,13 @@ export const FeatureFlags = { networkLogLimit: () => NativeInstabug.getNetworkBodyMaxSize(), }; -export const registerW3CFlagsListener = () => { - _registerW3CFlagsChangeListener( +export const registerFeatureFlagsListener = () => { + _registerFeatureFlagsChangeListener( (res: { isW3ExternalTraceIDEnabled: boolean; isW3ExternalGeneratedHeaderEnabled: boolean; isW3CaughtHeaderEnabled: boolean; + networkBodyLimit: number; }) => { FeatureFlags.isW3ExternalTraceID = async () => { return res.isW3ExternalTraceIDEnabled; @@ -24,6 +25,9 @@ export const registerW3CFlagsListener = () => { FeatureFlags.isW3CaughtHeader = async () => { return res.isW3CaughtHeaderEnabled; }; + FeatureFlags.networkLogLimit = async () => { + return res.networkBodyLimit; + }; }, ); }; diff --git a/test/mocks/mockInstabug.ts b/test/mocks/mockInstabug.ts index fb182520d..391a00a38 100644 --- a/test/mocks/mockInstabug.ts +++ b/test/mocks/mockInstabug.ts @@ -72,7 +72,7 @@ const mockInstabug: InstabugNativeModule = { isW3ExternalTraceIDEnabled: jest.fn(), isW3ExternalGeneratedHeaderEnabled: jest.fn(), isW3CaughtHeaderEnabled: jest.fn(), - registerW3CFlagsChangeListener: jest.fn(), + registerFeatureFlagsChangeListener: jest.fn(), setNetworkLogBodyEnabled: jest.fn(), setOnFeaturesUpdatedListener: jest.fn(), enableAutoMasking: jest.fn(), diff --git a/test/modules/Instabug.spec.ts b/test/modules/Instabug.spec.ts index 904cefb7d..753bf53c4 100644 --- a/test/modules/Instabug.spec.ts +++ b/test/modules/Instabug.spec.ts @@ -902,17 +902,17 @@ describe('Instabug Module', () => { it('should register W3C flag listener', async () => { const callback = jest.fn(); - Instabug._registerW3CFlagsChangeListener(callback); + Instabug._registerFeatureFlagsChangeListener(callback); - expect(NativeInstabug.registerW3CFlagsChangeListener).toBeCalledTimes(1); + expect(NativeInstabug.registerFeatureFlagsChangeListener).toBeCalledTimes(1); }); it('should invoke callback on emitting the event IBGOnNewW3CFlagsUpdateReceivedCallback', () => { const callback = jest.fn(); - Instabug._registerW3CFlagsChangeListener(callback); - emitter.emit(NativeEvents.ON_W3C_FLAGS_CHANGE); + Instabug._registerFeatureFlagsChangeListener(callback); + emitter.emit(NativeEvents.ON_FEATURE_FLAGS_CHANGE); - expect(emitter.listenerCount(NativeEvents.ON_W3C_FLAGS_CHANGE)).toBe(1); + expect(emitter.listenerCount(NativeEvents.ON_FEATURE_FLAGS_CHANGE)).toBe(1); expect(callback).toHaveBeenCalled(); }); From 2c883b6e05d535e0ef49c38a1a3485cc2920cd1b Mon Sep 17 00:00:00 2001 From: kholood Date: Tue, 27 May 2025 18:35:47 +0300 Subject: [PATCH 9/9] chore: fix sync_generated_files CI job --- examples/default/ios/Podfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/default/ios/Podfile.lock b/examples/default/ios/Podfile.lock index f22d0d2db..61884fc18 100644 --- a/examples/default/ios/Podfile.lock +++ b/examples/default/ios/Podfile.lock @@ -2100,6 +2100,6 @@ SPEC CHECKSUMS: SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d Yoga: 055f92ad73f8c8600a93f0e25ac0b2344c3b07e6 -PODFILE CHECKSUM: a1b532d67a1a86843e1f086101751ad55afa52da +PODFILE CHECKSUM: f7f8d2b03a0b566cb0f5b4b422469af0a1a278b1 COCOAPODS: 1.14.0