Flutter API Reference
Custom Network Requests
The Tingyun SDK automatically collects network data by setting HttpOverrides.global. Currently, it supports httpClient as well as dio and http network libraries based on HttpClient encapsulation.
If your project sets HttpOverrides, it will prevent the Tingyun SDK from collecting network data, and you'll need to manually instrument data collection.
- Related Interface
/*
@url:Complete URL of the network request
*/
TYWebRequestTiming timing = await Tingyun().createWebRequest(String url);// Create a network performance data entry
timing.start();// Start the request
/*
@code:Status code of the request
*/
timing.stop(int code);// Request completion
- 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 completion
return response;
});
Custom Start and End Points
The Tingyun SDK by default calculates the "cold start time" from SDK initialization to the end of the first page load. Developers can change the calculation of "cold start time" according to their application needs.
Project Requirements
-
Android Project: Collecting cold start (including first launch) data requires implementing a custom Application class.
-
iOS Project: Collecting launch data requires embedding in the main function.
Enable Custom Start Switch
The TingYun_SDK initialization needs to call the Related interface in the native part.
-
Android Interface
/*
@isCustom:Whether to enable custom start, default is false. Set to true to enable.
*/
NBSAppAgent.isCustomAppStart(boolean isCustom); -
iOS Interface
/**
Whether to enable custom start. Call before starting the SDK. Default is NO. Set to YES to enable.
*/
+ (void)customLanuchEnd:(BOOL)enable; -
Code Example
- Android Example
public class MyApplication extends Application {
@Override
public void onCreate() {
NBSAppAgent.setLicenseKey("AppKey")
.isCustomAppStart(true)//Call during SDK initialization to enable custom start time feature
.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]));
}
}
Setting Custom Start End Points
You need to enable the custom start switch. The custom start end point setting interface will only take effect when the custom start switch is set to true.
-
Related Interface
Tingyun().setCustomOnResumeEndIns();
-
Code Example
Widget build(BuildContext context) {
Tingyun().setCustomOnResumeEndIns();
return Scaffold(
body:Column(
crossAxisAlignment: CrossAxisAlignment.center,
.....
));
}
Custom User Operations
Supports collecting operation data through instrumentation, supporting both root and sub-trace levels. Note: Here two levels mean that sub-trace allows multiple traces, not just two.
-
Interface Restrictions
-
Operation data is recorded up to the root node.
-
Multiple sets of instrumentation root nodes cannot be called in parallel.
-
-
Related Interface
/*
@name:Operation 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" interface, you can collect "try/catch exceptions" and "business errors" and display them in the "Exception Analysis > Errors" section of the Tingyun platform, helping developers collect exceptions and errors.
- Related Interface
/*
@message:Cannot be empty, maximum length 1024 bytes, truncated to the first 1024 bytes if exceeded
@stackTrace:Fetch the stack when the exception is thrown
@props:The value supports Number, String, Array, Map types, with a maximum limit of 128k. If it exceeds the maximum limit, upload it as empty
*/
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"});
}
Setting User Identifier
Adding a user identifier allows you to retrieve specific user performance issues on the Tingyun reporting platform.
- Related Interface
/*
@userIdentifier:Contains up to 64 characters, truncated to the first 64 characters, supports Chinese, English, numbers, underscores, but cannot contain spaces or other escape characters
*/
Tingyun().setUserIdentifier(String userIdentifier);
- Code Example
Tingyun().setUserIdentifier("zhangsan@tingyun.com");
Recording User Paths (Breadcrumbs)
Developers can call the "breadcrumbs" interface for instrumentation at any location in the application. When the application crashes, the SDK collects breadcrumb information in the order of code triggers and highlights it in the crash trace to help developers understand the code call logic when the application crashes.
- Related Interface
/*
@breadcrumb:Custom information, containing up to 100 characters, truncated to the first 100 characters, supports Chinese, English, numbers, underscores
*/
Tingyun().leaveBreadcrumb(String breadcrumb);
- Code Example
Tingyun().leaveBreadcrumb("Add to Cart");
Custom Additional Information for Crashes
When an application crashes, developers often need more information to collect on-site environments. You can upload additional information through the "Custom Crash Additional Information" interface to assist in analyzing crash problems.
- Related Interface
/*
Only the latest 10 pieces of data are retained and uploaded with the crash
@key:key value
@value:value, maximum length limit 100, truncated to 100 if exceeded
*/
Tingyun().setUserCrashMessage(String key, String value);
- Code Example
Tingyun().setUserCrashMessage("Current Page", "Main");