Exception Data Related Interfaces
Setting Breadcrumbs
Developers can call the 'Breadcrumb' interface at any point in the application to set a point. When the application crashes, the SDK collects the breadcrumb information in the order of code execution and highlights it in the crash track to assist developers in understanding the code call logic during application crashes.
- Related Interface
/**
* @param breadcrumb:Custom information, up to 100 characters, supporting Chinese, English, numbers, underscores
*/
NBSAppAgent.leaveBreadcrumb(String breadcrumb);
- Code Example
public MyActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
NBSAppAgent.setLicenseKey("AppKey")
.start(this.getApplicationContext());
NBSAppAgent.leaveBreadcrumb("login MyActivity onCreate");
}
public void onResume() {
super.onResume();
NBSAppAgent.leaveBreadcrumb("login MyActivity onResume");
}
public void logginPressed(View view) {
NBSAppAgent.leaveBreadcrumb("login MyActivity logginPressed");
new LoginAsyncTask.execute();
}
public void onStop() {
super.onStop();
NBSAppAgent.leaveBreadcrumb("login MyActivity onStop");
}
}
Custom Information
When an application crashes, developers often need more information to collect the scene environment. They can call the 'Custom Information' interface to upload additional information to assist in analyzing crash issues. The collected custom information will be displayed in the 'Custom Information' section on the exception details page.
- Related Interface
/**
* A maximum of 10 pieces of additional information can be added, which will be uploaded with the crash.
* param key The key value
* param value The value, each piece of additional information supports up to 100 bytes
*/
NBSAppAgent.setUserCrashMessage(String key,String value);
- Code Example
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
NBSAppAgent.setLicenseKey("AppKey")
.start(this.getApplicationContext());
NBSAppAgent.setUserCrashMessage("Zhang San", "13700001234"); // Insert custom additional information at any point after initialization
}
Custom Log
Developers can use the Android logging system LogCat to collect and view system debug output information, investigate the application information when a bug occurs by printing out Log information, and upload custom Log logs through the TingYun App SDK.
- Related Interface
/**
* @param enable Set to true to upload LogCat logs upon crash
*/
NBSAppAgent.enableLogging(boolean enable)
- Code Example
NBSAppAgent.setLicenseKey("AppKey").enableLogging(true).start(this.getApplicationContext());
Custom Error
The 'Custom Error' interface can be used to collect developers' 'try / catch exceptions' and 'business errors' and display them in the 'Error' section of 'Exception Analysis' on the Tingyun platform, which can help developers collect exceptions and errors.
- Related Interface
/**
* @param message Cannot be null, up to 1024 bytes in length, exceeding will take the first 1024 bytes
* @param exception Uploading exception to get the stack trace when thrown, not passing will only get the stack trace when calling the interface, in a multi-threaded environment, only the stack trace of the thread calling the interface will be taken, the maximum stack depth is 100
* @param metaData The value supports Number, String, Array, Map types, up to 128k, exceeding will set metadata to: "metaData":{"error":"The size of metaData is greater than the maximum limit of 128K"}
*/
NBSAppAgent.reportError(String message, Exception e, Map<String, Object> metaData)
NBSAppAgent.reportError(String message, Map<String, Object> metaData);
- Code Example
try {
//...business code
} catch (Exception e) {
Map<String, Object> map = new HashMap<>();
map.put("Current Page", "Home Page");
NBSAppAgent.reportError("Exception occurred", e, map);
}
try {
//...business code
} catch (Exception e) {
Map<String, Object> map = new HashMap<>();
map.put("Current Page", "Home Page");
NBSAppAgent.reportError("Exception occurred", map);
}
Setting Exception Callback
After using the 'Exception Callback' interface, you can obtain the SDK-collected exception data 'crash, anr data' when a lag occurs or crash data is uploaded. Note: It needs to be called before the crash data is uploaded or a lag occurs 'the SDK will upload crash data after the server is successfully connected'. Do not perform time-consuming operations in the callback interface. Do not kill the process in the callback interface.
- Related Interface
/**
* @param type The type of exception that triggers the interface callback, 1 for crash, 2 for lag, 3 for both crash and lag
* @param feedback DataTypeCallBack The object of the callback interface implementation class
*/
NBSAppAgent.setDataTypeCallBack(int type, TingyunAnomalousDataFeedBack feedback)
- Code Example
NBSAppAgent.setDataTypeCallBack(3, new com.networkbench.agent.impl.instrumentation.TingyunAnomalousDataFeedBack() {
@Override
public void dataTypeFeedBack(com.networkbench.agent.impl.data.AnomalousData anomalousData) {
Log.e("TingYun","Exception thread is " + anomalousData.getThreadName() + ", stack trace is " + anomalousData.getAllStacktrace());
}
});