Skip to content

Commit 335601c

Browse files
feat: respect BE network body limit (#593)
* feat: add network body max size APIs in Android - Added `onNetworkLogBodyMaxSizeChange` method to `FeatureFlagsFlutterApi` in Dart. - Implemented `getNetworkBodyMaxSize` method in `InstabugApi` to retrieve network log character limit. - Updated `InstabugApiTest` with a new test for `getNetworkBodyMaxSize`. * feat: add network body max size APIs in iOS - Updated Instabug podspec to version 15.0.1. - Added `getNetworkBodyMaxSize` method in `InstabugApi` for retrieving network log body size. - Introduced a new test case for `getNetworkBodyMaxSize` in `InstabugApiTests`. - Updated .gitignore files to include project-specific and Android-related paths. * feat: add body size checks inside network manager and cache retrieved in feature flags manager - Added `_networkBodyMaxSize` to `FeatureFlagsManager` for managing network body size limits. - Introduced `didRequestBodyExceedSizeLimit` and `didResponseBodyExceedSizeLimit` methods in `NetworkManager` to validate request and response body sizes against the limit. - Created `InstabugConstants` for standardized logging messages related to network body size limits. - Implemented caching for network body size retrieval to optimize performance. * feat: utilize network manager size checker APIs inside `network_logger.dart` - Added early checks for request and response body size limits in `networkLogInternal`. - Implemented truncation of request/response bodies with warning messages if size limits are exceeded. - Logged truncation events using `InstabugLogger` for better visibility into network logging behavior. * chore: add default value of 10KB as a fallback, add network body size specific tests - Introduced a default network body max size of 10KB to improve logging consistency. - Updated error handling to set the cached size to the default when native API retrieval fails. - Added unit tests for `didRequestBodyExceedSizeLimit` and `didResponseBodyExceedSizeLimit` to ensure proper size limit checks for request and response bodies. * chore: run `dart format .`, and add new `example/pubspec.lock` * fix: reference the correct iOS SDK and the correct podfile setup * fix: update network body max size handling and caching - Changed the return type of `getNetworkBodyMaxSize` from `int?` to `double?` in the API and updated related method calls accordingly. - Renamed `registerW3CFlagsListener` to `registerFeatureFlagsListener` for consistency across the codebase. - Introduced a callback mechanism in `FeatureFlagsManager` to handle changes in network body max size, ensuring proper cache management in `NetworkManager`. - Updated tests to reflect the new method names and ensure functionality remains intact. * chore: update CHANGELOG to include backend network body size limit support * fix: flutter and android tests * fix: fix ios and flutter failing tests * chore: run dart format * fix: improve formatting to align with linter * fix * fix * fix --------- Co-authored-by: ahmed alaa <154802748+ahmedAlaaInstabug@users.noreply.github.com>
1 parent 7eab68c commit 335601c

File tree

23 files changed

+540
-10
lines changed

23 files changed

+540
-10
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ commands:
5656
steps:
5757
- run:
5858
name: Install Appium
59-
command: npm install -g appium
59+
command: npm install -g appium@2.19.0
6060
- when:
6161
condition:
6262
equal:

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ android/gradlew.bat
8080
**/ios/ServiceDefinitions.json
8181
**/ios/Runner/GeneratedPluginRegistrant.*
8282

83+
# Project specific
84+
/PRDs/
85+
8386
# Exceptions to above rules.
8487
!**/ios/**/default.mode1v3
8588
!**/ios/**/default.mode2v3

packages/instabug_dio_interceptor/test/instabug_dio_interceptor_test.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ void main() {
6464
'isW3cExternalTraceIDEnabled': true,
6565
}),
6666
);
67+
when(mHost.getNetworkBodyMaxSize()).thenAnswer(
68+
(_) => Future.value(10240),
69+
);
6770
});
6871

6972
setUp(() {
@@ -78,6 +81,7 @@ void main() {
7881

7982
test('onResponse Test', () async {
8083
try {
84+
8185
await dio.get<dynamic>('/test');
8286
// ignore: deprecated_member_use
8387
} on DioError {

packages/instabug_flutter/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
- Add support for user steps ([#519](https://github.com/Instabug/Instabug-Flutter/pull/519))
1212

1313
- Add support for App variant. ([#585](https://github.com/Instabug/Instabug-Flutter/pull/585))
14+
-
15+
- Add support for respecting backend network body size limits. ([#593](https://github.com/Instabug/Instabug-Flutter/pull/593))
1416

1517
### Changed
1618

@@ -25,7 +27,6 @@
2527

2628
### Added
2729

28-
2930
- Add support for xCode 16. ([#574](https://github.com/Instabug/Instabug-Flutter/pull/574))
3031

3132
- Add support for BugReporting user consents. ([#573](https://github.com/Instabug/Instabug-Flutter/pull/573))

packages/instabug_flutter/android/src/main/java/com/instabug/flutter/modules/InstabugApi.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,11 @@ public void reply(Void reply) {
528528

529529
}
530530
});
531+
532+
featureFlagsFlutterApi.onNetworkLogBodyMaxSizeChange(
533+
(long) featuresState.getNetworkLogCharLimit(),
534+
reply -> {}
535+
);
531536
}
532537
});
533538
}
@@ -747,4 +752,20 @@ public void setFullscreen(@NonNull final Boolean isEnabled) {
747752
}
748753
}
749754

755+
@Override
756+
public void getNetworkBodyMaxSize(@NonNull InstabugPigeon.Result<Double> result) {
757+
ThreadManager.runOnMainThread(
758+
new Runnable() {
759+
@Override
760+
public void run() {
761+
try {
762+
double networkCharLimit = InternalCore.INSTANCE.get_networkLogCharLimit();
763+
result.success(networkCharLimit);
764+
} catch (Exception e) {
765+
e.printStackTrace();
766+
}
767+
}
768+
}
769+
);
770+
}
750771
}

packages/instabug_flutter/android/src/test/java/com/instabug/flutter/InstabugApiTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,4 +779,15 @@ public void testAutoMasking() {
779779
mInstabug.verify(() -> Instabug.setAutoMaskScreenshotsTypes(MaskingType.LABELS,MaskingType.MEDIA,MaskingType.TEXT_INPUTS,MaskingType.MASK_NOTHING));
780780
}
781781

782+
783+
@Test
784+
public void testGetNetworkBodyMaxSize() {
785+
double expected = 10240;
786+
InstabugPigeon.Result<Double> result = makeResult((actual) -> assertEquals((Double) expected, actual));
787+
788+
mockkObject(new InternalCore[]{InternalCore.INSTANCE}, false);
789+
every(mockKMatcherScope -> InternalCore.INSTANCE.get_networkLogCharLimit()).returns((int) expected);
790+
791+
api.getNetworkBodyMaxSize(result);
792+
}
782793
}

packages/instabug_flutter/example/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,6 @@ app.*.symbols
3939

4040
# Obfuscation related
4141
app.*.map.json
42+
43+
# Android related
44+
/android/app/.cxx/

packages/instabug_flutter/example/android/settings.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pluginManagement {
2020

2121
plugins {
2222
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
23-
id "com.android.application" version "8.1.0" apply false
23+
id "com.android.application" version "8.2.1" apply false
2424
id "org.jetbrains.kotlin.android" version "1.8.22" apply false
2525
}
2626

packages/instabug_flutter/example/ios/InstabugTests/InstabugApiTests.m

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,4 +650,20 @@ - (void)testAutoMasking {
650650

651651
OCMVerify([self.mInstabug setAutoMaskScreenshots: (IBGAutoMaskScreenshotOptionMaskNothing | IBGAutoMaskScreenshotOptionTextInputs | IBGAutoMaskScreenshotOptionLabels | IBGAutoMaskScreenshotOptionMedia)]);
652652
}
653+
- (void)testGetNetworkBodyMaxSize {
654+
double expectedValue = 10240.0;
655+
XCTestExpectation *expectation = [self expectationWithDescription:@"Call completion handler"];
656+
657+
OCMStub([self.mNetworkLogger getNetworkBodyMaxSize]).andReturn(expectedValue);
658+
659+
[self.api getNetworkBodyMaxSizeWithCompletion:^(NSNumber *actual, FlutterError *error) {
660+
[expectation fulfill];
661+
XCTAssertEqual(actual.doubleValue, expectedValue);
662+
XCTAssertNil(error);
663+
}];
664+
665+
OCMVerify([self.mNetworkLogger getNetworkBodyMaxSize]);
666+
[self waitForExpectations:@[expectation] timeout:5.0];
667+
}
668+
653669
@end

packages/instabug_flutter/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
ignoresPersistentStateOnLaunch = "NO"
6969
debugDocumentVersioning = "YES"
7070
debugServiceExtension = "internal"
71+
enableGPUValidationMode = "1"
7172
allowLocationSimulation = "YES">
7273
<BuildableProductRunnable
7374
runnableDebuggingMode = "0">

0 commit comments

Comments
 (0)