[6.4.4]去除APM,替换为自研抓取上传崩溃日志
This commit is contained in:
@@ -54,8 +54,6 @@ dependencies {
|
||||
|
||||
implementation rootProject.ext.dependencies.arouter
|
||||
kapt rootProject.ext.dependencies.aroutercompiler
|
||||
implementation rootProject.ext.dependencies.apm_insight_crash
|
||||
implementation rootProject.ext.dependencies.apm_insight
|
||||
|
||||
if (Boolean.valueOf(USE_MAVEN_PACKAGE)) {
|
||||
api rootProject.ext.dependencies.crashreport
|
||||
|
||||
@@ -4,12 +4,6 @@ import android.content.Context;
|
||||
import android.util.Log;
|
||||
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.apm.insight.ExitType;
|
||||
import com.apm.insight.MonitorCrash;
|
||||
import com.apm.insight.log.VLog;
|
||||
import com.bytedance.apm.insight.ApmInsight;
|
||||
import com.bytedance.apm.insight.ApmInsightAgent;
|
||||
import com.bytedance.apm.insight.ApmInsightInitConfig;
|
||||
import com.mogo.commons.constants.SharedPrefsConstants;
|
||||
import com.mogo.commons.debug.DebugConfig;
|
||||
import com.mogo.eagle.core.data.app.AppConfigInfo;
|
||||
@@ -70,241 +64,18 @@ public class ApmCrashReportProvider implements ITestCrashReportProvider {
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.doOnNext(isDebug -> {
|
||||
initCrash(context, isDebug);
|
||||
initApmInsight(context, isDebug);
|
||||
}).subscribe();
|
||||
.subscribe();
|
||||
|
||||
}
|
||||
|
||||
private void initCrash(final Context context, boolean isDebug) {
|
||||
MonitorCrash.Config config =
|
||||
MonitorCrash.Config
|
||||
.app(isDebug ? BYTEAMP_APPID_DEV : BYTEAMP_APPID)
|
||||
.token(isDebug ? BYTEAMP_AppToken_DEV : BYTEAMP_AppToken)// 设置鉴权token,可从平台应用信息处获取,token错误无法上报数据
|
||||
.versionCode(CommonUtils.getVersionCode(context))// 可选,默认取PackageInfo中的versionCode
|
||||
.versionName(CommonUtils.getVersionName(context))// 可选,默认取PackageInfo中的versionName
|
||||
.channel(FunctionBuildConfig.appIdentityMode)// 可选,设置App发布渠道,在平台可以筛选
|
||||
// .url("www.xxx.com")// 默认不需要,私有化部署才配置上报地址
|
||||
//可选,可以设置自定义 did,不设置会使用内部默认的
|
||||
.dynamicParams(new MonitorCrash.Config.IDynamicParams() {
|
||||
@Override
|
||||
public String getDid() {//返回空会使用内部默认的did
|
||||
String sn = SharedPrefsMgr.getInstance().getString("sn");
|
||||
if (sn != null && !sn.isEmpty()) {
|
||||
return sn;
|
||||
} else {
|
||||
return DeviceUtils.getDeviceSN().isEmpty() ? null : DeviceUtils.getDeviceSN();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUserId() {
|
||||
return DeviceUtils.getDeviceSN();
|
||||
}
|
||||
})
|
||||
//应用崩溃后会执行这里,可选,添加业务自定义数据,在崩溃详情页->现场数据展示->自定义数据
|
||||
.customData(crashType -> {
|
||||
//车辆所在位置
|
||||
mCityCode = SharedPrefsMgr.getInstance().getString(SharedPrefsConstants.LOCATION_CITY_CODE);
|
||||
mLat = SharedPrefsMgr.getInstance().getString(SharedPrefsConstants.LOCATION_LATITUDE);
|
||||
mLogt = SharedPrefsMgr.getInstance().getString(SharedPrefsConstants.LOCATION_LONGITUDE);
|
||||
//车辆信息
|
||||
String carInfoString = SharedPrefsMgr.getInstance().getString(SharedPrefsConstants.CAR_INFO);
|
||||
if (carInfoString != null && !carInfoString.isEmpty()) {
|
||||
mInfo = GsonUtils.fromJson(carInfoString, CarInfo.class);
|
||||
}
|
||||
|
||||
//======================================== 自定义维度值 begin========================================
|
||||
HashMap<String, String> dimension = new HashMap<>();
|
||||
// dimension.put("Devices_SN_DeviceId", sn + "__" + DeviceUtils.getDeviceSN());
|
||||
// dimension.put("Devices_SN_WidevineID_MD5", sn + "__" + DeviceIdUtils.getWidevineIDWithMd5(context));
|
||||
// dimension.put("Devices_SN_WidevineID", sn + "__" + DeviceIdUtils.getWidevineID(context));
|
||||
//************************************* APP构建的信息 ***********************************************
|
||||
// Git版本信息
|
||||
dimension.put("GIT_BRANCH", AppConfigInfo.INSTANCE.getWorkingBranchName());
|
||||
dimension.put("GIT_HASH", AppConfigInfo.INSTANCE.getWorkingBranchHash());
|
||||
// 地图版本
|
||||
dimension.put("APP_MAP_SDK_VERSION", DebugConfig.getMapVersion());
|
||||
// 渠道信息
|
||||
dimension.put("APP_CHANNEL", FunctionBuildConfig.appIdentityMode);
|
||||
// 车辆类型
|
||||
dimension.put("APP_CAR_TYPE", AppIdentityModeUtils.INSTANCE.getBuildCarType(FunctionBuildConfig.appIdentityMode));
|
||||
//************************************* APP构建的信息 ***********************************************
|
||||
|
||||
//************************************* 与车辆连接的 IPC(工控机)、OBU 等信息 ***********************************************
|
||||
// 连接的OBU 状态
|
||||
dimension.put("OBU_CONNECT_STATUS", "" + AppConfigInfo.INSTANCE.isConnectObu());
|
||||
// 车牌号,从工控机获取的数据
|
||||
dimension.put("IPC_PLATE_NUMBER", AppConfigInfo.INSTANCE.getPlateNumber());
|
||||
// 连接的工控机 状态
|
||||
dimension.put("IPC_CONNECT_STATUS", "" + AppConfigInfo.INSTANCE.isConnectAutopilot());
|
||||
// 连接的工控机 MAC地址
|
||||
dimension.put("IPC_MAC", AppConfigInfo.INSTANCE.getIPCMacAddress());
|
||||
// 连接的工控机 Docker版本
|
||||
dimension.put("IPC_MAP_VERSION", AppConfigInfo.INSTANCE.getDockerVersion());
|
||||
// 连接的工控机 Protocol版本
|
||||
dimension.put("IPC_MAP_PROTOCOL_VERSION", "" + AppConfigInfo.INSTANCE.getProtocolVersionNumber());
|
||||
//************************************* 与车辆连接的 IPC(工控机)、OBU 等信息 ***********************************************
|
||||
|
||||
//************************************* 位置信息 ***********************************************
|
||||
// 城市信息
|
||||
dimension.put("LOCATION_CITY_CODE", mCityCode);
|
||||
dimension.put("LOCATION_LATITUDE", mLat);
|
||||
dimension.put("LOCATION_LONGITUTE", mLogt);
|
||||
//************************************* 位置信息 ***********************************************
|
||||
|
||||
//************************************* CMDB绑定的信息 ***********************************************
|
||||
if (mInfo != null) {
|
||||
dimension.put("CMDB_PLATE_NUMBER", mInfo.getNumber_plate());
|
||||
dimension.put("CMDB_BRAND", mInfo.getBrand());
|
||||
dimension.put("CMDB_MODEL", mInfo.getModel());
|
||||
}
|
||||
//************************************* CMDB绑定的信息 ***********************************************
|
||||
|
||||
HashMap<String, Double> metric = new HashMap<>();
|
||||
//指标值
|
||||
//metric.put("Devices_ID_metric", (double) 100);
|
||||
ApmInsightAgent.monitorEvent("Devices_ID_EVENT", dimension, metric);
|
||||
//======================================== 自定义维度值 end========================================
|
||||
|
||||
|
||||
//===================================== 自定义收集一些信息,在崩溃详情页->现场数据展示->自定义数据 begin========================================
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
|
||||
//************************************* APP构建的信息 ***********************************************
|
||||
// Git版本信息
|
||||
map.put("GIT_BRANCH", AppConfigInfo.INSTANCE.getWorkingBranchName());
|
||||
map.put("GIT_HASH", AppConfigInfo.INSTANCE.getWorkingBranchHash());
|
||||
// 地图版本
|
||||
map.put("APP_MAP_SDK_VERSION", DebugConfig.getMapVersion());
|
||||
// 渠道信息
|
||||
map.put("APP_CHANNEL", FunctionBuildConfig.appIdentityMode);
|
||||
// 车辆类型
|
||||
map.put("APP_CAR_TYPE", AppIdentityModeUtils.INSTANCE.getBuildCarType(FunctionBuildConfig.appIdentityMode));
|
||||
//************************************* APP构建的信息 ***********************************************
|
||||
|
||||
//************************************* 与车辆连接的 IPC(工控机)、OBU 等信息 ***********************************************
|
||||
// 连接的OBU 状态
|
||||
map.put("OBU_CONNECT_STATUS", "" + AppConfigInfo.INSTANCE.isConnectObu());
|
||||
// 车牌号,从工控机获取的数据
|
||||
map.put("IPC_PLATE_NUMBER", AppConfigInfo.INSTANCE.getPlateNumber());
|
||||
// 连接的工控机 状态
|
||||
map.put("IPC_CONNECT_STATUS", "" + AppConfigInfo.INSTANCE.isConnectAutopilot());
|
||||
// 连接的工控机 MAC地址
|
||||
map.put("IPC_MAC", AppConfigInfo.INSTANCE.getIPCMacAddress());
|
||||
// 连接的工控机 Docker版本
|
||||
map.put("IPC_MAP_VERSION", AppConfigInfo.INSTANCE.getDockerVersion());
|
||||
// 连接的工控机 Protocol版本
|
||||
map.put("IPC_MAP_PROTOCOL_VERSION", "" + AppConfigInfo.INSTANCE.getProtocolVersionNumber());
|
||||
//************************************* 与车辆连接的 IPC(工控机)、OBU 等信息 ***********************************************
|
||||
|
||||
//************************************* 位置信息 ***********************************************
|
||||
// 城市信息
|
||||
map.put("LOCATION_CITY_CODE", mCityCode);
|
||||
map.put("LOCATION_LATITUDE", mLat);
|
||||
map.put("LOCATION_LONGITUTE", mLogt);
|
||||
//************************************* 位置信息 ***********************************************
|
||||
|
||||
|
||||
//************************************* CMDB绑定的信息 ***********************************************
|
||||
if (mInfo != null) {
|
||||
CallerLogger.d(TAG, "nuber = " + mInfo.getNumber_plate() + "--brand = " + mInfo.getBrand() + "--modle = " + mInfo.getModel());
|
||||
map.put("CMDB_PLATE_NUMBER", mInfo.getNumber_plate());
|
||||
map.put("CMDB_BRAND", mInfo.getBrand());
|
||||
map.put("CMDB_MODEL", mInfo.getModel());
|
||||
}
|
||||
//************************************* CMDB绑定的信息 ***********************************************
|
||||
|
||||
return map;
|
||||
//===================================== 自定义收集一些信息,在崩溃详情页->现场数据展示->自定义数据 end========================================
|
||||
})
|
||||
// 可选,添加pv事件的自定义tag,可以用来筛选崩溃率计算的分母数据
|
||||
//.pageViewTags(<<Map<String, String>>>)
|
||||
.exitType(ExitType.ALL) // 上报应用退出原因
|
||||
.crashProtect(true) // 开启崩溃防护
|
||||
.build();
|
||||
MonitorCrash monitorCrash = MonitorCrash.init(context, config);
|
||||
}
|
||||
|
||||
/**
|
||||
* ApmInsight性能监控初始化
|
||||
*/
|
||||
private void initApmInsight(Context context, boolean isDebug) {
|
||||
ApmInsightInitConfig.Builder builder = ApmInsightInitConfig.builder();
|
||||
//设置分配的appid
|
||||
builder.aid(isDebug ? BYTEAMP_APPID_DEV : BYTEAMP_APPID);
|
||||
//设置分配的AppToken
|
||||
builder.token(isDebug ? BYTEAMP_AppToken_DEV : BYTEAMP_AppToken);
|
||||
//是否开启卡顿功能
|
||||
builder.blockDetect(true);
|
||||
//是否开启严重卡顿功能
|
||||
builder.seriousBlockDetect(true);
|
||||
//是否开启流畅性和丢帧
|
||||
builder.fpsMonitor(true);
|
||||
//控制是否打开WebVeiw监控
|
||||
builder.enableWebViewMonitor(true);
|
||||
//控制是否打开内存监控
|
||||
builder.memoryMonitor(true);
|
||||
//控制是否打开电量监控
|
||||
builder.batteryMonitor(true);
|
||||
//控制是否打开CPU监控
|
||||
builder.cpuMonitor(true);
|
||||
//控制是否打开磁盘监控
|
||||
builder.diskMonitor(true);
|
||||
//控制是否打开流量监控
|
||||
builder.trafficMonitor(true);
|
||||
//是否打印日志,注:线上release版本要配置为false
|
||||
builder.debugMode(true);
|
||||
//支持用户自定义user_id把平台数据和自己用户关联起来,可以不配置
|
||||
// builder.userId(MoGoAiCloudClientConfig.getInstance().getSn());
|
||||
//私有化部署:配置数据上报的域名 (私有化部署才需要配置,内部有默认域名),测试支持设置http://www.xxx.com 默认是https协议
|
||||
// builder.defaultReportDomain("www.xxx.com");
|
||||
//设置渠道。1.3.16版本增加接口
|
||||
builder.channel(FunctionBuildConfig.appIdentityMode);
|
||||
//打开自定义日志回捞能力,1.4.1版本新增接口
|
||||
builder.enableLogRecovery(true);
|
||||
//设置数据和Rangers Applog数据打通,设备标识did必填。1.3.16版本增加接口
|
||||
// builder.setDynamicParams(new IDynamicParams() {
|
||||
// @Override
|
||||
// public String getUserUniqueID() {
|
||||
// //可选。依赖AppLog可以通过AppLog.getUserUniqueID()获取,否则可以返回null。
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String getAbSdkVersion() {
|
||||
// //可选。如果依赖AppLog可以通过AppLog.getAbSdkVersion()获取,否则可以返回null。
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String getSsid() {
|
||||
// //可选。依赖AppLog可以通过AppLog.getSsid()获取,否则可以返回null。
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public String getDid() {
|
||||
// //1.4.0版本及以上,可选,其他版本必填。设备的唯一标识,如果依赖AppLog可以通过 AppLog.getDid() 获取,也可以自己生成。
|
||||
// return AppLog.getDid();
|
||||
// }
|
||||
// });
|
||||
ApmInsight.getInstance().init(context, builder.build());
|
||||
//初始化自定日志,配置自定义日志最大占用磁盘,内部一般配置20,代表最大20M磁盘占用。1.4.1版本开始存在这个api
|
||||
VLog.init(context, 50);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean uploadVlog(long startTime, long endTime) {
|
||||
AtomicBoolean result = new AtomicBoolean(false);
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
ApmInsightAgent.uploadVlog(startTime, endTime, (success, msg) -> {
|
||||
Log.d(TAG, "--- uploadVlog callback ---:" + success + ", msg:" + msg);
|
||||
result.set(success);
|
||||
latch.countDown();
|
||||
});
|
||||
try {
|
||||
latch.await();
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
Reference in New Issue
Block a user