RUM Configuration¶
RUM Initialization Configuration¶
| Field | Type | Required | Description |
|---|---|---|---|
| androidAppId | String | Yes | The app_id for the Android platform, applied for in the RUM console |
| iOSAppId | String | Yes | The app_id for the iOS platform, applied for in the RUM console |
| sampleRate | double | No | Sampling rate, value range [0,1]. 0 means no collection, 1 means full collection. Default is 1. Scope is all View, Action, LongTask, Error data under the same session_id |
| sessionOnErrorSampleRate | double | No | Error collection rate. When a session is not sampled by sampleRate, if an error occurs during the session, data from the 1 minute before the error can be collected. Value range [0,1], default is 0 |
| enableUserResource | bool | No | Whether to enable automatic Flutter http Resource capture, default false. Implemented by modifying HttpOverrides.global. If the project has customization needs, inherit FTHttpOverrides |
| enableNativeUserAction | bool | No | Whether to track Native Action, default false |
| enableNativeUserView | bool | No | Whether to enable automatic Native View tracking. Recommended to turn off for pure Flutter applications, default false |
| enableNativeUserViewInFragment | bool | No | Whether to automatically track Native Fragment type page data, default false, only supports Android |
| enableNativeUserResource | bool | No | Whether to enable automatic Native Resource tracking. Recommended to turn off for pure Flutter applications, default false |
| enableAppUIBlock | bool | No | Whether to enable automatic Native Freeze tracking, default false |
| nativeUiBlockDurationMS | int | No | Sets the time threshold for Native Freeze, value range [100, ), unit milliseconds. iOS default 250ms, Android default 1000ms |
| enableTrackNativeAppANR | bool | No | Whether to enable Native ANR monitoring, default false |
| enableTrackNativeCrash | bool | No | Whether to enable Android Java Crash and OC/C/C++ crash monitoring, default false |
| errorMonitorType | enum ErrorMonitorType | No | Sets auxiliary monitoring information, adds additional monitoring data to RUM Error data. Default is off |
| deviceMetricsMonitorType | enum DeviceMetricsMonitorType | No | Adds performance monitoring data within the View cycle, default is off |
| detectFrequency | enum DetectFrequency | No | View performance monitoring sampling frequency, default DetectFrequency.normal |
| globalContext | Map | No | Custom global parameters. For adding rules, refer to Conflict Field Description |
| rumCacheDiscard | enum | No | Discard policy: FTRUMCacheDiscard.discard discards new data (default), FTRUMCacheDiscard.discardOldest discards oldest data |
| rumCacheLimitCount | number | No | Local cache maximum RUM entry count limit [10_000, ), default 100_000 |
| isInTakeUrl | callBack | No | Sets conditions for filtering Resources. For usage, refer to Data Collection Custom Rules |
RUM User Data Tracking¶
Action¶
Usage¶
/// Add an action
/// [actionName] action name
/// [actionType] action type
/// [property] additional property parameters (optional)
Future<void> startAction(String actionName, String actionType,
{Map<String, String>? property})
Code Example¶
View¶
Custom View¶
Usage¶
/// View creation, this method must be called before [starView]
/// [viewName] page name
/// [duration] page load duration
Future<void> createView(String viewName, int duration)
/// View start
/// [viewName] page name
/// [viewReferer] previous page name
/// [property] additional property parameters (optional)
Future<void> starView(String viewName, {Map<String, String>? property})
/// View end
/// [property] additional property parameters (optional)
Future<void> stopView({Map<String, String>? property})
Code Example¶
FTRUMManager().createView("Current Page Name", 100000000);
FTRUMManager().starView("Current Page Name");
FTRUMManager().stopView();
For automatic page collection, route filtering, sleep/wakeup listener rules, etc., refer to Data Collection Custom Rules.
Error¶
Automatic Collection¶
void main() async {
runZonedGuarded(() async {
WidgetsFlutterBinding.ensureInitialized();
await FTMobileFlutter.sdkConfig(
datakitUrl: serverUrl,
debug: true,
);
await FTRUMManager().setConfig(
androidAppId: appAndroidId,
iOSAppId: appIOSId,
);
// Flutter exception capture
FlutterError.onError = FTRUMManager().addFlutterError;
runApp(MyApp());
}, (Object error, StackTrace stack) {
// Add Error data
FTRUMManager().addError(error, stack);
});
}
Custom Error¶
Usage¶
/// Add a custom error
/// [stack] stack trace
/// [message] error message
/// [appState] application state
/// [errorType] custom errorType
/// [property] additional property parameters (optional)
Future<void> addCustomError(String stack, String message,
{Map<String, String>? property, String? errorType})
Code Example¶
Resource¶
Automatic Collection¶
Enabled via FTRUMManager().setConfig by setting enableUserResource to true.
Custom Resource¶
Usage¶
/// Start a resource request
/// [key] unique id
/// [property] additional property parameters (optional)
Future<void> startResource(String key, {Map<String, String>? property})
/// End a resource request
/// [key] unique id
/// [property] additional property parameters (optional)
Future<void> stopResource(String key, {Map<String, String>? property})
/// Send resource data metrics
Future<void> addResource({
required String key,
required String url,
required String httpMethod,
required Map<String, dynamic> requestHeader,
Map<String, dynamic>? responseHeader,
String? responseBody = "",
int? resourceStatus,
})
Code Example¶
void httpClientGetHttp(String url) async {
var httpClient = HttpClient();
String key = Uuid().v4();
HttpClientResponse? response;
HttpClientRequest? request;
try {
request = await httpClient
.getUrl(Uri.parse(url))
.timeout(Duration(seconds: 10));
FTRUMManager().startResource(key);
response = await request.close();
} finally {
Map<String, dynamic> requestHeader = {};
Map<String, dynamic> responseHeader = {};
request!.headers.forEach((name, values) {
requestHeader[name] = values;
});
var responseBody = "";
if (response != null) {
response.headers.forEach((name, values) {
responseHeader[name] = values;
});
responseBody = await response.transform(Utf8Decoder()).join();
}
FTRUMManager().stopResource(key);
FTRUMManager().addResource(
key: key,
url: request.uri.toString(),
requestHeader: requestHeader,
httpMethod: request.method,
responseHeader: responseHeader,
resourceStatus: response?.statusCode,
responseBody: responseBody,
);
}
}
For usage with the
httplibrary anddiolibrary, refer to example.