Skip to content

Commit 6d0460f

Browse files
chore: add the feature flag logic
1 parent 8869a82 commit 6d0460f

File tree

9 files changed

+371
-65
lines changed

9 files changed

+371
-65
lines changed

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

Lines changed: 87 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import org.json.JSONException;
2121
import org.json.JSONObject;
22+
2223
import java.lang.reflect.InvocationTargetException;
2324
import java.lang.reflect.Method;
2425

@@ -58,6 +59,7 @@ public void run() {
5859

5960
/**
6061
* Enables or disables APM.
62+
*
6163
* @param isEnabled boolean indicating enabled or disabled.
6264
*/
6365
@ReactMethod
@@ -76,6 +78,7 @@ public void run() {
7678

7779
/**
7880
* Enables or disables app launch tracking.
81+
*
7982
* @param isEnabled boolean indicating enabled or disabled.
8083
*/
8184
@ReactMethod
@@ -111,6 +114,7 @@ public void run() {
111114

112115
/**
113116
* Enables or disables auto UI tracing
117+
*
114118
* @param isEnabled boolean indicating enabled or disabled.
115119
*/
116120
@ReactMethod
@@ -209,7 +213,6 @@ public void run() {
209213
* Starts an execution trace
210214
*
211215
* @param name string name of the trace.
212-
*
213216
* @deprecated see {@link #startFlow(String)}
214217
*/
215218
@Deprecated
@@ -240,7 +243,6 @@ public void run() {
240243
* @param id String id of the trace.
241244
* @param key attribute key
242245
* @param value attribute value. Null to remove attribute
243-
*
244246
* @deprecated see {@link #setFlowAttribute}
245247
*/
246248
@Deprecated
@@ -262,7 +264,6 @@ public void run() {
262264
* Ends a trace
263265
*
264266
* @param id string id of the trace.
265-
*
266267
* @deprecated see {@link #endFlow}
267268
*/
268269
@Deprecated
@@ -282,6 +283,7 @@ public void run() {
282283

283284
/**
284285
* Starts a UI trace
286+
*
285287
* @param name string name of the UI trace.
286288
*/
287289
@ReactMethod
@@ -341,34 +343,95 @@ private void networkLogAndroid(final double requestStartTime,
341343
try {
342344
Method method = getMethod(Class.forName("com.instabug.apm.networking.APMNetworkLogger"), "log", long.class, long.class, String.class, String.class, long.class, String.class, String.class, String.class, String.class, String.class, long.class, int.class, String.class, String.class, String.class, String.class, APMCPNetworkLog.W3CExternalTraceAttributes.class);
343345
if (method != null) {
344-
method.invoke(
345-
networkLogger,
346-
(long) requestStartTime * 1000,
347-
(long) requestDuration,
348-
requestHeaders,
349-
requestBody,
350-
(long) requestBodySize,
351-
requestMethod,
352-
requestUrl,
353-
requestContentType,
354-
responseHeaders,
355-
responseBody,
356-
(long)responseBodySize,
357-
(int) statusCode,
358-
responseContentType,
359-
errorMessage,
360-
gqlQueryName,
361-
serverErrorMessage,
362-
null
363-
);
346+
method.invoke(
347+
networkLogger,
348+
(long) requestStartTime * 1000,
349+
(long) requestDuration,
350+
requestHeaders,
351+
requestBody,
352+
(long) requestBodySize,
353+
requestMethod,
354+
requestUrl,
355+
requestContentType,
356+
responseHeaders,
357+
responseBody,
358+
(long) responseBodySize,
359+
(int) statusCode,
360+
responseContentType,
361+
errorMessage,
362+
gqlQueryName,
363+
serverErrorMessage,
364+
null
365+
);
364366
} else {
365367
Log.e("IB-CP-Bridge", "APMNetworkLogger.log was not found by reflection");
366368
}
367369
} catch (Throwable e) {
368370
e.printStackTrace();
369371
}
370-
} catch(Throwable e) {
372+
} catch (Throwable e) {
371373
e.printStackTrace();
372374
}
373375
}
376+
377+
/**
378+
* Get first time Value of [cp_native_interception_enabled] flag
379+
*/
380+
@ReactMethod
381+
public void isNativeInterceptionEnabled(Promise promise) {
382+
MainThreadHandler.runOnMainThread(new Runnable() {
383+
@Override
384+
public void run() {
385+
try {
386+
promise.resolve(true);
387+
} catch (Exception e) {
388+
e.printStackTrace();
389+
promise.resolve(false);
390+
}
391+
392+
}
393+
});
394+
}
395+
396+
/**
397+
* Indicate if user added APM Network plugin or not
398+
* [true] means user added the APM plugin
399+
* [false] means not
400+
*/
401+
@ReactMethod
402+
public void hasAPMNetworkPlugin(Promise promise) {
403+
MainThreadHandler.runOnMainThread(new Runnable() {
404+
@Override
405+
public void run() {
406+
try {
407+
promise.resolve(false);
408+
} catch (Exception e) {
409+
e.printStackTrace();
410+
promise.resolve(false);
411+
}
412+
413+
}
414+
});
415+
}
416+
417+
/**
418+
* Indicate APM is enabled & Network logging is enabled
419+
* [true] ApmEnabled && NetworkEnabled
420+
* [false] otherwise
421+
*/
422+
@ReactMethod
423+
public void isAPMNetworkEnabled(Promise promise) {
424+
MainThreadHandler.runOnMainThread(new Runnable() {
425+
@Override
426+
public void run() {
427+
try {
428+
promise.resolve(false);
429+
} catch (Exception e) {
430+
e.printStackTrace();
431+
promise.resolve(false);
432+
}
433+
434+
}
435+
});
436+
}
374437
}

examples/default/ios/Podfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ PODS:
4343
- RCT-Folly (= 2021.07.22.00)
4444
- React-Core
4545
- libevent (2.1.12)
46-
- OCMock (3.9.3)
46+
- OCMock (3.9.4)
4747
- RCT-Folly (2021.07.22.00):
4848
- boost
4949
- DoubleConversion
@@ -707,7 +707,7 @@ SPEC CHECKSUMS:
707707
Instabug: 4f26295103a330ec0236918359eef7ccaa74e2fa
708708
instabug-reactnative-ndk: 960119a69380cf4cbe47ccd007c453f757927d17
709709
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
710-
OCMock: 300b1b1b9155cb6378660b981c2557448830bdc6
710+
OCMock: 589f2c84dacb1f5aaf6e4cec1f292551fe748e74
711711
RCT-Folly: 424b8c9a7a0b9ab2886ffe9c3b041ef628fd4fb1
712712
RCTRequired: a2faf4bad4e438ca37b2040cb8f7799baa065c18
713713
RCTTypeSafety: cb09f3e4747b6d18331a15eb05271de7441ca0b3
@@ -758,4 +758,4 @@ SPEC CHECKSUMS:
758758

759759
PODFILE CHECKSUM: 281036e04bd4b9e7c2cc03a503b3245d3f1dd0dd
760760

761-
COCOAPODS: 1.12.0
761+
COCOAPODS: 1.15.2

examples/default/src/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Instabug, {
77
CrashReporting,
88
InvocationEvent,
99
LogLevel,
10+
NetworkInterceptionMode,
1011
ReproStepsMode,
1112
} from 'instabug-reactnative';
1213
import { NativeBaseProvider } from 'native-base';
@@ -26,6 +27,7 @@ export const App: React.FC = () => {
2627
token: 'deb1910a7342814af4e4c9210c786f35',
2728
invocationEvents: [InvocationEvent.floatingButton],
2829
debugLogsLevel: LogLevel.verbose,
30+
networkInterceptionMode: NetworkInterceptionMode.native,
2931
});
3032
CrashReporting.setNDKCrashesEnabled(true);
3133

ios/RNInstabug/InstabugAPMBridge.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ - (id) init
109109
[IBGAPM endUITrace];
110110
}
111111

112+
// Get first-time value of [cp_native_interception_enabled] flag
113+
RCT_EXPORT_METHOD(isNativeInterceptionEnabled:(RCTPromiseResolveBlock)resolve
114+
rejecter:(RCTPromiseRejectBlock)reject) {
115+
@try {
116+
// Assuming you want to return YES for now, wrapped in NSNumber
117+
resolve(@(YES));
118+
119+
120+
} @catch (NSError *error) {
121+
reject(@"error_code", @"An error occurred", error);
122+
}
123+
}
112124

113125
@synthesize description;
114126

0 commit comments

Comments
 (0)