Skip to content

Commit eaec607

Browse files
Merge pull request #1362 from Instabug/feat/stop-capturing-network-body
feat: enable/disable stop capturing network body
2 parents 461eee5 + 2bd1043 commit eaec607

File tree

10 files changed

+69
-0
lines changed

10 files changed

+69
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## [Unreleased](https://github.com/Instabug/Instabug-React-Native/compare/v14.1.0...dev)
2+
3+
### Added
4+
5+
- Add support for enable/disable capturing network body. ([#1362](https://github.com/Instabug/Instabug-React-Native/pull/1362))
6+
17
# Changelog
28

39
## [Unreleased](https://github.com/Instabug/Instabug-React-Native/compare/v14.1.0...dev)

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,4 +1294,21 @@ public void run() {
12941294

12951295
});
12961296
}
1297+
/**
1298+
* Enables or disables capturing network body.
1299+
* @param isEnabled A boolean to enable/disable capturing network body.
1300+
*/
1301+
@ReactMethod
1302+
public void setNetworkLogBodyEnabled(final boolean isEnabled) {
1303+
MainThreadHandler.runOnMainThread(new Runnable() {
1304+
@Override
1305+
public void run() {
1306+
try {
1307+
Instabug.setNetworkLogBodyEnabled(isEnabled);
1308+
} catch (Exception e) {
1309+
e.printStackTrace();
1310+
}
1311+
}
1312+
});
1313+
}
12971314
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,4 +676,18 @@ public void testEnableAutoMasking(){
676676

677677
mockInstabug.verify(() -> Instabug.setAutoMaskScreenshotsTypes(MaskingType.LABELS,MaskingType.MEDIA,MaskingType.TEXT_INPUTS,MaskingType.MASK_NOTHING));
678678
}
679+
680+
@Test
681+
public void testSetNetworkLogBodyEnabled() {
682+
rnModule.setNetworkLogBodyEnabled(true);
683+
684+
mockInstabug.verify(() -> Instabug.setNetworkLogBodyEnabled(true));
685+
}
686+
687+
@Test
688+
public void testSetNetworkLogBodyDisabled() {
689+
rnModule.setNetworkLogBodyEnabled(false);
690+
691+
mockInstabug.verify(() -> Instabug.setNetworkLogBodyEnabled(false));
692+
}
679693
}

examples/default/ios/InstabugTests/InstabugSampleTests.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,4 +625,13 @@ - (void)testEnableAutoMasking {
625625
OCMVerify([mock setAutoMaskScreenshots:IBGAutoMaskScreenshotOptionLabels | IBGAutoMaskScreenshotOptionTextInputs | IBGAutoMaskScreenshotOptionMedia | IBGAutoMaskScreenshotOptionMaskNothing]);
626626
}
627627

628+
- (void)testSetNetworkLogBodyEnabled {
629+
id mock = OCMClassMock([IBGNetworkLogger class]);
630+
BOOL isEnabled = YES;
631+
632+
OCMStub([mock setLogBodyEnabled:isEnabled]);
633+
[self.instabugBridge setNetworkLogBodyEnabled:isEnabled];
634+
OCMVerify([mock setLogBodyEnabled:isEnabled]);
635+
}
636+
628637
@end

ios/RNInstabug/InstabugReactBridge.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,5 +139,6 @@ w3cExternalTraceAttributes:(NSDictionary * _Nullable)w3cExternalTraceAttributes;
139139
- (void)removeFeatureFlags:(NSArray *)featureFlags;
140140
- (void)removeAllFeatureFlags;
141141
- (void)enableAutoMasking:(NSArray *)autoMaskingTypes;
142+
- (void)setNetworkLogBodyEnabled:(BOOL)isEnabled;
142143

143144
@end

ios/RNInstabug/InstabugReactBridge.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,4 +451,7 @@ + (BOOL)iOSVersionIsLessThan:(NSString *)iOSVersion {
451451
[Instabug setAutoMaskScreenshots: autoMaskingOptions];
452452

453453
};
454+
RCT_EXPORT_METHOD(setNetworkLogBodyEnabled:(BOOL)isEnabled) {
455+
IBGNetworkLogger.logBodyEnabled = isEnabled;
456+
}
454457
@end

src/modules/NetworkLogger.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import xhr, { NetworkData, ProgressCallback } from '../utils/XhrNetworkIntercept
55
import { isContentTypeNotAllowed, reportNetworkLog } from '../utils/InstabugUtils';
66
import { InstabugRNConfig } from '../utils/config';
77
import { Logger } from '../utils/logger';
8+
import { NativeInstabug } from '../native/NativeInstabug';
89

910
export type { NetworkData };
1011

@@ -114,3 +115,11 @@ export const apolloLinkRequestHandler: RequestHandler = (operation, forward) =>
114115

115116
return forward(operation);
116117
};
118+
119+
/**
120+
* Sets whether network body logs will be captured or not.
121+
* @param isEnabled
122+
*/
123+
export const setNetworkLogBodyEnabled = (isEnabled: boolean) => {
124+
NativeInstabug.setNetworkLogBodyEnabled(isEnabled);
125+
};

src/native/NativeInstabug.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export interface InstabugNativeModule extends NativeModule {
7373
): void;
7474

7575
setNetworkLoggingEnabled(isEnabled: boolean): void;
76+
setNetworkLogBodyEnabled(isEnabled: boolean): void;
7677

7778
// Repro Steps APIs //
7879
setReproStepsConfig(

test/mocks/mockInstabug.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ const mockInstabug: InstabugNativeModule = {
7474
isW3CaughtHeaderEnabled: jest.fn(),
7575
registerW3CFlagsChangeListener: jest.fn(),
7676
enableAutoMasking: jest.fn(),
77+
setNetworkLogBodyEnabled: jest.fn(),
7778
};
7879

7980
export default mockInstabug;

test/modules/NetworkLogger.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import Interceptor from '../../src/utils/XhrNetworkInterceptor';
88
import { isContentTypeNotAllowed, reportNetworkLog } from '../../src/utils/InstabugUtils';
99
import InstabugConstants from '../../src/utils/InstabugConstants';
1010
import { Logger } from '../../src/utils/logger';
11+
import { NativeInstabug } from '../../src/native/NativeInstabug';
1112

1213
const clone = <T>(obj: T): T => {
1314
return JSON.parse(JSON.stringify(obj));
@@ -282,4 +283,11 @@ describe('NetworkLogger Module', () => {
282283

283284
expect(reportNetworkLog).toHaveBeenCalledWith(networkData);
284285
});
286+
287+
it('should call the native method setNetworkLogBodyEnabled', () => {
288+
NetworkLogger.setNetworkLogBodyEnabled(true);
289+
290+
expect(NativeInstabug.setNetworkLogBodyEnabled).toBeCalledTimes(1);
291+
expect(NativeInstabug.setNetworkLogBodyEnabled).toBeCalledWith(true);
292+
});
285293
});

0 commit comments

Comments
 (0)