API Reference
Custom Network Requests
The Tingyun SDK automatically collects network data by setting HttpOverrides.global, currently supporting httpClient and network libraries based on HttpClient such as dio and http.
If your project sets HttpOverrides, it will prevent the Tingyun SDK from collecting network data, requiring manual instrumentation to collect data.
- Related APIs
/*
@url:Complete URL of the network request
*/
TYWebRequestTiming timing = await Tingyun().createWebRequest(String url);// Create a network performance data entry
timing.start();// Request start
/*
@code:Request status code
*/
timing.stop(int code);// Request end
- Code Example
var url = "https://www.tingyun.com";
TYWebRequestTiming timing = await Tingyun().createWebRequest(url);
timing.startWebRequestTiming();
var response = await http.get(url)
.then((response) {
timing.stop(response.statusCode);// Request end
return response;
});
Custom Launch Endpoint
The Tingyun SDK by default calculates the time from SDK initialization start to the first page load completion as "cold launch time". Developers can change the endpoint for calculating "cold launch time" based on their application requirements.
Project Requirements
-
Android project: Collecting cold launch (including first launch) data requires implementing a custom Application class.
-
iOS project: Collecting launch data requires code embedding in the main function.
Enable Custom Launch Switch
Need to call related APIs when initializing TingYun_SDK in the native part.
-
Android API
/*
@isCustom:Whether to enable custom launch, default false, set to true if needed
*/
NBSAppAgent.isCustomAppStart(boolean isCustom); -
iOS API
/**
Whether to enable custom launch, call before starting SDK, default NO, set to YES if needed
*/
+ (void)customLanuchEnd:(BOOL)enable; -
Code Examples
- Android Example
public class MyApplication extends Application {
@Override
public void onCreate() {
NBSAppAgent.setLicenseKey("AppKey")
.isCustomAppStart(true)//Call when initializing SDK to enable custom launch time functionality
.start(this.getApplicationContext());
}
}- iOS Example
int main(int argc, char* argv[]) {
@autoreleasepool {
[NBSAppAgent customLanuchEnd:YES];
[NBSAppAgent setRedirectURL:@"Dc_Redirect"];
[NBSAppAgent startWithAppID:@"AppKey"];
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
}
}
Set Custom Launch Endpoint
Need to enable the custom launch switch. When the custom launch switch is set to true, the custom launch endpoint API settings will take effect.
-
Related API
Tingyun().setCustomOnResumeEndIns(); -
Code Example
Widget build(BuildContext context) {
Tingyun().setCustomOnResumeEndIns();
return Scaffold(
body:Column(
crossAxisAlignment: CrossAxisAlignment.center,
.....
));
}
Custom User Actions
Supports collecting action data through instrumentation, supporting root and sub two-level traces (note: the two levels here refer to sub traces allowing multiple instances, not just two).
-
API Limitations
-
Action data ends when the root node ends.
-
Multiple instrumentation root nodes cannot cross-call.
-
-
Related APIs
/*
@name:Action name
*/
TingyunRootAction rootAction = Tingyun().enterAction(String name);//Create an action
/*
@name:Sub Action name
*/
TingyunAction subAction = rootAction.enterAction(String name);//Create a sub Action
subAction.leaveAction();//Sub Action complete
/*
@props:Additional information
@tag:Tag identifier
*/
rootAction.leaveAction({Map<String, dynamic> props, String tag = ""});//Action complete
- Code Example
TingyunRootAction rootAction = Tingyun().enterAction('my button enter');
TingyunAction subAction1 = rootAction.enterAction('sub1 button enter');
subAction1.leaveAction();
TingyunAction subAction2 = rootAction.enterAction('sub2 button enter');
subAction2.leaveAction();
rootAction.leaveAction(props:{"key1":"value1","key2":"value2"},tag: "tag");
Custom Errors
Using the "Custom Error" API can collect developers' "try / catch exceptions" and "business errors", and display them in the Tingyun platform's Exception Analysis > Errors, helping developers collect exceptions and errors.
- Related API
/*
@message:Cannot be empty, maximum length 1024 bytes, truncate first 1024 bytes if exceeded
@stackTrace:Upload exception to get the stack trace when thrown
@props:Value supports Number, String, Array, Map types, maximum limit 128k, upload empty if exceeded
*/
Tingyun().reportError(String message, String stackTrace, {Map<String, dynamic> props});
- Code Example
try {
throw new StateError('This is an async Dart exception.');
} catch (exception, stack) {
Tingyun().reportError(exception.toString(), stack.toString(),props: {"ke y1":"value1","key2":"value2"});
}
Set User Identifier
By adding a user identifier, you can search for specific users' performance issues in the Tingyun reporting platform using this identifier.
- Related API
/*
@userIdentifier:Maximum 64 characters, truncate first 64 characters if exceeded, supports Chinese, English, numbers, underscores, but cannot contain spaces or other escape characters
*/
Tingyun().setUserIdentifier(String userIdentifier);
- Code Example
Tingyun().setUserIdentifier("zhangsan@tingyun.com");
Record User Path (Breadcrumbs)
Developers can call the "breadcrumb" API for instrumentation at any location in the application. When the application crashes, the SDK will collect instrumentation information in the order of code execution and highlight it in the crash trace to help developers understand the code call logic when the application crashes.
- Related API
/*
@breadcrumb:Custom information, maximum 100 characters, truncate first 100 characters if exceeded, supports Chinese, English, numbers, underscores
*/
Tingyun().leaveBreadcrumb(String breadcrumb);
- Code Example
Tingyun().leaveBreadcrumb("Add to cart");
Custom Additional Information
When an application crashes, developers often need more information to collect the scene environment. They can upload additional information by calling the "Custom Crash Additional Information" API to assist in analyzing crash issues.
- Related API
/*
Only keeps the latest 10 pieces of data, uploaded with crash
@key:Key value
@value:Value, maximum length limit 100, truncate first 100 if exceeded
*/
Tingyun().setUserCrashMessage(String key, String value);
- Code Example
Tingyun().setUserCrashMessage("Current page", "Main");