Skip to content

Commit a9d0cec

Browse files
Merge remote-tracking branch 'origin/feat/network-spans-feature-flags' into feat/network-spans-filtering
# Conflicts: # examples/default/ios/InstabugExample.xcodeproj/project.pbxproj # examples/default/ios/Podfile # examples/default/ios/Podfile.lock # ios/RNInstabug/InstabugNetworkLoggerBridge.h # ios/RNInstabug/InstabugNetworkLoggerBridge.m # src/native/NativeNetworkLogger.ts
2 parents b7299d9 + b8ab1c4 commit a9d0cec

File tree

9 files changed

+181
-119
lines changed

9 files changed

+181
-119
lines changed

examples/default/ios/InstabugExample.xcodeproj/project.pbxproj

Lines changed: 74 additions & 78 deletions
Large diffs are not rendered by default.

examples/default/ios/Podfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ target 'InstabugExample' do
1818
# Flags change depending on the env values.
1919
flags = get_default_flags()
2020

21-
# pod 'Instabug', :podspec => 'https://ios-releases.instabug.com/custom/feature-support_cp_network_filtering_obfuscation-base/13.4.2/Instabug.podspec'
22-
pod 'Instabug', :podspec => 'https://ios-releases.instabug.com/custom/feature-support_cp_network_filtering_obfuscation-release/13.4.3/Instabug.podspec'
21+
pod 'Instabug', :podspec => 'https://ios-releases.instabug.com/custom/release-support_cp_network_filtering_obfuscation-add_reset_network_state/13.4.3/Instabug.podspec'
2322
use_react_native!(
2423
:path => config[:reactNativePath],
2524
# Hermes is now enabled by default. Disable by setting this flag to false.

examples/default/ios/Podfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ DEPENDENCIES:
524524
- FBReactNativeSpec (from `../node_modules/react-native/React/FBReactNativeSpec`)
525525
- glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`)
526526
- hermes-engine (from `../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec`)
527-
- Instabug (from `https://ios-releases.instabug.com/custom/feature-support_cp_network_filtering_obfuscation-release/13.4.3/Instabug.podspec`)
527+
- Instabug (from `https://ios-releases.instabug.com/custom/release-support_cp_network_filtering_obfuscation-add_reset_network_state/13.4.3/Instabug.podspec`)
528528
- instabug-reactnative-ndk (from `../node_modules/instabug-reactnative-ndk`)
529529
- libevent (~> 2.1.12)
530530
- OCMock
@@ -600,7 +600,7 @@ EXTERNAL SOURCES:
600600
:podspec: "../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec"
601601
:tag: hermes-2023-03-20-RNv0.72.0-49794cfc7c81fb8f69fd60c3bbf85a7480cc5a77
602602
Instabug:
603-
:podspec: https://ios-releases.instabug.com/custom/feature-support_cp_network_filtering_obfuscation-release/13.4.3/Instabug.podspec
603+
:podspec: https://ios-releases.instabug.com/custom/release-support_cp_network_filtering_obfuscation-add_reset_network_state/13.4.3/Instabug.podspec
604604
instabug-reactnative-ndk:
605605
:path: "../node_modules/instabug-reactnative-ndk"
606606
RCT-Folly:
@@ -706,7 +706,7 @@ SPEC CHECKSUMS:
706706
Google-Maps-iOS-Utils: f77eab4c4326d7e6a277f8e23a0232402731913a
707707
GoogleMaps: 032f676450ba0779bd8ce16840690915f84e57ac
708708
hermes-engine: 10fbd3f62405c41ea07e71973ea61e1878d07322
709-
Instabug: f582dcf7a4099acca604fa7ffa3bf4eda295317f
709+
Instabug: 12ea6990039094c48a7c7e8103ba8679c0833f5e
710710
instabug-reactnative-ndk: 960119a69380cf4cbe47ccd007c453f757927d17
711711
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
712712
OCMock: 589f2c84dacb1f5aaf6e4cec1f292551fe748e74
@@ -758,6 +758,6 @@ SPEC CHECKSUMS:
758758
SocketRocket: f32cd54efbe0f095c4d7594881e52619cfe80b17
759759
Yoga: 8796b55dba14d7004f980b54bcc9833ee45b28ce
760760

761-
PODFILE CHECKSUM: afd54e1cb156d7b63f6e1beca2ba1f66fa30be0f
761+
PODFILE CHECKSUM: c4e288aeafe746a77427798d0e33069c948e4b76
762762

763763
COCOAPODS: 1.15.2

examples/default/src/screens/apm/NetworkScreen.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Screen } from '../../components/Screen';
55
import { ClipboardTextInput } from '../../components/ClipboardTextInput';
66
import { useQuery } from 'react-query';
77
import { HStack, VStack } from 'native-base';
8-
import { gql, request } from 'graphql-request';
8+
import { gql, GraphQLClient } from 'graphql-request';
99
import { CustomButton } from '../../components/CustomButton';
1010
import axios from 'axios';
1111
import type { HomeStackParamList } from '../../navigation/HomeStack';
@@ -101,6 +101,12 @@ export const NetworkScreen: React.FC<
101101
}
102102

103103
const fetchGraphQlData = async () => {
104+
const client = new GraphQLClient('https://countries.trevorblades.com/graphql', {
105+
headers: {
106+
'ibg-graphql-header': 'AndrewQL', // change Query Name here
107+
},
108+
});
109+
104110
const document = gql`
105111
query {
106112
country(code: "EG") {
@@ -110,10 +116,7 @@ export const NetworkScreen: React.FC<
110116
}
111117
`;
112118

113-
return request<{ country: { emoji: string; name: string } }>(
114-
'https://countries.trevorblades.com/graphql',
115-
document,
116-
);
119+
return client.request<{ country: { emoji: string; name: string } }>(document);
117120
};
118121

119122
const { data, isError, isSuccess, isLoading, refetch } = useQuery('helloQuery', fetchGraphQlData);
@@ -127,7 +130,6 @@ export const NetworkScreen: React.FC<
127130
}
128131

129132
async function makeSequentialApiCalls(urls: string[]): Promise<any[]> {
130-
// const fetchPromises = urls.map((url) => fetch(url).then((response) => response.json()));
131133
const results: any[] = [];
132134

133135
try {
@@ -182,7 +184,7 @@ export const NetworkScreen: React.FC<
182184
title="Send Sequantail Requests"
183185
/>
184186

185-
<CustomButton onPress={() => refetch} title="Reload GraphQL" />
187+
<CustomButton onPress={() => refetch()} title="Reload GraphQL" />
186188
<View>
187189
{isLoading && <Text>Loading...</Text>}
188190
{isSuccess && <Text>GraphQL Data: {data.country.emoji}</Text>}

ios/RNInstabug/InstabugNetworkLoggerBridge.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,8 @@ typedef NS_ENUM(NSInteger, NetworkListenerType) {
3131
- (void) updateNetworkLogSnapshot: (NSString * _Nonnull)jsonString;
3232

3333
- (void) setNetworkLoggingRequestFilterPredicateIOS:(NSString * _Nonnull) callbackID : (BOOL)value;
34+
35+
- (void)forceStartNetworkLoggingIOS;
36+
37+
- (void)forceStopNetworkLoggingIOS;
3438
@end

ios/RNInstabug/InstabugNetworkLoggerBridge.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,14 @@ - (NSDictionary *)createNetworkRequestDictForRequest:(NSURLRequest *)request cal
212212
};
213213
}
214214

215+
RCT_EXPORT_METHOD(forceStartNetworkLoggingIOS) {
216+
[IBGNetworkLogger forceStartNetworkLogging];
217+
}
218+
219+
RCT_EXPORT_METHOD(forceStopNetworkLoggingIOS) {
220+
[IBGNetworkLogger forceStopNetworkLogging];
221+
}
222+
223+
224+
215225
@end

ios/RNInstabug/Util/IBGNetworkLogger+CP.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ NS_ASSUME_NONNULL_BEGIN
3030
timestamp:(NSNumber * _Nullable)timestamp
3131
generatedW3CTraceparent:(NSString * _Nullable)generatedW3CTraceparent
3232
caughtedW3CTraceparent:(NSString * _Nullable)caughtedW3CTraceparent;
33+
+ (void)forceStartNetworkLogging;
34+
+ (void)forceStopNetworkLogging;
3335

3436
+ (void)setCPRequestAsyncObfuscationHandler:(void (^)(NSURLRequest * requestToBeObfuscated, void (^ completion)(NSURLRequest * obfuscatedRequest)))asyncObfuscationHandler;
3537
+ (void)setCPRequestFilteringHandler:(void (^)(NSURLRequest * request, void (^completion)(BOOL keep)))requestFilteringHandler;

src/modules/Instabug.ts

Lines changed: 71 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,22 @@ function reportCurrentViewForAndroid(screenName: string | null) {
7373
}
7474

7575
function _logFlags() {
76-
console.log(
77-
`Andrew: init -> {
76+
if (Platform.OS === 'android') {
77+
console.log(
78+
`Andrew: APM Flags -> {
7879
isNativeInterceptionFeatureEnabled: ${isNativeInterceptionFeatureEnabled},
7980
hasAPMNetworkPlugin: ${hasAPMNetworkPlugin},
8081
shouldEnableNativeInterception: ${shouldEnableNativeInterception}
8182
}`,
82-
);
83+
);
84+
} else {
85+
console.log(
86+
`Andrew: APM Flags -> {
87+
isNativeInterceptionFeatureEnabled: ${isNativeInterceptionFeatureEnabled},
88+
shouldEnableNativeInterception: ${shouldEnableNativeInterception}
89+
}`,
90+
);
91+
}
8392
}
8493

8594
/**
@@ -101,19 +110,19 @@ export const init = async (config: InstabugConfig) => {
101110
// Add app state listener to handle background/foreground transitions
102111
addAppStateListener(async (nextAppState) => handleAppStateChange(nextAppState, config));
103112

113+
// Perform platform-specific checks and update interception mode
114+
handleNetworkInterceptionMode(config);
115+
116+
// Log the current APM network flags and initialize Instabug
117+
_logFlags();
118+
104119
//Set APM networking flags for the first time
105120
setApmNetworkFlagsIfChanged({
106121
isNativeInterceptionFeatureEnabled: isNativeInterceptionFeatureEnabled,
107122
hasAPMNetworkPlugin: hasAPMNetworkPlugin,
108123
shouldEnableNativeInterception: shouldEnableNativeInterception,
109124
});
110125

111-
// Perform platform-specific checks and update interception mode
112-
handleNetworkInterceptionMode(config);
113-
114-
// Log the current APM network flags and initialize Instabug
115-
_logFlags();
116-
117126
// call Instabug native init method
118127
initializeNativeInstabug(config);
119128

@@ -140,16 +149,20 @@ const handleAppStateChange = async (nextAppState: AppStateStatus, config: Instab
140149
// Checks if the app has come to the foreground
141150
if (['inactive', 'background'].includes(_currentAppState) && nextAppState === 'active') {
142151
// Update the APM network flags
143-
const updatedFlags = await fetchApmNetworkFlags();
144-
const isUpdated = setApmNetworkFlagsIfChanged(updatedFlags);
152+
const isUpdated = await fetchApmNetworkFlags();
145153

146154
if (isUpdated) {
155+
console.log('Andrew: App has come to the foreground!');
147156
console.log('Andrew: APM network flags updated.');
148157
handleNetworkInterceptionMode(config);
149-
initializeNativeInstabug(config);
158+
handleIOSNativeInterception(config);
159+
_logFlags();
160+
setApmNetworkFlagsIfChanged({
161+
isNativeInterceptionFeatureEnabled,
162+
hasAPMNetworkPlugin,
163+
shouldEnableNativeInterception,
164+
});
150165
}
151-
_logFlags();
152-
console.log('Andrew: App has come to the foreground!');
153166
}
154167

155168
_currentAppState = nextAppState;
@@ -160,16 +173,25 @@ const handleAppStateChange = async (nextAppState: AppStateStatus, config: Instab
160173
* Fetches the current APM network flags.
161174
*/
162175
const fetchApmNetworkFlags = async () => {
163-
isNativeInterceptionFeatureEnabled = await NativeNetworkLogger.isNativeInterceptionEnabled();
176+
let isUpdated = false;
177+
const newNativeInterceptionFeatureEnabled =
178+
await NativeNetworkLogger.isNativeInterceptionEnabled();
179+
if (isNativeInterceptionFeatureEnabled !== newNativeInterceptionFeatureEnabled) {
180+
isNativeInterceptionFeatureEnabled = newNativeInterceptionFeatureEnabled;
181+
isUpdated = true;
182+
}
164183
if (Platform.OS === 'android') {
165-
hasAPMNetworkPlugin = await NativeNetworkLogger.hasAPMNetworkPlugin();
184+
const newHasAPMNetworkPlugin = await NativeNetworkLogger.hasAPMNetworkPlugin();
185+
if (hasAPMNetworkPlugin !== newHasAPMNetworkPlugin) {
186+
hasAPMNetworkPlugin = newHasAPMNetworkPlugin;
187+
isUpdated = true;
188+
}
166189
}
167190

168-
return {
169-
isNativeInterceptionFeatureEnabled,
170-
hasAPMNetworkPlugin,
171-
shouldEnableNativeInterception,
172-
};
191+
console.log(
192+
`Andrew: fetchApmNetworkFlags {isNativeInterceptionFeatureEnabled: ${isNativeInterceptionFeatureEnabled}, hasAPMNetworkPlugin: ${hasAPMNetworkPlugin}}`,
193+
);
194+
return isUpdated;
173195
};
174196

175197
/**
@@ -195,7 +217,8 @@ const handleNetworkInterceptionMode = (config: InstabugConfig) => {
195217
};
196218

197219
/**
198-
* Handles the JS interception logic for Android.
220+
* Handles the network interception logic for Android if the user set
221+
* network interception mode with [NetworkInterceptionMode.javascript].
199222
*/
200223
function handleAndroidJSInterception() {
201224
if (isNativeInterceptionFeatureEnabled && hasAPMNetworkPlugin) {
@@ -207,7 +230,8 @@ function handleAndroidJSInterception() {
207230
}
208231

209232
/**
210-
* Handles the native interception logic for Android.
233+
* Handles the network interception logic for Android if the user set
234+
* network interception mode with [NetworkInterceptionMode.native].
211235
*/
212236
function handleAndroidNativeInterception() {
213237
if (isNativeInterceptionFeatureEnabled) {
@@ -231,7 +255,30 @@ function handleAndroidNativeInterception() {
231255
}
232256

233257
/**
234-
* Handles the interception mode logic for Android.
258+
* Control either to enable or disable the native interception logic for iOS.
259+
*/
260+
function handleIOSNativeInterception(config: InstabugConfig) {
261+
if (Platform.OS === 'ios') {
262+
console.log(
263+
`Andrew: handleIOSNativeInterception(${
264+
shouldEnableNativeInterception &&
265+
config.networkInterceptionMode === NetworkInterceptionMode.native
266+
})`,
267+
);
268+
269+
if (
270+
shouldEnableNativeInterception &&
271+
config.networkInterceptionMode === NetworkInterceptionMode.native
272+
) {
273+
NativeNetworkLogger.forceStartNetworkLoggingIOS(); // Enable native iOS automatic network logging.
274+
} else {
275+
NativeNetworkLogger.forceStopNetworkLoggingIOS(); // Disable native iOS automatic network logging.
276+
}
277+
}
278+
}
279+
280+
/**
281+
* Handles the network interception mode logic for Android.
235282
* By deciding which interception mode should be enabled (Native or JavaScript).
236283
*/
237284
const handleInterceptionModeForAndroid = (config: InstabugConfig) => {

src/native/NativeNetworkLogger.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,17 @@ export enum NetworkListenerType {
1010
export interface NetworkLoggerNativeModule extends NativeModule {
1111
isNativeInterceptionEnabled(): Promise<boolean>;
1212

13-
isAPMNetworkEnabled(): Promise<boolean>; // Android only
14-
15-
hasAPMNetworkPlugin(): Promise<boolean>; // Android only
16-
1713
registerNetworkLogsListener(type: NetworkListenerType): void;
1814

1915
updateNetworkLogSnapshot(networkData: string): void;
2016

17+
hasAPMNetworkPlugin(): Promise<boolean>; // Android only
18+
2119
setNetworkLoggingRequestFilterPredicateIOS(id: string, value: boolean): void; // iOS only
20+
21+
forceStartNetworkLoggingIOS(): void; // iOS only;
22+
23+
forceStopNetworkLoggingIOS(): void; // iOS only;
2224
}
2325

2426
export const NativeNetworkLogger = NativeModules.IBGNetworkLogger;

0 commit comments

Comments
 (0)