Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ commands:
steps:
- run:
name: Install Appium
command: npm install -g appium
command: npm install -g appium@2.19.0
- when:
condition:
equal:
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ android/gradlew.bat
**/ios/ServiceDefinitions.json
**/ios/Runner/GeneratedPluginRegistrant.*

# Project specific
/PRDs/

# Exceptions to above rules.
!**/ios/**/default.mode1v3
!**/ios/**/default.mode2v3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ void main() {
'isW3cExternalTraceIDEnabled': true,
}),
);
when(mHost.getNetworkBodyMaxSize()).thenAnswer(
(_) => Future.value(10240),
);
});

setUp(() {
Expand All @@ -78,6 +81,7 @@ void main() {

test('onResponse Test', () async {
try {

await dio.get<dynamic>('/test');
// ignore: deprecated_member_use
} on DioError {
Expand Down
3 changes: 2 additions & 1 deletion packages/instabug_flutter/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
- Add support for user steps ([#519](https://github.com/Instabug/Instabug-Flutter/pull/519))

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

### Changed

Expand All @@ -25,7 +27,6 @@

### Added


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

- Add support for BugReporting user consents. ([#573](https://github.com/Instabug/Instabug-Flutter/pull/573))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,11 @@ public void reply(Void reply) {

}
});

featureFlagsFlutterApi.onNetworkLogBodyMaxSizeChange(
(long) featuresState.getNetworkLogCharLimit(),
reply -> {}
);
}
});
}
Expand Down Expand Up @@ -747,4 +752,20 @@ public void setFullscreen(@NonNull final Boolean isEnabled) {
}
}

@Override
public void getNetworkBodyMaxSize(@NonNull InstabugPigeon.Result<Double> result) {
ThreadManager.runOnMainThread(
new Runnable() {
@Override
public void run() {
try {
double networkCharLimit = InternalCore.INSTANCE.get_networkLogCharLimit();
result.success(networkCharLimit);
} catch (Exception e) {
e.printStackTrace();
}
}
}
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -779,4 +779,15 @@ public void testAutoMasking() {
mInstabug.verify(() -> Instabug.setAutoMaskScreenshotsTypes(MaskingType.LABELS,MaskingType.MEDIA,MaskingType.TEXT_INPUTS,MaskingType.MASK_NOTHING));
}


@Test
public void testGetNetworkBodyMaxSize() {
double expected = 10240;
InstabugPigeon.Result<Double> result = makeResult((actual) -> assertEquals((Double) expected, actual));

mockkObject(new InternalCore[]{InternalCore.INSTANCE}, false);
every(mockKMatcherScope -> InternalCore.INSTANCE.get_networkLogCharLimit()).returns((int) expected);

api.getNetworkBodyMaxSize(result);
}
}
3 changes: 3 additions & 0 deletions packages/instabug_flutter/example/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ app.*.symbols

# Obfuscation related
app.*.map.json

# Android related
/android/app/.cxx/
2 changes: 1 addition & 1 deletion packages/instabug_flutter/example/android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pluginManagement {

plugins {
id "dev.flutter.flutter-plugin-loader" version "1.0.0"
id "com.android.application" version "8.1.0" apply false
id "com.android.application" version "8.2.1" apply false
id "org.jetbrains.kotlin.android" version "1.8.22" apply false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -650,4 +650,20 @@ - (void)testAutoMasking {

OCMVerify([self.mInstabug setAutoMaskScreenshots: (IBGAutoMaskScreenshotOptionMaskNothing | IBGAutoMaskScreenshotOptionTextInputs | IBGAutoMaskScreenshotOptionLabels | IBGAutoMaskScreenshotOptionMedia)]);
}
- (void)testGetNetworkBodyMaxSize {
double expectedValue = 10240.0;
XCTestExpectation *expectation = [self expectationWithDescription:@"Call completion handler"];

OCMStub([self.mNetworkLogger getNetworkBodyMaxSize]).andReturn(expectedValue);

[self.api getNetworkBodyMaxSizeWithCompletion:^(NSNumber *actual, FlutterError *error) {
[expectation fulfill];
XCTAssertEqual(actual.doubleValue, expectedValue);
XCTAssertNil(error);
}];

OCMVerify([self.mNetworkLogger getNetworkBodyMaxSize]);
[self waitForExpectations:@[expectation] timeout:5.0];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
enableGPUValidationMode = "1"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
Expand Down
5 changes: 5 additions & 0 deletions packages/instabug_flutter/ios/Classes/Modules/InstabugApi.m
Original file line number Diff line number Diff line change
Expand Up @@ -609,4 +609,9 @@ - (void)setFullscreenIsEnabled:(NSNumber *)isEnabled error:(FlutterError *_Nulla
// Empty implementation as requested
}

- (void)getNetworkBodyMaxSizeWithCompletion:(nonnull void (^)(NSNumber * _Nullable, FlutterError * _Nullable))completion {
completion(@(IBGNetworkLogger.getNetworkBodyMaxSize), nil);
}


@end
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ NS_ASSUME_NONNULL_BEGIN
duration:(int64_t) duration
gqlQueryName:(NSString * _Nullable)gqlQueryName;

+ (double)getNetworkBodyMaxSize;

@end

NS_ASSUME_NONNULL_END
2 changes: 1 addition & 1 deletion packages/instabug_flutter/lib/src/modules/instabug.dart
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class Instabug {
debugLogsLevel.toString(),
appVariant,
);
return FeatureFlagsManager().registerW3CFlagsListener();
return FeatureFlagsManager().registerFeatureFlagsListener();
}

/// Sets a [callback] to be called wehenever a screen name is captured to mask
Expand Down
33 changes: 32 additions & 1 deletion packages/instabug_flutter/lib/src/modules/network_logger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import 'package:instabug_flutter/src/models/network_data.dart';
import 'package:instabug_flutter/src/models/w3c_header.dart';
import 'package:instabug_flutter/src/modules/apm.dart';
import 'package:instabug_flutter/src/utils/feature_flags_manager.dart';
import 'package:instabug_flutter/src/utils/instabug_constants.dart';
import 'package:instabug_flutter/src/utils/instabug_logger.dart';
import 'package:instabug_flutter/src/utils/iterable_ext.dart';
import 'package:instabug_flutter/src/utils/network_manager.dart';
import 'package:instabug_flutter/src/utils/w3c_header_utils.dart';
Expand Down Expand Up @@ -86,7 +88,36 @@ class NetworkLogger {
Future<void> networkLogInternal(NetworkData data) async {
final omit = await _manager.omitLog(data);
if (omit) return;
final obfuscated = await _manager.obfuscateLog(data);

// Check size limits early to avoid processing large bodies
final requestExceeds = await _manager.didRequestBodyExceedSizeLimit(data);
final responseExceeds = await _manager.didResponseBodyExceedSizeLimit(data);

var processedData = data;
if (requestExceeds || responseExceeds) {
// Replace bodies with warning messages
processedData = data.copyWith(
requestBody: requestExceeds
? InstabugConstants.getRequestBodyReplacementMessage(
data.requestBodySize,
)
: data.requestBody,
responseBody: responseExceeds
? InstabugConstants.getResponseBodyReplacementMessage(
data.responseBodySize,
)
: data.responseBody,
);

// Log the truncation event.
final isBothExceeds = requestExceeds && responseExceeds;
InstabugLogger.I.e(
"Truncated network ${isBothExceeds ? 'request and response' : requestExceeds ? 'request' : 'response'} body",
tag: InstabugConstants.networkLoggerTag,
);
}

final obfuscated = await _manager.obfuscateLog(processedData);
await _host.networkLog(obfuscated.toJson());
await APM.networkLogAndroid(obfuscated);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ typedef OnW3CFeatureFlagChange = void Function(
bool isW3cCaughtHeaderEnabled,
);

typedef OnNetworkBodyMaxSizeChangeCallback = void Function();

class FeatureFlagsManager implements FeatureFlagsFlutterApi {
// Access the singleton instance
factory FeatureFlagsManager() {
Expand All @@ -23,6 +25,10 @@ class FeatureFlagsManager implements FeatureFlagsFlutterApi {
// Host API instance
static InstabugHostApi _host = InstabugHostApi();

// Callback for network body max size changes
static OnNetworkBodyMaxSizeChangeCallback?
_onNetworkBodyMaxSizeChangeCallback;

/// @nodoc
@visibleForTesting
// Setter for the host API
Expand All @@ -38,10 +44,21 @@ class FeatureFlagsManager implements FeatureFlagsFlutterApi {
// since it breaks the singleton pattern
}

/// Sets the callback for network body max size changes
// ignore: avoid_setters_without_getters
set onNetworkBodyMaxSizeChangeCallback(
OnNetworkBodyMaxSizeChangeCallback callback,
) {
_onNetworkBodyMaxSizeChangeCallback = callback;
}

// Internal state flags
bool _isAndroidW3CExternalTraceID = false;
bool _isAndroidW3CExternalGeneratedHeader = false;
bool _isAndroidW3CCaughtHeader = false;
int _networkBodyMaxSize = 0;

int get networkBodyMaxSize => _networkBodyMaxSize;

Future<W3cFeatureFlags> getW3CFeatureFlagsHeader() async {
if (IBGBuildInfo.instance.isAndroid) {
Expand All @@ -64,9 +81,10 @@ class FeatureFlagsManager implements FeatureFlagsFlutterApi {
);
}

Future<void> registerW3CFlagsListener() async {
Future<void> registerFeatureFlagsListener() async {
FeatureFlagsFlutterApi.setup(this); // Use 'this' instead of _instance

// W3C Feature Flags
final featureFlags = await _host.isW3CFeatureFlagsEnabled();
_isAndroidW3CCaughtHeader =
featureFlags['isW3cCaughtHeaderEnabled'] ?? false;
Expand All @@ -75,6 +93,10 @@ class FeatureFlagsManager implements FeatureFlagsFlutterApi {
_isAndroidW3CExternalGeneratedHeader =
featureFlags['isW3cExternalGeneratedHeaderEnabled'] ?? false;

// Network Body Max Size
final networkBodyMaxSize = await _host.getNetworkBodyMaxSize();
_networkBodyMaxSize = networkBodyMaxSize?.toInt() ?? 0;

return _host.registerFeatureFlagChangeListener();
}

Expand All @@ -89,4 +111,10 @@ class FeatureFlagsManager implements FeatureFlagsFlutterApi {
_isAndroidW3CExternalTraceID = isW3cExternalTraceIDEnabled;
_isAndroidW3CExternalGeneratedHeader = isW3cExternalGeneratedHeaderEnabled;
}

@override
void onNetworkLogBodyMaxSizeChange(int networkBodyMaxSize) {
_networkBodyMaxSize = networkBodyMaxSize;
_onNetworkBodyMaxSizeChangeCallback?.call();
}
}
31 changes: 31 additions & 0 deletions packages/instabug_flutter/lib/src/utils/instabug_constants.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/// Constants used throughout the Instabug Flutter SDK
class InstabugConstants {
InstabugConstants._();

// Network logging constants
static const String networkLoggerTag = 'NetworkLogger';
static const String networkManagerTag = 'NetworkManager';

// Network body replacement messages
static const String requestBodyReplacedPrefix = '[REQUEST_BODY_REPLACED]';
static const String responseBodyReplacedPrefix = '[RESPONSE_BODY_REPLACED]';
static const String exceedsLimitSuffix = 'exceeds limit';

/// Generates a request body replacement message
static String getRequestBodyReplacementMessage(int size) {
return '$requestBodyReplacedPrefix - Size: $size $exceedsLimitSuffix';
}

/// Generates a response body replacement message
static String getResponseBodyReplacementMessage(int size) {
return '$responseBodyReplacedPrefix - Size: $size $exceedsLimitSuffix';
}

/// Generates a network body size limit exceeded log message
static String getNetworkBodyLimitExceededMessage({
required String type,
required int bodySize,
}) {
return 'Network body size limit exceeded for $type - Size: $bodySize';
}
}
Loading