Exception Data
Set Breadcrumb
Developers can call the "breadcrumb" interface anywhere in the application to add markers. When the application crashes, the SDK will collect the breadcrumb information in the order triggered by the code and highlight it in the crash trace to help developers understand the code call logic during a crash.
- Related interface
/**
* @param breadcrumb: Custom information, up to 100 characters, supports Chinese, English, numbers, and 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 on-site environment. You can upload additional information by calling the "custom information" interface to assist in analyzing crash issues. The collected custom information will be displayed in the "Custom Information" section of the exception details page.
- Related interface
/**
* You can add up to 10 additional pieces of information, which will be uploaded with the crash
* param key key value
* param value value, each 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 anywhere after initialization
}
Custom Log
Developers can use Android's LogCat system to collect and view system debug output information, investigate application information when bugs occur by printing Log information, and upload custom Log logs via the Tingyun App SDK.
- Related interface
/**
* @param enable Set to true to upload LogCat logs on crash
*/
NBSAppAgent.enableLogging(boolean enable)
- Code example
NBSAppAgent.setLicenseKey("AppKey").enableLogging(true).start(this.getApplicationContext());
Custom Error
Use the "custom error" interface to collect "try/catch exceptions" and "business errors" and display them in the "Error" section under "Exception Analysis" on the Tingyun platform. This helps developers collect exceptions and errors.
- Related interface
/**
* @param message Cannot be null, max length 1024 bytes, excess will be truncated
* @param exception If provided, uploads the stack trace at the time of the exception; if not, only the stack trace at the interface call is collected. In multithreaded scenarios, only the calling thread's stack trace is collected. Max stack depth is 100.
* @param metaData Value supports Number, String, Array, Map types, max 128k. If exceeded, metadata will be set to: {"error":"metaData size exceeds 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);
}
Set Exception Callback
After using the "exception callback" interface, you can obtain the exception data (crash, ANR data) collected by the SDK when an ANR occurs or crash data is uploaded. Note: Call this before crash upload or ANR occurs (the SDK will upload crash data after connecting to the server). Do not perform time-consuming operations in the callback interface. Do not kill the process in the callback interface.
- Related interface
/**
* @param type The exception type that triggers the callback: 1 for crash, 2 for ANR, 3 for both crash and ANR
* @param feedback DataTypeCallBack callback interface implementation
*/
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: " + anomalousData.getThreadName() + ", stack trace: " + anomalousData.getAllStacktrace());
}
});