Skip to content

Commit a34fafc

Browse files
kholood-eaahmedAlaaInstabug
authored andcommitted
feat: migrate w3c flags to APM core
1 parent ec23cfa commit a34fafc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1150
-543
lines changed

.circleci/config.yml

Lines changed: 220 additions & 123 deletions
Large diffs are not rendered by default.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Distribution
22
dist/
33
bin/
4+
upload/*
5+
!upload/package.json
46

57
# NodeJS
68
node_modules/

CHANGELOG.md

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
# Changelog
22

3-
## [Unreleased](https://github.com/Instabug/Instabug-React-Native/compare/v13.2.0...dev)
3+
## [Unreleased](https://github.com/Instabug/Instabug-React-Native/compare/v13.3.0...dev)
4+
5+
### Added
6+
7+
- Add support for Expo Router navigation tracking ([#1270](https://github.com/Instabug/Instabug-React-Native/pull/1270)).
8+
9+
## [13.3.0](https://github.com/Instabug/Instabug-React-Native/compare/v13.2.0...v13.3.0) (August 4, 2024)
10+
11+
### Added
12+
13+
- Add support for Feature Flags APIs `Instabug.addFeatureFlags`, `Instabug.removeFeatureFlags` and `Instabug.clearAllFeatureFlags` ([#1230](https://github.com/Instabug/Instabug-React-Native/pull/1230)).
14+
- Export `uploadSourcemaps` and `uploadSoFiles` utilities in the `instabug-reactnative/upload` sub-package for usage in custom Node.js upload scripts ([#1252](https://github.com/Instabug/Instabug-React-Native/pull/1252)).
15+
16+
### Changed
17+
18+
- Bump Instabug Android SDK to v13.3.0 ([#1261](https://github.com/Instabug/Instabug-React-Native/pull/1261)). [See release notes](https://github.com/Instabug/Instabug-Android/releases/tag/v13.3.0).
19+
- Bump Instabug iOS SDK to v13.3.0 ([#1262](https://github.com/Instabug/Instabug-React-Native/pull/1262)). [See release notes](https://github.com/Instabug/Instabug-iOS/releases/tag/13.3.0).
20+
21+
### Deprecated
22+
23+
- Deprecate Experiments APIs `Instabug.addExperiments`, `Instabug.removeExperiments` and `Instabug.clearAllExperiments` in favor of the new Feature Flags APIs ([#1230](https://github.com/Instabug/Instabug-React-Native/pull/1230)).
424

525
### Fixed
626

@@ -59,8 +79,20 @@
5979
- Bump Instabug iOS SDK to v13.0.0 ([#1189](https://github.com/Instabug/Instabug-React-Native/pull/1189)). [See release notes](https://github.com/instabug/instabug-ios/releases/tag/13.0.0).
6080
- Bump Instabug Android SDK to v13.0.0 ([#1188](https://github.com/Instabug/Instabug-React-Native/pull/1188)). [See release notes](https://github.com/Instabug/android/releases/tag/v13.0.0).
6181

82+
<<<<<<< HEAD
83+
6284
## [12.9.0](https://github.com/Instabug/Instabug-React-Native/compare/v12.8.0...v12.9.0) (April 2, 2024)
6385

86+
=======
87+
88+
### Deprecated
89+
90+
- Deprecate Execution Traces APIs `APM.startExecutionTrace`, `Trace.end` and `Trace.setAttribute` in favor of the new App Flows APIs ([#1138](https://github.com/Instabug/Instabug-React-Native/pull/1138)).
91+
92+
## [12.9.0](https://github.com/Instabug/Instabug-React-Native/compare/v12.8.0...12.9.0)(April 2, 2024)
93+
94+
> > > > > > > origin/dev
95+
6496
### Added
6597

6698
- Adds symbol files upload script ([#1137](https://github.com/Instabug/Instabug-React-Native/pull/1137))
@@ -71,10 +103,6 @@
71103

72104
- Deprecate execution traces APIs `APM.startExecutionTrace`, `Trace.end` and `Trace.setFlowAttribute` in favor of the new app flow APIs ([#1138](https://github.com/Instabug/Instabug-React-Native/pull/1138)).
73105

74-
### Deprecated
75-
76-
- Deprecate Execution Traces APIs `APM.startExecutionTrace`, `Trace.end` and `Trace.setAttribute` in favor of the new App Flows APIs ([#1138](https://github.com/Instabug/Instabug-React-Native/pull/1138)).
77-
78106
### Changed
79107

80108
- Bump Instabug Android SDK to v12.9.0 ([#1168](https://github.com/Instabug/Instabug-React-Native/pull/1168)). [See release notes](https://github.com/Instabug/android/releases/tag/v12.9.0).

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ android {
5757
minSdkVersion getExtOrDefault('minSdkVersion').toInteger()
5858
targetSdkVersion getExtOrDefault('targetSdkVersion').toInteger()
5959
versionCode 1
60-
versionName "13.2.0"
60+
versionName "13.3.0"
6161
multiDexEnabled true
6262
ndk {
6363
abiFilters "armeabi-v7a", "x86"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<manifest package="com.instabug.reactlibrary"
1+
<manifest
22
xmlns:android="http://schemas.android.com/apk/res/android">
33

44
</manifest>

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,10 @@ private void networkLogAndroid(final double requestStartTime,
330330
@Nullable final String errorDomain,
331331
@Nullable final ReadableMap w3cAttributes,
332332
@Nullable final String gqlQueryName,
333-
@Nullable final String serverErrorMessage) {
333+
@Nullable final String serverErrorMessage
334+
) {
334335
try {
335336
APMNetworkLogger networkLogger = new APMNetworkLogger();
336-
337337
final boolean hasError = errorDomain != null && !errorDomain.isEmpty();
338338
final String errorMessage = hasError ? errorDomain : null;
339339

@@ -363,13 +363,12 @@ private void networkLogAndroid(final double requestStartTime,
363363
w3cAttributes.getString("w3cGeneratedHeader"),
364364
w3cAttributes.getString("w3cCaughtHeader")
365365
);
366-
367366
try {
368367
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);
369368
if (method != null) {
370369
method.invoke(
371370
networkLogger,
372-
(long) requestStartTime,
371+
(long) requestStartTime * 1000,
373372
(long) requestDuration,
374373
requestHeaders,
375374
requestBody,

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

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.facebook.react.bridge.ReactApplicationContext;
1818
import com.facebook.react.bridge.ReactMethod;
1919
import com.facebook.react.bridge.ReadableArray;
20+
import com.facebook.react.bridge.ReadableMap;
2021
import com.facebook.react.bridge.WritableArray;
2122
import com.facebook.react.bridge.WritableMap;
2223
import com.facebook.react.bridge.WritableNativeArray;
@@ -36,6 +37,7 @@
3637
import com.instabug.library.internal.crossplatform.CoreFeaturesState;
3738
import com.instabug.library.internal.crossplatform.FeaturesStateListener;
3839
import com.instabug.library.internal.crossplatform.InternalCore;
40+
import com.instabug.library.featuresflags.model.IBGFeatureFlag;
3941
import com.instabug.library.internal.module.InstabugLocale;
4042
import com.instabug.library.invocation.InstabugInvocationEvent;
4143
import com.instabug.library.logging.InstabugLog;
@@ -48,6 +50,7 @@
4850
import com.instabug.reactlibrary.utils.MainThreadHandler;
4951

5052
import com.instabug.reactlibrary.utils.RNTouchedViewExtractor;
53+
5154
import org.json.JSONException;
5255
import org.json.JSONObject;
5356
import org.json.JSONTokener;
@@ -57,6 +60,7 @@
5760
import java.util.ArrayList;
5861
import java.util.Arrays;
5962
import java.util.HashMap;
63+
import java.util.Iterator;
6064
import java.util.List;
6165
import java.util.Locale;
6266
import java.util.Map;
@@ -1030,6 +1034,9 @@ public void run() {
10301034
});
10311035
}
10321036

1037+
/**
1038+
* @deprecated see @link #addFeatureFlags(ReadableArray)
1039+
*/
10331040
@ReactMethod
10341041
public void addExperiments(final ReadableArray experiments) {
10351042
MainThreadHandler.runOnMainThread(new Runnable() {
@@ -1046,6 +1053,9 @@ public void run() {
10461053
});
10471054
}
10481055

1056+
/**
1057+
* @deprecated see {@link #removeFeatureFlags(ReadableArray)}
1058+
*/
10491059
@ReactMethod
10501060
public void removeExperiments(final ReadableArray experiments) {
10511061
MainThreadHandler.runOnMainThread(new Runnable() {
@@ -1062,6 +1072,9 @@ public void run() {
10621072
});
10631073
}
10641074

1075+
/**
1076+
* @deprecated see {@link #removeAllFeatureFlags()}
1077+
*/
10651078
@ReactMethod
10661079
public void clearAllExperiments() {
10671080
MainThreadHandler.runOnMainThread(new Runnable() {
@@ -1076,6 +1089,59 @@ public void run() {
10761089
});
10771090
}
10781091

1092+
@ReactMethod
1093+
public void addFeatureFlags(final ReadableMap featureFlagsMap) {
1094+
MainThreadHandler.runOnMainThread(new Runnable() {
1095+
@Override
1096+
public void run() {
1097+
try {
1098+
Iterator<Map.Entry<String, Object>> iterator = featureFlagsMap.getEntryIterator();
1099+
ArrayList<IBGFeatureFlag> featureFlags = new ArrayList<>();
1100+
while (iterator.hasNext()) {
1101+
Map.Entry<String, Object> item = iterator.next();
1102+
String variant = (String) item.getValue();
1103+
String name = item.getKey();
1104+
featureFlags.add(new IBGFeatureFlag(name, variant.isEmpty() ? null : variant));
1105+
}
1106+
if (!featureFlags.isEmpty()) {
1107+
Instabug.addFeatureFlags(featureFlags);
1108+
}
1109+
} catch (Exception e) {
1110+
e.printStackTrace();
1111+
}
1112+
}
1113+
});
1114+
}
1115+
1116+
@ReactMethod
1117+
public void removeFeatureFlags(final ReadableArray featureFlags) {
1118+
MainThreadHandler.runOnMainThread(new Runnable() {
1119+
@Override
1120+
public void run() {
1121+
try {
1122+
ArrayList<String> stringArray = ArrayUtil.parseReadableArrayOfStrings(featureFlags);
1123+
Instabug.removeFeatureFlag(stringArray);
1124+
} catch (Exception e) {
1125+
e.printStackTrace();
1126+
}
1127+
}
1128+
});
1129+
}
1130+
1131+
@ReactMethod
1132+
public void removeAllFeatureFlags() {
1133+
MainThreadHandler.runOnMainThread(new Runnable() {
1134+
@Override
1135+
public void run() {
1136+
try {
1137+
Instabug.removeAllFeatureFlags();
1138+
} catch (Exception e) {
1139+
e.printStackTrace();
1140+
}
1141+
}
1142+
});
1143+
}
1144+
10791145
@ReactMethod
10801146
public void willRedirectToStore() {
10811147
MainThreadHandler.runOnMainThread(new Runnable() {

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

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.instabug.library.ReproMode;
2121
import com.instabug.library.internal.crossplatform.CoreFeature;
2222
import com.instabug.library.internal.crossplatform.InternalCore;
23+
import com.instabug.library.featuresflags.model.IBGFeatureFlag;
2324
import com.instabug.library.internal.module.InstabugLocale;
2425
import com.instabug.library.ui.onboarding.WelcomeMessage;
2526
import com.instabug.reactlibrary.utils.MainThreadHandler;
@@ -40,6 +41,7 @@
4041
import java.lang.reflect.Method;
4142
import java.util.ArrayList;
4243
import java.util.HashMap;
44+
import java.util.Iterator;
4345
import java.util.List;
4446
import java.util.Locale;
4547
import java.util.Map;
@@ -569,8 +571,6 @@ public void testIdentifyUserWithId() {
569571

570572
@Test
571573
public void given$clearAllExperiments_whenQuery_thenShouldCallNativeApi() {
572-
// given
573-
574574
// when
575575
rnModule.clearAllExperiments();
576576

@@ -579,6 +579,56 @@ public void testIdentifyUserWithId() {
579579
Instabug.clearAllExperiments();
580580
}
581581

582+
@Test
583+
public void testAddFeatureFlags() {
584+
// given
585+
JavaOnlyMap map = new JavaOnlyMap();
586+
map.putString("key1", "value1");
587+
map.putString("key2", "value2");
588+
589+
// when
590+
rnModule.addFeatureFlags(map);
591+
592+
// then
593+
Iterator<Map.Entry<String, Object>> iterator = map.getEntryIterator();
594+
ArrayList<IBGFeatureFlag> featureFlags = new ArrayList<>();
595+
while (iterator.hasNext()) {
596+
Map.Entry<String, Object> item = iterator.next();
597+
featureFlags.add(new IBGFeatureFlag(item.getKey(), (String) item.getValue()));
598+
}
599+
600+
mockInstabug.verify(() -> Instabug.addFeatureFlags(featureFlags));
601+
602+
}
603+
604+
@Test
605+
public void testRemoveFeatureFlags() {
606+
// given
607+
JavaOnlyArray array = new JavaOnlyArray();
608+
array.pushString("exp1");
609+
array.pushString("exp2");
610+
611+
// when
612+
rnModule.removeFeatureFlags(array);
613+
614+
// then
615+
List<String> expectedList = new ArrayList<String>();
616+
for (Object o : array.toArrayList()) {
617+
expectedList.add((String) o);
618+
}
619+
mockInstabug.verify(() -> Instabug.removeFeatureFlag(expectedList));
620+
621+
}
622+
623+
@Test
624+
public void testRemoveAllFeatureFlags() {
625+
// when
626+
rnModule.removeAllFeatureFlags();
627+
628+
// then
629+
mockInstabug.verify(() -> Instabug.removeAllFeatureFlags());
630+
}
631+
582632
@Test
583633
public void testWillRedirectToStore() {
584634
// when

0 commit comments

Comments
 (0)