Skip to content

Commit 83c5b9e

Browse files
committed
feat: respect be network body limit (#1397)
* chore(ios): add respect BE network body limit custom build * feat(ios): add getNetworkBodyMaxSize API * feat:add getNetworkBodyMaxSize API * chore(android): add respect network body limit snapshot * chore(ios): sync pdfile.lock * Revert "Merge pull request #1388 from Instabug/refactor/replace-reflection" This reverts commit 256e72a, reversing changes made to 196b481. * feat(android): add getNetworkBodyMaxSize API * feat:add feature flag change listener for android * chore: fix sync_generated_files CI job * feat(ios): add getNetworkBodyMaxSize API * chore: add change log * Revert duplicate "feat(ios): add getNetworkBodyMaxSize API" This reverts commit ef8710e. * chore: edit a change log * chore: update test cases titles
1 parent acbeb9c commit 83c5b9e

File tree

17 files changed

+159
-64
lines changed

17 files changed

+159
-64
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
- Add support for network spans. ([#1394](https://github.com/Instabug/Instabug-React-Native/pull/1394))
1414

15+
- Add respect to backend network body limit. ([#1397](https://github.com/Instabug/Instabug-React-Native/pull/1397))
16+
1517
### Changed
1618

1719
- Bump Instabug iOS SDK to v15.1.1 ([#1402](https://github.com/Instabug/Instabug-React-Native/pull/1402)). [See release notes](https://github.com/Instabug/Instabug-iOS/releases/tag/15.1.1).

android/src/main/java/com/instabug/reactlibrary/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ final class Constants {
1313
final static String IBG_ON_FEATURES_UPDATED_CALLBACK = "IBGOnFeatureUpdatedCallback";
1414
final static String IBG_NETWORK_LOGGER_HANDLER = "IBGNetworkLoggerHandler";
1515

16-
final static String IBG_ON_NEW_W3C_FLAGS_UPDATE_RECEIVED_CALLBACK = "IBGOnNewW3CFlagsUpdateReceivedCallback";
16+
final static String IBG_ON_FEATURE_FLAGS_UPDATE_RECEIVED_CALLBACK = "IBGOnNewFeatureFlagsUpdateReceivedCallback";
1717

1818
final static String IBG_SESSION_REPLAY_ON_SYNC_CALLBACK_INVOCATION = "IBGSessionReplayOnSyncCallback";
1919

android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,10 +1159,10 @@ public void run() {
11591159
}
11601160

11611161
/**
1162-
* Register a listener for W3C flags value change
1162+
* Register a listener for feature flags value change
11631163
*/
11641164
@ReactMethod
1165-
public void registerW3CFlagsChangeListener() {
1165+
public void registerFeatureFlagsChangeListener() {
11661166

11671167
MainThreadHandler.runOnMainThread(new Runnable() {
11681168
@Override
@@ -1175,8 +1175,9 @@ public void invoke(@NonNull CoreFeaturesState featuresState) {
11751175
params.putBoolean("isW3ExternalTraceIDEnabled", featuresState.isW3CExternalTraceIdEnabled());
11761176
params.putBoolean("isW3ExternalGeneratedHeaderEnabled", featuresState.isAttachingGeneratedHeaderEnabled());
11771177
params.putBoolean("isW3CaughtHeaderEnabled", featuresState.isAttachingCapturedHeaderEnabled());
1178+
params.putInt("networkBodyLimit",featuresState.getNetworkLogCharLimit());
11781179

1179-
sendEvent(Constants.IBG_ON_NEW_W3C_FLAGS_UPDATE_RECEIVED_CALLBACK, params);
1180+
sendEvent(Constants.IBG_ON_FEATURE_FLAGS_UPDATE_RECEIVED_CALLBACK, params);
11801181
}
11811182
});
11821183
} catch (Exception e) {
@@ -1306,7 +1307,7 @@ public void run() {
13061307
}
13071308
});
13081309
}
1309-
/**
1310+
13101311
/**
13111312
* Sets the auto mask screenshots types.
13121313
*
@@ -1331,4 +1332,23 @@ public void run() {
13311332

13321333
});
13331334
}
1335+
1336+
/**
1337+
* Get network body size limit
1338+
*/
1339+
@ReactMethod
1340+
public void getNetworkBodyMaxSize(Promise promise) {
1341+
1342+
MainThreadHandler.runOnMainThread(new Runnable() {
1343+
@Override
1344+
public void run() {
1345+
try {
1346+
promise.resolve(InternalCore.INSTANCE.get_networkLogCharLimit());
1347+
} catch (Exception e) {
1348+
e.printStackTrace();
1349+
promise.resolve(false);
1350+
}
1351+
}
1352+
});
1353+
}
13341354
}

android/src/test/java/com/instabug/reactlibrary/RNInstabugReactnativeModuleTest.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,9 +686,22 @@ public void testEnableAutoMasking(){
686686
String maskTextInputs = "textInputs";
687687
String maskMedia = "media";
688688
String maskNone = "none";
689-
689+
690690
rnModule.enableAutoMasking(JavaOnlyArray.of(maskLabel, maskMedia, maskTextInputs,maskNone));
691-
691+
692692
mockInstabug.verify(() -> Instabug.setAutoMaskScreenshotsTypes(MaskingType.LABELS,MaskingType.MEDIA,MaskingType.TEXT_INPUTS,MaskingType.MASK_NOTHING));
693693
}
694+
695+
@Test
696+
public void testGetNetworkBodyMaxSize_resolvesPromiseWithExpectedValue() {
697+
Promise promise = mock(Promise.class);
698+
InternalCore internalAPM = mock(InternalCore.class);
699+
int expected = 10240;
700+
when(internalAPM.get_networkLogCharLimit()).thenReturn(expected);
701+
702+
rnModule.getNetworkBodyMaxSize(promise);
703+
704+
verify(promise).resolve(expected);
705+
}
706+
694707
}

examples/default/ios/InstabugTests/InstabugSampleTests.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,4 +634,23 @@ - (void)testSetNetworkLogBodyEnabled {
634634
OCMVerify([mock setLogBodyEnabled:isEnabled]);
635635
}
636636

637+
- (void)testGetNetworkBodyMaxSize {
638+
id mock = OCMClassMock([IBGNetworkLogger class]);
639+
double expectedValue = 10240.0;
640+
641+
OCMStub([mock getNetworkBodyMaxSize]).andReturn(expectedValue);
642+
643+
XCTestExpectation *expectation = [self expectationWithDescription:@"Call resolve block"];
644+
RCTPromiseResolveBlock resolve = ^(NSNumber *result) {
645+
XCTAssertEqual(result.doubleValue, expectedValue);
646+
[expectation fulfill];
647+
};
648+
649+
[self.instabugBridge getNetworkBodyMaxSize:resolve :nil];
650+
[self waitForExpectationsWithTimeout:1.0 handler:nil];
651+
652+
OCMVerify(ClassMethod([mock getNetworkBodyMaxSize]));
653+
}
654+
655+
637656
@end

examples/default/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const App: React.FC = () => {
5050
token: 'deb1910a7342814af4e4c9210c786f35',
5151
invocationEvents: [InvocationEvent.floatingButton],
5252
debugLogsLevel: LogLevel.verbose,
53-
networkInterceptionMode: NetworkInterceptionMode.native,
53+
networkInterceptionMode: NetworkInterceptionMode.javascript,
5454
});
5555

5656
CrashReporting.setNDKCrashesEnabled(true);

ios/RNInstabug/InstabugReactBridge.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,5 +140,6 @@ w3cExternalTraceAttributes:(NSDictionary * _Nullable)w3cExternalTraceAttributes;
140140
- (void)removeAllFeatureFlags;
141141
- (void)setNetworkLogBodyEnabled:(BOOL)isEnabled;
142142
- (void)enableAutoMasking:(NSArray *)autoMaskingTypes;
143+
- (void)getNetworkBodyMaxSize:(RCTPromiseResolveBlock)resolve :(RCTPromiseRejectBlock)reject;
143144

144145
@end

ios/RNInstabug/InstabugReactBridge.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,10 @@ + (BOOL)iOSVersionIsLessThan:(NSString *)iOSVersion {
452452
[Instabug setAutoMaskScreenshots: autoMaskingOptions];
453453
};
454454

455+
RCT_EXPORT_METHOD(getNetworkBodyMaxSize:(RCTPromiseResolveBlock)resolve :(RCTPromiseRejectBlock)reject) {
456+
resolve(@(IBGNetworkLogger.getNetworkBodyMaxSize));
457+
}
458+
455459
RCT_EXPORT_METHOD(setNetworkLogBodyEnabled:(BOOL)isEnabled) {
456460
IBGNetworkLogger.logBodyEnabled = isEnabled;
457461
}

ios/RNInstabug/Util/IBGNetworkLogger+CP.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ NS_ASSUME_NONNULL_BEGIN
6161
+ (void)setCPRequestAsyncObfuscationHandler:(void (^)(NSURLRequest * requestToBeObfuscated, void (^ completion)(NSURLRequest * obfuscatedRequest)))asyncObfuscationHandler;
6262
+ (void)setCPRequestFilteringHandler:(void (^)(NSURLRequest * request, void (^completion)(BOOL keep)))requestFilteringHandler;
6363
+ (void)setCPResponseFilteringHandler:(void (^)(NSURLResponse * response, void (^comppletion)(BOOL keep)))responseFilteringHandler;
64+
+ (double)getNetworkBodyMaxSize;
6465

6566
@end
6667

src/modules/Instabug.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import type { NavigationAction, NavigationState as NavigationStateV4 } from 'rea
1616
import type { InstabugConfig } from '../models/InstabugConfig';
1717
import Report from '../models/Report';
1818
import { emitter, NativeEvents, NativeInstabug } from '../native/NativeInstabug';
19-
import { registerW3CFlagsListener } from '../utils/FeatureFlags';
19+
import { registerFeatureFlagsListener } from '../utils/FeatureFlags';
2020
import {
2121
AutoMaskingType,
2222
ColorTheme,
@@ -87,7 +87,7 @@ function reportCurrentViewForAndroid(screenName: string | null) {
8787
export const init = async (config: InstabugConfig) => {
8888
if (Platform.OS === 'android') {
8989
// Add android feature flags listener for android
90-
registerW3CFlagsListener();
90+
registerFeatureFlagsListener();
9191
addOnFeatureUpdatedListener(config);
9292
} else {
9393
isNativeInterceptionFeatureEnabled = await NativeNetworkLogger.isNativeInterceptionEnabled();
@@ -871,20 +871,21 @@ export const componentDidAppearListener = (event: ComponentDidAppearEvent) => {
871871
};
872872

873873
/**
874-
* Sets listener to W3ExternalTraceID flag changes
874+
* Sets listener to feature flag changes
875875
* @param handler A callback that gets the update value of the flag
876876
*/
877-
export const _registerW3CFlagsChangeListener = (
877+
export const _registerFeatureFlagsChangeListener = (
878878
handler: (payload: {
879879
isW3ExternalTraceIDEnabled: boolean;
880880
isW3ExternalGeneratedHeaderEnabled: boolean;
881881
isW3CaughtHeaderEnabled: boolean;
882+
networkBodyLimit: number;
882883
}) => void,
883884
) => {
884-
emitter.addListener(NativeEvents.ON_W3C_FLAGS_CHANGE, (payload) => {
885+
emitter.addListener(NativeEvents.ON_FEATURE_FLAGS_CHANGE, (payload) => {
885886
handler(payload);
886887
});
887-
NativeInstabug.registerW3CFlagsChangeListener();
888+
NativeInstabug.registerFeatureFlagsChangeListener();
888889
};
889890

890891
/**

0 commit comments

Comments
 (0)