Skip to content

Commit b7299d9

Browse files
Merge remote-tracking branch 'origin/feat/network-spans-feature-flags' into feat/network-spans-unit-testing
2 parents 867bfc0 + 19c1c98 commit b7299d9

File tree

1 file changed

+46
-31
lines changed

1 file changed

+46
-31
lines changed

src/modules/Instabug.ts

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,10 @@ const handleNetworkInterceptionMode = (config: InstabugConfig) => {
182182
}
183183

184184
if (Platform.OS === 'android') {
185-
checkNativeInterceptionForAndroid(config);
185+
handleInterceptionModeForAndroid(config);
186186
config.networkInterceptionMode = NetworkInterceptionMode.javascript; // Need to enable JS interceptor in all scenarios for Bugs & Crashes network logs
187187
} else if (Platform.OS === 'ios') {
188-
checkNativeInterceptionForIOS(config);
188+
handleInterceptionModeForIOS(config);
189189
}
190190
NetworkLogger.setNativeInterceptionEnabled(shouldEnableNativeInterception);
191191

@@ -195,49 +195,64 @@ const handleNetworkInterceptionMode = (config: InstabugConfig) => {
195195
};
196196

197197
/**
198-
* Handles the native interception logic for Android.
198+
* Handles the JS interception logic for Android.
199199
*/
200-
const checkNativeInterceptionForAndroid = (config: InstabugConfig) => {
201-
const { networkInterceptionMode } = config;
200+
function handleAndroidJSInterception() {
201+
if (isNativeInterceptionFeatureEnabled && hasAPMNetworkPlugin) {
202+
shouldEnableNativeInterception = true;
203+
console.warn(
204+
InstabugConstants.IBG_APM_TAG + InstabugConstants.SWITCHED_TO_NATIVE_INTERCEPTION_MESSAGE,
205+
);
206+
}
207+
}
202208

203-
if (networkInterceptionMode === NetworkInterceptionMode.javascript) {
204-
if (isNativeInterceptionFeatureEnabled && hasAPMNetworkPlugin) {
205-
shouldEnableNativeInterception = true;
206-
console.warn(
207-
InstabugConstants.IBG_APM_TAG + InstabugConstants.SWITCHED_TO_NATIVE_INTERCEPTION_MESSAGE,
208-
);
209+
/**
210+
* Handles the native interception logic for Android.
211+
*/
212+
function handleAndroidNativeInterception() {
213+
if (isNativeInterceptionFeatureEnabled) {
214+
shouldEnableNativeInterception = hasAPMNetworkPlugin;
215+
if (!hasAPMNetworkPlugin) {
216+
console.error(InstabugConstants.IBG_APM_TAG + InstabugConstants.PLUGIN_NOT_INSTALLED_MESSAGE);
209217
}
210218
} else {
211-
if (isNativeInterceptionFeatureEnabled) {
212-
shouldEnableNativeInterception = hasAPMNetworkPlugin;
213-
if (!hasAPMNetworkPlugin) {
214-
console.error(
215-
InstabugConstants.IBG_APM_TAG + InstabugConstants.PLUGIN_NOT_INSTALLED_MESSAGE,
216-
);
217-
}
219+
shouldEnableNativeInterception = false; // rollback to use JS interceptor for APM & Core.
220+
if (hasAPMNetworkPlugin) {
221+
console.error(
222+
InstabugConstants.IBG_APM_TAG + InstabugConstants.NATIVE_INTERCEPTION_DISABLED_MESSAGE,
223+
);
218224
} else {
219-
if (hasAPMNetworkPlugin) {
220-
console.error(
221-
InstabugConstants.IBG_APM_TAG + InstabugConstants.NATIVE_INTERCEPTION_DISABLED_MESSAGE,
222-
);
223-
} else {
224-
shouldEnableNativeInterception = false; // rollback to use JS interceptor for APM & Core.
225-
console.error(
226-
InstabugConstants.IBG_APM_TAG +
227-
InstabugConstants.PLUGIN_NOT_INSTALLED_AND_NATIVE_INTERCEPTION_DISABLED_MESSAGE,
228-
);
229-
}
225+
console.error(
226+
InstabugConstants.IBG_APM_TAG +
227+
InstabugConstants.PLUGIN_NOT_INSTALLED_AND_NATIVE_INTERCEPTION_DISABLED_MESSAGE,
228+
);
230229
}
231230
}
231+
}
232+
233+
/**
234+
* Handles the interception mode logic for Android.
235+
* By deciding which interception mode should be enabled (Native or JavaScript).
236+
*/
237+
const handleInterceptionModeForAndroid = (config: InstabugConfig) => {
238+
const { networkInterceptionMode } = config;
239+
240+
if (networkInterceptionMode === NetworkInterceptionMode.javascript) {
241+
handleAndroidJSInterception();
242+
} else {
243+
handleAndroidNativeInterception();
244+
}
232245
};
233246

234247
/**
235-
* Handles the native interception logic for iOS.
248+
* Handles the interception mode logic for iOS.
249+
* By deciding which interception mode should be enabled (Native or JavaScript).
236250
*/
237-
const checkNativeInterceptionForIOS = (config: InstabugConfig) => {
251+
const handleInterceptionModeForIOS = (config: InstabugConfig) => {
238252
if (config.networkInterceptionMode === NetworkInterceptionMode.native) {
239253
if (isNativeInterceptionFeatureEnabled) {
240254
shouldEnableNativeInterception = true;
255+
NetworkLogger.setEnabled(false); // insure JS interceptor is disabled
241256
} else {
242257
shouldEnableNativeInterception = false;
243258
NetworkLogger.setEnabled(true); // rollback to JS interceptor

0 commit comments

Comments
 (0)