Real User Monitoring (RUM) offers various configuration items for its software development kit (SDK) that you can set to meet your requirements. This topic describes the common SDK configuration items for Flutter applications.
Startup configuration
The start method is the core method for starting the AlibabaCloudRUM Flutter plugin. It initializes the plugin's monitoring system and starts the application.
Future<void> start(Widget topLevelWidget, {Function()? beforeRunApp}) asyncParameter | Description | Parameter limits | Result on failure |
topLevelWidget | The root widget of Flutter. | Not empty. | The API call fails. |
beforeRunApp | A callback function. It is invoked before | Optional. If this parameter is set, you must call | - |
Example:
AlibabaCloudRUM().start(
// The root widget
MyApp(),
beforeRunApp: () async => {
// Before this function ends, you must call the method below.
WidgetsFlutterBinding.ensureInitialized(),
// Other business logic
// ...
},
);Print error messages
By default, when the SDK catches a Flutter exception, it calls the FlutterError.dumpErrorToConsole method to output the error message to the console. You can use the setDumpError method to enable or disable this feature.
void setDumpError(bool enable)Parameter | Description | Parameter limits | Result on failure |
enable | Sets whether to output error messages to the console. | Valid values:
| - |
Example:
// Disable outputting error messages to the console.
AlibabaCloudRUM().setDumpError(false); Flutter error callback
Flutter does not propagate errors through monitoring layers. This means that after the AlibabaCloudRUM plugin monitors synchronous and asynchronous interfaces, the application's original error listeners stop working. To resolve this issue, the Flutter plugin provides a unified error callback interface.
void onRUMErrorCallback(bool callback(Object? error, StackTrace? stack, bool isAsync))Callback function input parameters
Parameter | Type | Description |
error | Object | The cause of the error. |
stack | StackTrace | Optional. The error stack. |
isAsync | Bool | Optional. Specifies whether the error is asynchronous. |
Callback function return value
Type | Description |
Bool | Specifies whether to continue processing the error.
|
Example:
AlibabaCloudRUM().onRUMErrorCallback((error, stack, isAsync) {
// Handle the error event.
// ...
// logger.d('debuggg error: $error, stack: $stack');
// Return true to let the SDK report the error.
return true;
});Read the device ID
The SDK generates a deviceId by default. You can retrieve the device ID using the getDeviceId interface.
Future<String?> getDeviceId() asyncExample:
AlibabaCloudRUM().getDeviceId().then(((value) => {print("deviceId: ${value}")}));Custom username
The SDK lets you set user-related information. This helps you associate data analytics with actual users.
Future<void> setUserName(String userName)Parameter | Description | Parameter limits | Result on failure |
userName | The username identifier. | The string can be null or empty. The string must be 256 characters or less. It cannot contain special characters. Only digits, letters, colons (:), spaces, forward slashes (/), underscores (_), hyphens (-), periods (.), and at signs (@) are allowed. | The API call fails. The current setting is invalid. |
Example:
AlibabaCloudRUM().setUserName("xxxxx");Custom user extension information
The SDK lets you set user-related information. This helps you associate data analytics with actual users.
Set user extension information. This method works in overwrite mode. Calling this method overwrites any previously set user extension information.
Future<void> setUserExtraInfo(Map<String, dynamic> extraInfo) asyncParameter
Description
Parameter limits
Result on failure
extraInfo
User extension information.
The Map can be null or empty. After conversion to JSON, the length must be within 7,000 characters. Otherwise, the API call fails.
The API call fails. The current setting is invalid.
Example:
AlibabaCloudRUM().setUserExtraInfo({"shopId": "xxxxx", "shopName": "yyyyy"});Append user extension information. This method works in append mode.
Future<void> addUserExtraInfo(Map<String, dynamic> extraInfo) asyncParameter
Description
Parameter limits
Result on failure
extraInfo
User extension information.
The Map can be null or empty. After conversion to JSON, the length must be within 7,000 characters. Otherwise, the API call fails.
The API call fails. The current setting is invalid.
Example:
AlibabaCloudRUM().addUserExtraInfo({"userId": "11111111"});
Custom global extension information
The SDK lets you set global information. This helps you add context to all reported data.
Set global extension information. This method works in overwrite mode. Calling this method overwrites any previously set global extension information.
Future<void> setExtraInfo(Map<String, dynamic> extraInfo) asyncParameter
Description
Parameter limits
Result on failure
extraInfo
Global extension information.
The Map can be null or empty. After conversion to JSON, the length must be within 7,000 characters. Otherwise, the API call fails.
The API call fails. The current setting is invalid.
Example:
AlibabaCloudRUM().setExtraInfo({"global_key": "global_value", "global_key2": "global_value2"});Append global extension information. This method works in append mode.
Future<void> addExtraInfo(Map<String, dynamic> extraInfo) asyncParameter
Description
Parameter limits
Result on failure
extraInfo
Global extension information.
The Map can be null or empty. After conversion to JSON, the length must be within 7,000 characters. Otherwise, the API call fails.
The API call fails. The current setting is invalid.
Example:
AlibabaCloudRUM().addExtraInfo({"global_userId": "2222222222"});
Custom Exception
You can call the custom exception interface and pass the required parameters. This lets you collect statistics on custom exception data.
Future<void> setCustomException(String exceptionType, String causedBy, String errorDump)Parameter | Description | Parameter limits | Result on failure |
exceptionType | Exception type (Required). | The string length must be between 1 and 256 characters. | The API call fails and the setting is invalid. |
causedBy | Cause of the exception (Required). | The string must be 512 characters or less. Longer strings are truncated. | Not applicable. |
errorDump | Exception information (Optional). | The string can be null or empty. The string must be 10,000 characters or less. Longer strings are truncated. | Not applicable. |
Example:
AlibabaCloudRUM().setCustomException("custom exception type",
"caused by customer",
"Custom error dump");Custom events
The SDK supports reporting custom events. You can call the corresponding interface and pass the required parameters to collect statistics on custom event data.
Future<void> setCustomEvent(String name, {String? group, String? snapshots, double? value, Map<String, String>? attributes})Parameter | Description | Parameter limits | Result on failure |
name | Event name (Required). | The string must be 512 characters or less. Longer strings are truncated. | The API call fails and the setting is invalid. |
group | Event group (Optional). | The string can be null or empty. The string must be 256 characters or less. Longer strings are truncated. | Not applicable. |
snapshots | Event snapshot (Optional). | The string can be null or empty. The string must be 7,000 characters or less. Longer strings are truncated. | Not applicable. |
value | Event value (Optional). | Data type: Double. | Not applicable. |
attributes | Key-value storage information (Optional). | After being converted to a JSON string, the length must not exceed 7,000 characters. | Not applicable. |
Example:
AlibabaCloudRUM().setCustomEvent("search_shop",
group: "shop",
snapshots: 'Search: ${search.toString()}',
value: 1,
attributes: {"search": "xxxxx"});Custom logs
The SDK supports reporting custom log information. You can call the corresponding interface and pass the required parameters to collect statistics on custom log data.
Future<void> setCustomLog(String logInfo, {String? name, String? snapshots, String? level, Map<String, String>? attributes})Parameter | Description | Parameter limits | Result on failure |
logInfo | Log information (Required). | The string length must be between 1 and 10,000 characters. Longer strings are truncated. | The API call fails and the setting is invalid. |
name | Log name (Optional). | The string length must be between 1 and 256 characters. | Not applicable. |
snapshots | Log snapshot (Optional). | The string can be null or empty. The string must be 7,000 characters or less. Longer strings are truncated. | Not applicable. |
level | Log level (Optional). | The string length must be between 1 and 256 characters. The default value is INFO. | Not applicable. |
attributes | Additional log information (Optional). | The Map can be null or empty. The length of the string after JSON conversion is counted towards the size limit of logInfo. The API call fails if this limit is exceeded. | Not applicable. |
Example:
AlibabaCloudRUM().setCustomLog("2024-08-20 14:00:05 Print shopinfo info.",
name: "shop",
snapshots: 'Shop: ${shop.toString()}',
level: "DEBUG",
attributes: {"shopId": "xxxxx", "shopName": "yyyyy"});