Skip to content

Commit a542b26

Browse files
Merge pull request #201 from Instabug/feature/apm
2 parents 77fce9d + c623ff4 commit a542b26

26 files changed

+1045
-69
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060

6161
flutter_tests:
6262
docker:
63-
- image: cirrusci/flutter
63+
- image: cirrusci/flutter:2.2.3
6464
steps:
6565
- checkout
6666
- run: sudo gem install bundler:1.16.1

.github/issue_template.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!--
2+
Please fill in the template below when creating an issue
3+
to help us reproduce it and fix it faster.
4+
5+
While not required, including a sample project that reproduces
6+
your issue will help us a lot.
7+
-->
8+
9+
### Steps to Reproduce the Problem
10+
11+
### Expected Behavior
12+
13+
### Actual Behavior
14+
15+
### Instabug integration code
16+
<!--Make sure to remove your app token.-->
17+
18+
### SDK Version
19+
<!--Which version of Instabug Flutter are you on?.-->
20+
21+
### Flutter, iOS and Android Versions
22+
23+
### Device Model
24+
<!--If this issue is happening on specific devices, please mention them.-->
25+
26+
### [Optional] Project That Reproduces the Issue
27+
<!--While not required, providing a sample project that reproduces the issue you're having will help us solve it much faster.-->
28+

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## v10.8.0 (2021-09-13)
2+
3+
* Introduces Instabug's new App Performance Monitoring (APM)
4+
5+
16
## v10.0.1 (2021-08-25)
27

38
* Fixes an issue with http client logger.

android/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ buildscript {
88
}
99

1010
dependencies {
11-
classpath 'com.android.tools.build:gradle:3.2.1'
11+
classpath 'com.android.tools.build:gradle:3.5.4'
1212
}
1313
}
1414

@@ -34,6 +34,6 @@ android {
3434
}
3535
}
3636
dependencies {
37-
implementation 'com.instabug.library:instabug:10.8.1'
37+
implementation 'com.instabug.library:instabug:10.9.0'
3838
testImplementation 'junit:junit:4.12'
3939
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
zipStoreBase=GRADLE_USER_HOME
4+
zipStorePath=wrapper/dists
5+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip

android/src/main/java/com/instabug/instabugflutter/ArgsRegistry.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.instabug.library.InstabugCustomTextPlaceHolder;
88
import com.instabug.library.extendedbugreport.ExtendedBugReport;
99
import com.instabug.library.visualusersteps.State;
10+
import com.instabug.apm.model.LogLevel;
1011

1112
import java.util.HashMap;
1213
import java.util.Locale;
@@ -60,6 +61,7 @@ final class ArgsRegistry {
6061
registerInstabugExtendedBugReportModeArgs(ARGS);
6162
registerInstabugActionTypesArgs(ARGS);
6263
registerReproStepsModeArgs(ARGS);
64+
registerLogLevelArgs(ARGS);
6365
}
6466

6567
/**
@@ -217,4 +219,13 @@ static void registerReproStepsModeArgs(Map<String, Object> args) {
217219
args.put("ReproStepsMode.enabledWithNoScreenshots",State.ENABLED_WITH_NO_SCREENSHOTS);
218220
}
219221

222+
static void registerLogLevelArgs(Map<String, Object> args) {
223+
args.put("logLevelNone", LogLevel.NONE);
224+
args.put("logLevelError", LogLevel.ERROR);
225+
args.put("logLevelWarning", LogLevel.WARNING);
226+
args.put("logLevelInfo", LogLevel.INFO);
227+
args.put("logLevelDebug", LogLevel.DEBUG);
228+
args.put("logLevelVerbose", LogLevel.VERBOSE);
229+
}
230+
220231
}

android/src/main/java/com/instabug/instabugflutter/InstabugFlutterPlugin.java

Lines changed: 224 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
import android.os.Looper;
88
import android.util.Log;
99

10+
import com.instabug.apm.APM;
11+
import com.instabug.apm.model.ExecutionTrace;
12+
import com.instabug.apm.networking.APMNetworkLogger;
1013
import com.instabug.bug.BugReporting;
1114
import com.instabug.bug.invocation.Option;
1215
import com.instabug.chat.Chats;
@@ -64,6 +67,7 @@ public class InstabugFlutterPlugin implements MethodCallHandler {
6467
final public static String INVOCATION_EVENT_SHAKE = "InvocationEvent.shake";
6568

6669
private InstabugCustomTextPlaceHolder placeHolder = new InstabugCustomTextPlaceHolder();
70+
HashMap<String, ExecutionTrace> traces = new HashMap<String, ExecutionTrace>();
6771

6872
static MethodChannel channel;
6973

@@ -106,14 +110,14 @@ public void onMethodCall(MethodCall call, Result result) {
106110
}
107111
}
108112

109-
private void setCrossPlatform() {
113+
private void setCurrentPlatform() {
110114
try {
111-
Method method = getMethod(Class.forName("com.instabug.library.Instabug"), "setCrossPlatform", int.class);
115+
Method method = getMethod(Class.forName("com.instabug.library.Instabug"), "setCurrentPlatform", int.class);
112116
if (method != null) {
113-
Log.i("IB-CP-Bridge", "invoking setCrossPlatform with platform: " + Platform.FLUTTER);
117+
Log.i("IB-CP-Bridge", "invoking setCurrentPlatform with platform: " + Platform.FLUTTER);
114118
method.invoke(null, Platform.FLUTTER);
115119
} else {
116-
Log.e("IB-CP-Bridge", "setCrossPlatform was not found by reflection");
120+
Log.e("IB-CP-Bridge", "setCurrentPlatform was not found by reflection");
117121
}
118122
} catch (Exception e) {
119123
e.printStackTrace();
@@ -129,7 +133,7 @@ private void setCrossPlatform() {
129133
* @param invocationEvents invocationEvents The events that invoke the SDK's UI.
130134
*/
131135
public void start(Application application, String token, ArrayList<String> invocationEvents) {
132-
setCrossPlatform();
136+
setCurrentPlatform();
133137
InstabugInvocationEvent[] invocationEventsArray = new InstabugInvocationEvent[invocationEvents.size()];
134138
for (int i = 0; i < invocationEvents.size(); i++) {
135139
String key = invocationEvents.get(i);
@@ -138,8 +142,6 @@ public void start(Application application, String token, ArrayList<String> invoc
138142
new Instabug.Builder(application, token).setInvocationEvents(invocationEventsArray).build();
139143
enableScreenShotByMediaProjection();
140144

141-
// Temporarily disabling APM
142-
APM.setEnabled(false);
143145
}
144146

145147
/**
@@ -422,6 +424,15 @@ public void setSessionProfilerEnabled(boolean sessionProfilerEnabled) {
422424
}
423425
}
424426

427+
/**
428+
* Enable/disable SDK logs
429+
*
430+
* @param debugEnabled desired state of debug mode
431+
*/
432+
public void setDebugEnabled(boolean debugEnabled) {
433+
Instabug.setDebugEnabled(debugEnabled);
434+
}
435+
425436
/**
426437
* Set the primary color that the SDK will use to tint certain UI elements in
427438
* the SDK
@@ -897,7 +908,7 @@ public void networkLog(HashMap<String, Object> jsonObject) throws JSONException
897908
(new JSONObject((HashMap<String, String>) jsonObject.get("requestHeaders"))).toString(4));
898909
networkLog.setResponseHeaders(
899910
(new JSONObject((HashMap<String, String>) jsonObject.get("responseHeaders"))).toString(4));
900-
networkLog.setTotalDuration(((Number) jsonObject.get("duration")).longValue());
911+
networkLog.setTotalDuration(((Number) jsonObject.get("duration")).longValue() / 1000);
901912
networkLog.insert();
902913
}
903914

@@ -938,6 +949,211 @@ public void run() {
938949
});
939950
}
940951

952+
/**
953+
* Enables and disables everything related to APM feature.
954+
*
955+
* @param {boolean} isEnabled
956+
*/
957+
public void setAPMEnabled(final boolean isEnabled) {
958+
new Handler(Looper.getMainLooper()).post(new Runnable() {
959+
@Override
960+
public void run() {
961+
try {
962+
APM.setEnabled(isEnabled);
963+
} catch (Exception e) {
964+
e.printStackTrace();
965+
}
966+
}
967+
});
968+
}
969+
970+
/**
971+
* Sets the printed logs priority. Filter to one of the following levels.
972+
*
973+
* @param {String} logLevel.
974+
*/
975+
public void setAPMLogLevel(final String logLevel) {
976+
new Handler(Looper.getMainLooper()).post(new Runnable() {
977+
@Override
978+
public void run() {
979+
try {
980+
if (ArgsRegistry.getDeserializedValue(logLevel, Integer.class) == null) {
981+
return;
982+
}
983+
APM.setLogLevel((int) ArgsRegistry.getRawValue(logLevel));
984+
} catch (Exception e) {
985+
e.printStackTrace();
986+
}
987+
}
988+
});
989+
}
990+
991+
/**
992+
* Enables or disables cold app launch tracking.
993+
* @param isEnabled boolean indicating enabled or disabled.
994+
*/
995+
public void setColdAppLaunchEnabled(final boolean isEnabled) {
996+
new Handler(Looper.getMainLooper()).post(new Runnable() {
997+
@Override
998+
public void run() {
999+
try {
1000+
APM.setAppLaunchEnabled(isEnabled);
1001+
} catch (Exception e) {
1002+
e.printStackTrace();
1003+
}
1004+
}
1005+
});
1006+
}
1007+
/**
1008+
* Starts an execution trace
1009+
* @param name string name of the trace.
1010+
*/
1011+
public void startExecutionTrace(final String name, final String id) {
1012+
new Handler(Looper.getMainLooper()).post(new Runnable() {
1013+
@Override
1014+
public void run() {
1015+
try {
1016+
String result = null;
1017+
ExecutionTrace trace = APM.startExecutionTrace(name);
1018+
if (trace != null) {
1019+
result = id;
1020+
traces.put(id, trace);
1021+
}
1022+
channel.invokeMethod("startExecutionTraceCallBack", result);
1023+
} catch (Exception e) {
1024+
e.printStackTrace();
1025+
}
1026+
}
1027+
});
1028+
}
1029+
1030+
/**
1031+
* Sets an execution trace attribute
1032+
* @param id string id of the trace.
1033+
* @param key string key of the attribute.
1034+
* @param value string value of the attribute.
1035+
*/
1036+
public void setExecutionTraceAttribute(final String id, final String key, final String value) {
1037+
new Handler(Looper.getMainLooper()).post(new Runnable() {
1038+
@Override
1039+
public void run() {
1040+
try {
1041+
traces.get(id).setAttribute(key, value);
1042+
} catch (Exception e) {
1043+
e.printStackTrace();
1044+
}
1045+
}
1046+
});
1047+
}
1048+
1049+
/**
1050+
* Ends an execution trace
1051+
* @param id string id of the trace.
1052+
*/
1053+
public void endExecutionTrace(final String id) {
1054+
new Handler(Looper.getMainLooper()).post(new Runnable() {
1055+
@Override
1056+
public void run() {
1057+
try {
1058+
traces.get(id).end();
1059+
} catch (Exception e) {
1060+
e.printStackTrace();
1061+
}
1062+
}
1063+
});
1064+
}
1065+
1066+
/**
1067+
* Enables or disables auto UI tracing
1068+
* @param isEnabled boolean indicating enabled or disabled.
1069+
*/
1070+
public void setAutoUITraceEnabled(final boolean isEnabled) {
1071+
new Handler(Looper.getMainLooper()).post(new Runnable() {
1072+
@Override
1073+
public void run() {
1074+
try {
1075+
APM.setAutoUITraceEnabled(isEnabled);
1076+
} catch (Exception e) {
1077+
e.printStackTrace();
1078+
}
1079+
}
1080+
});
1081+
}
1082+
1083+
/**
1084+
* Starts a UI trace
1085+
* @param name string name of the UI trace.
1086+
*/
1087+
public void startUITrace(final String name) {
1088+
new Handler(Looper.getMainLooper()).post(new Runnable() {
1089+
@Override
1090+
public void run() {
1091+
try {
1092+
APM.startUITrace(name);
1093+
} catch (Exception e) {
1094+
e.printStackTrace();
1095+
}
1096+
}
1097+
});
1098+
}
1099+
1100+
/**
1101+
* Ends the current running UI trace
1102+
*/
1103+
public void endUITrace() {
1104+
new Handler(Looper.getMainLooper()).post(new Runnable() {
1105+
@Override
1106+
public void run() {
1107+
try {
1108+
APM.endUITrace();
1109+
} catch (Exception e) {
1110+
e.printStackTrace();
1111+
}
1112+
}
1113+
});
1114+
}
1115+
1116+
public void apmNetworkLogByReflection(HashMap<String, Object> jsonObject) throws JSONException {
1117+
APMNetworkLogger apmNetworkLogger = new APMNetworkLogger();
1118+
final String requestUrl = (String) jsonObject.get("url");
1119+
final String requestBody = (String) jsonObject.get("requestBody");
1120+
final String responseBody = (String) jsonObject.get("responseBody");
1121+
final String requestMethod = (String) jsonObject.get("method");
1122+
//--------------------------------------------
1123+
final String requestContentType = (String) jsonObject.get("contentType");
1124+
final String responseContentType = (String) jsonObject.get("responseContentType");
1125+
//--------------------------------------------
1126+
final String errorDomain = (String) jsonObject.get("errorDomain");
1127+
final Integer statusCode = (Integer) jsonObject.get("responseCode");
1128+
final long requestDuration = ((Number) jsonObject.get("duration")).longValue() / 1000;
1129+
final long requestStartTime = ((Number) jsonObject.get("startTime")).longValue() * 1000;
1130+
final String requestHeaders = (new JSONObject((HashMap<String, String>) jsonObject.get("requestHeaders"))).toString(4);
1131+
final String responseHeaders = (new JSONObject((HashMap<String, String>) jsonObject.get("responseHeaders"))).toString(4);
1132+
final String errorMessage;
1133+
1134+
if(errorDomain.equals("")) {
1135+
errorMessage = null;
1136+
} else {
1137+
errorMessage = errorDomain;
1138+
}
1139+
1140+
try {
1141+
Method method = getMethod(Class.forName("com.instabug.apm.networking.APMNetworkLogger"), "log", long.class, long.class, String.class, String.class, String.class, String.class, String.class, String.class, String.class, int.class, String.class, String.class);
1142+
if (method != null) {
1143+
method.invoke(apmNetworkLogger, requestStartTime, requestDuration, requestHeaders, requestBody, requestMethod, requestUrl, requestContentType, responseHeaders, responseBody, statusCode, responseContentType, errorMessage);
1144+
} else {
1145+
Log.e("IB-CP-Bridge", "apmNetworkLogByReflection was not found by reflection");
1146+
}
1147+
} catch (ClassNotFoundException e) {
1148+
e.printStackTrace();
1149+
} catch (IllegalAccessException e) {
1150+
e.printStackTrace();
1151+
} catch (InvocationTargetException e) {
1152+
e.printStackTrace();
1153+
}
1154+
1155+
}
1156+
9411157
/*
9421158
*
9431159
* Reports that the screen has been

0 commit comments

Comments
 (0)