RUM Configuration¶
RUM Initialization Configuration¶
FTSdk.initRUMWithConfig(
new FTRUMConfig()
.setRumAppId(RUM_APP_ID)
.setEnableTraceUserView(true)
.setDeviceMetricsMonitorType(DeviceMetricsMonitorType.ALL.getValue())
.setEnableTraceUserAction(true)
.setEnableTraceUserResource(true)
.setEnableTrackAppUIBlock(true)
.setEnableTrackAppCrash(true)
.setEnableTrackAppANR(true)
.setExtraMonitorTypeWithError(ErrorMonitorType.ALL.getValue())
);
FTSdk.initRUMWithConfig(
FTRUMConfig()
.setRumAppId(RUM_APP_ID)
.setEnableTraceUserView(true)
.setDeviceMetricsMonitorType(DeviceMetricsMonitorType.ALL.getValue())
.setEnableTraceUserAction(true)
.setEnableTraceUserResource(true)
.setEnableTrackAppUIBlock(true)
.setEnableTrackAppCrash(true)
.setEnableTrackAppANR(true)
.setExtraMonitorTypeWithError(ErrorMonitorType.ALL.getValue())
)
| Method Name | Type | Required | Description |
|---|---|---|---|
| setRumAppId | String | Yes | Set the RUM AppId. RUM collection is enabled only when the RUM appid is set. How to obtain the AppId |
| setSamplingRate | Float | No | Set the sampling rate, range [0,1]. 0 means no collection, 1 means full collection. Default value is 1. Scope: all View, Action, LongTask, and Error data under the same session_id. |
| setSessionErrorSampleRate | Float | No | Set the error sampling rate. When a session is not sampled by setSamplingRate, if an error occurs during the session, data from the 1 minute before the error can be collected. Range [0,1], 0 means no collection, 1 means full collection, default value is 0. Scope: all View, Action, LongTask, and Error data under the same session_id. Supported in ft-sdk 1.6.11 and above. |
| setEnableTrackAppCrash | Boolean | No | Whether to report App crash logs. Default is false. When enabled, error stack traces are displayed in error analysis. For obfuscated content conversion in crash logs, refer to Symbol File Upload. In ft-sdk 1.5.1 and above, you can use extraLogCatWithJavaCrash and extraLogCatWithNativeCrash to control whether logcat is displayed for Java Crash and Native Crash. |
| setIssueDataProvider | FTIssueDataProvider | No | Add validated custom fields to automatically collected Java/Native Crash and watchdog/native ANR Error, including historical recovery data. Default is not set. Supported in ft-sdk 1.7.5 and above. See Crash/ANR Custom Fields. |
| setExtraMonitorTypeWithError | Array | No | Set auxiliary monitoring information. Add additional monitoring data to RUM crash data. ErrorMonitorType.BATTERY for battery level, ErrorMonitorType.MEMORY for memory usage, ErrorMonitorType.CPU for CPU usage. Default is not set. |
| setDeviceMetricsMonitorType | Array | No | Set View monitoring information. Add monitoring data during the View lifecycle. DeviceMetricsMonitorType.BATTERY monitors the maximum current output of the current page, DeviceMetricsMonitorType.MEMORY monitors the memory usage of the current app, DeviceMetricsMonitorType.CPU monitors CPU jitter count, DeviceMetricsMonitorType.FPS monitors screen frame rate. Monitoring cycle options: DetectFrequency.DEFAULT 500ms, DetectFrequency.FREQUENT 100ms, DetectFrequency.RARE 1s. Default is not set. |
| setEnableTrackAppANR | Boolean | No | Whether to enable ANR collection. Default is false. Starting from ft-sdk 1.7.5, on Android 11 (API 30) and above, fatal ANRs are recovered via ApplicationExitInfo on subsequent process launches; non-fatal real-time ANRs are not collected. On Android 10 (API 29) and below, real-time watchdog/native ANR collection continues. extraLogCatWithANR is only used for the real-time collection path on API 29 and below. |
| setEnableTrackAppUIBlock | Boolean, long | No | Whether to enable UI stuck detection. Default is false. In ft-sdk 1.6.4 and above, you can control the detection time range using blockDurationMs [100, ), in milliseconds, default is 1 second. |
| setEnableTraceUserAction | Boolean | No | Whether to automatically track user actions. Currently only supports user launch and click actions. This configuration depends on ft-plugin. Default is false. |
| setEnableTraceUserView | Boolean | No | Whether to automatically track user page actions. This configuration depends on ft-plugin. Default is false. |
| setEnableTraceUserViewInFragment | Boolean | No | Whether to automatically track Fragment type page data. This configuration depends on ft-plugin. Default is false. Supported in ft-sdk 1.6.11 and above. |
| setEnableTraceUserResource | Boolean | No | Whether to track user network requests. Only supports OkHttp. Default is false. Automatic collection of regular HTTP requests depends on ft-plugin; when ft-sdk >= 1.7.5 with ft-plugin >= 1.3.8, it also automatically collects the handshake Resource of newWebSocket(), or you can use FTWebSocket for explicit integration. |
| setEnableResourceHostIP | Boolean | No | Whether to collect the IP of the requested target domain. Scope: only affects default collection when EnableTraceUserResource is true. For custom Resource collection, use FTResourceEventListener.FTFactory(true) to enable this feature. Additionally, the same OkHttp has an IP cache mechanism for the same domain; the same OkHttpClient will only generate one IP record as long as the server IP does not change. |
| setResourceUrlHandler | Callback | No | Set conditions for filtering Resources. Default is no filtering. |
| setOkHttpEventListenerHandler | Callback | No | ASM sets a global OkHttp EventListener. Default is not set. |
| setOkHttpResourceContentHandler | Callback | No | ASM sets a global FTResourceInterceptor.ContentHandlerHelper. Default is not set. Supported in ft-sdk 1.6.7 and above. Custom Resource. |
| addGlobalContext | Dictionary | No | Add custom tags for distinguishing user monitoring data sources. If tracing is needed, the parameter key must be track_id and value can be any number. For adding rules, see here. |
| setRumCacheLimitCount | int | No | Local cache limit for RUM data [10_000, ). Default is 100_000. Supported in ft-sdk 1.6.6 and above. |
| setEnableTraceWebView | Boolean | No | Whether to enable WebView data collection via Android SDK. Default is true. Supported in ft-sdk 1.6.12 and above. |
| setAllowWebViewHost | Array | No | Set allowed WebView host addresses for data tracking. null means all hosts are collected. Default is null. Supported in ft-sdk 1.6.12 and above. This method is deprecated; use FTSDKConfig.setAllowWebViewHost to configure WebView RUM and Log uniformly from ft-sdk 1.7.5. |
| setViewActivityTrackingHandler | FTViewActivityTrackingHandler | No | Customize the tracking method for Activity views. When an Activity lifecycle event occurs, this handler is called to decide how to track the Activity. Default is no processing. Supported in ft-sdk 1.6.13 and above. |
| setViewFragmentTrackingHandler | FTViewFragmentTrackingHandler | No | Customize the tracking method for Fragment views. When a Fragment lifecycle event occurs, this handler is called to decide how to track the Fragment. Default is no processing. Supported in ft-sdk 1.6.13 and above. |
| setActionTrackingHandler | FTActionTrackingHandler | No | Customize the tracking method for user actions. When a user performs an action, this handler is called to decide how to track the action. Default is no processing. Supported in ft-sdk 1.6.13 and above. |
WebSocket Handshake Resource¶
When ft-sdk >= 1.7.5 with ft-plugin >= 1.3.8, enabling FTRUMConfig.setEnableTraceUserResource(true) will automatically collect one handshake Resource for OkHttp newWebSocket() requests.
If you only upgrade ft-sdk to 1.7.5 and continue using ft-plugin 1.3.7, the build and runtime are still compatible, but 1.3.7 does not automatically intercept WebSocket handshakes. In this case, you can use FTWebSocket.newWebSocket() or FTWebSocket.wrap() for explicit integration; third-party libraries that cannot modify call points or inject WebSocket.Factory still need to upgrade to ft-plugin >= 1.3.8.
The Resource ends when the handshake succeeds, is rejected by the server, or fails. It does not count the duration of the WebSocket connection, nor does it collect message content. Existing Resource URL filtering and RUM sampling rules still apply. The data includes the following fields:
resource_type=websocketresource_websocket_collection_level=handshakeresource_websocket_handshake_state: valuessuccess,rejected, orfailed
Crash/ANR Custom Fields¶
ft-sdk >= 1.7.5 can add custom fields to automatically collected Crash and ANR RUM Errors via FTRUMConfig.setIssueDataProvider(FTIssueDataProvider).
FTRUMConfig config = new FTRUMConfig()
.setEnableTrackAppCrash(true)
.setEnableTrackAppANR(true)
.setIssueDataProvider(issue -> {
Map<String, Object> fields = new HashMap<>();
fields.put("business_scene", sceneStore.current());
fields.put("historical_issue", issue.isHistorical());
return fields;
});
FTIssueDataProvider.provideAdditionalFields(FTIssueInfo) is called synchronously during Error construction and may be called concurrently. The implementation must be thread-safe, avoid I/O, and return within 10 ms. Setting a Provider does not automatically enable Crash or ANR collection; you still need to enable the corresponding collection items.
- Only automatically collected Java/Native Crash, and watchdog, native, or
ApplicationExitInfoANR trigger the Provider; manual Errors, Network Errors, and WebView Errors do not trigger it. - In data restored from Native dump or
ApplicationExitInfo,FTIssueInfo.isHistorical()returnstrue. - Return values support strings, booleans, and limited numeric values, with a maximum of 50 entries checked; keys are limited to 100 UTF-8 bytes, string values to 4096 UTF-8 bytes, and total fields must not exceed 25 KiB.
- Invalid, over-limit, SDK reserved fields, and keys starting with
error.orerror_are ignored. It is the business's responsibility to ensure field content complies with privacy and regulatory requirements.
RUM Manual Instrumentation¶
Configure enableTraceUserAction, enableTraceUserView, enableTraceUserResource, setEnableTrackAppUIBlock, setEnableTrackAppCrash, and setEnableTrackAppANR in FTRUMConfig to enable automatic collection of Action, View, Resource, LongTask, and Error. If you need custom collection, you can manually report via FTRUMGlobalManager.
Action¶
Usage¶
/**
* Add an Action
*
* @param actionName Action name
* @param actionType Action type
* @param property Additional attributes (optional)
*/
public void startAction(String actionName, String actionType, HashMap<String, Object> property)
/**
* Add an Action. This type of data cannot be associated with Error, Resource, or LongTask data.
*
* @param actionName Action name
* @param actionType Action type
* @param duration Duration in nanoseconds (optional)
* @param property Extended attributes (optional)
*/
public void addAction(String actionName, String actionType, long duration, HashMap<String, Object> property)
/**
* Add an action
*
* @param actionName Action name
* @param actionType Action type
* @param property Additional attributes (optional)
*/
fun startAction(actionName: String, actionType: String, property: HashMap<String, Any>)
/**
* Add an Action
*
* @param actionName Action name
* @param actionType Action type
* @param duration Duration in nanoseconds (optional)
* @param property Extended attributes (optional)
*/
fun addAction(actionName: String, actionType: String, duration: Long, property: HashMap<String, Any>)
startActionhas an internal duration calculation algorithm that tries to associate with nearbyResource,LongTask, andErrordata during calculation. It has a 100 ms frequent trigger protection and is recommended for user action type data. For frequent calls, useaddAction, which does not conflict withstartActionand does not associate with currentResource,LongTask, orErrordata.
Code Examples¶
// Scenario 1
FTRUMGlobalManager.get().startAction("login", "action_type");
// Scenario 2: Dynamic parameters
HashMap<String, Object> map = new HashMap<>();
map.put("ft_key", "ft_value");
FTRUMGlobalManager.get().startAction("login", "action_type", map);
// Scenario 1
FTRUMGlobalManager.get().addAction("login", "action_type");
// Scenario 2: Dynamic parameters
HashMap<String, Object> map = new HashMap<>();
map.put("ft_key", "ft_value");
FTRUMGlobalManager.get().addAction("login", "action_type", map);
// Scenario 1
FTRUMGlobalManager.get().startAction("login", "action_type")
// Scenario 2: Dynamic parameters
val map = HashMap<String, Any>()
map["ft_key"] = "ft_value"
FTRUMGlobalManager.get().startAction("login", "action_type", map)
// Scenario 1
FTRUMGlobalManager.get().addAction("login", "action_type")
// Scenario 2: Dynamic parameters
val map = HashMap<String, Any>()
map["ft_key"] = "ft_value"
FTRUMGlobalManager.get().addAction("login", "action_type", map)
View¶
Usage¶
/**
* View start
*
* @param viewName Current page name
* @param property Additional attributes (optional)
*/
public void startView(String viewName, HashMap<String, Object> property)
/**
* View stop
*
* @param property Additional attributes (optional)
*/
public void stopView(HashMap<String, Object> property)
/**
* Update the current view loading_time metric, in nanoseconds
*
* @param duration duration
*/
public void updateLoadTime(long duration)
/**
* View start
*
* @param viewName Current page name
* @param property Additional attributes (optional)
*/
fun startView(viewName: String, property: HashMap<String, Any>)
/**
* View stop
*
* @param property Additional attributes (optional)
*/
fun stopView(property: HashMap<String, Any>)
/**
* Update the current view loading_time metric, in nanoseconds
*
* @param duration duration
*/
fun updateLoadTime(duration: Long)
Code Examples¶
@Override
protected void onResume() {
super.onResume();
// Scenario 1
FTRUMGlobalManager.get().startView("Current Page Name");
// Scenario 2: Dynamic parameters
HashMap<String, Object> map = new HashMap<>();
map.put("ft_key", "ft_value");
map.put("ft_key_will_change", "ft_value");
FTRUMGlobalManager.get().startView("Current Page Name", map)
}
@Override
protected void onPause() {
super.onPause();
// Scenario 1
FTRUMGlobalManager.get().stopView();
// Scenario 2: Dynamic parameters
HashMap<String, Object> map = new HashMap<>();
map.put("ft_key_will_change", "ft_value_change"); // The value of ft_key_will_change will be updated to ft_value_change when stopView is called.
FTRUMGlobalManager.get().stopView(map);
}
override fun onResume() {
super.onResume()
// Scenario 1
FTRUMGlobalManager.get().startView("Current Page Name")
// Scenario 2: Dynamic parameters
val map = HashMap<String, Any>()
map["ft_key"] = "ft_value"
map["ft_key_will_change"] = "ft_value"
FTRUMGlobalManager.get().startView("Current Page Name", map)
}
override fun onPause() {
super.onPause()
// Scenario 1
FTRUMGlobalManager.get().stopView()
// Scenario 2: Dynamic parameters
val map = HashMap<String, Any>()
map["ft_key_will_change"] = "ft_value_change" // The value of ft_key_will_change will be changed to ft_value_change when stopView is called.
FTRUMGlobalManager.get().stopView(map)
}
Error¶
Usage¶
/**
* Add error information
*
* @param log Log
* @param message Message
* @param errorType Error type, ErrorType
* @param state App running state
* @param dateline Occurrence time in nanoseconds (optional)
* @param property Additional attributes (optional)
*/
public void addError(String log, String message, long dateline, ErrorType errorType,
AppState state, HashMap<String, Object> property)
/**
* Add error information
*
* @param log Log
* @param message Message
* @param errorType Error type, String
* @param state App running state
* @param dateline Occurrence time in nanoseconds (optional)
* @param property Additional attributes (optional)
*/
public void addError(String log, String message, long dateline, String errorType,
AppState state, HashMap<String, Object> property)
/**
* Add error information
*
* @param log Log
* @param message Message
* @param errorType Error type, ErrorType
* @param state App running state
* @param dateline Occurrence time in nanoseconds (optional)
* @param property Additional attributes (optional)
*/
fun addError(log: String, message: String, dateline: Long, errorType: ErrorType, state: AppState, property: HashMap<String, Any>)
/**
* Add error information
*
* @param log Log
* @param message Message
* @param errorType Error type, String
* @param state App running state
* @param dateline Occurrence time in nanoseconds (optional)
* @param property Additional attributes (optional)
*/
fun addError(log: String, message: String, dateline: Long, errorType: String, state: AppState, property: HashMap<String, Any>)
Code Examples¶
// Scenario 1:
FTRUMGlobalManager.get().addError("error log", "error msg", ErrorType.JAVA, AppState.RUN);
// Scenario 2: Record an error that occurred in the past; the time is usually the actual error occurrence time.
FTRUMGlobalManager.get().addError("error log", "error msg", 16789000000000000000L, ErrorType.JAVA, AppState.RUN);
// Scenario 3: Dynamic parameters
HashMap<String, Object> map = new HashMap<>();
map.put("ft_key", "ft_value");
FTRUMGlobalManager.get().addError("error log", "error msg", ErrorType.JAVA, AppState.RUN, map);
// Scenario 1:
FTRUMGlobalManager.get().addError("error log", "error msg", ErrorType.JAVA, AppState.RUN)
// Scenario 2: Record an error that occurred in the past; the time is usually the actual error occurrence time.
FTRUMGlobalManager.get().addError("error log", "error msg", 16789000000000000000, ErrorType.JAVA, AppState.RUN)
// Scenario 3: Dynamic parameters
val map = HashMap<String, Any>()
map["ft_key"] = "ft_value"
FTRUMGlobalManager.get().addError("error log", "error msg", ErrorType.JAVA, AppState.RUN, map)
LongTask¶
Usage¶
Code Examples¶
Resource¶
Usage¶
/**
* Resource start
*
* @param resourceId Resource ID
* @param property Additional attributes (optional)
*/
public void startResource(String resourceId, HashMap<String, Object> property)
/**
* Resource stop
*
* @param resourceId Resource ID
* @param property Additional attributes (optional)
*/
public void stopResource(final String resourceId, HashMap<String, Object> property)
/**
* Set network transfer content
*
* @param resourceId resourceId
* @param params params
* @param netStatusBean netStatusBean
*/
public void addResource(String resourceId, ResourceParams params, NetStatusBean netStatusBean)
/**
* Resource start
*
* @param resourceId Resource ID (optional)
*/
fun startResource(resourceId: String, property: HashMap<String, Any>)
/**
* Resource stop
*
* @param resourceId Resource ID
* @param property Additional attributes (optional)
*/
fun stopResource(resourceId: String, property: HashMap<String, Any>)
/**
* Set network transfer content
*
* @param resourceId resourceId
* @param params params
* @param netStatusBean netStatusBean
*/
fun addResource(resourceId: String, params: ResourceParams, netStatusBean: NetStatusBean)
Code Examples¶
// Scenario 1
// Request start
FTRUMGlobalManager.get().startResource("resourceId");
// ...
// Request end
FTRUMGlobalManager.get().stopResource("resourceId");
// Finally, after the request ends, send the request-related data metrics
ResourceParams params = new ResourceParams();
params.setUrl("https://guance.com");
params.setResponseContentType(response.header("Content-Type"));
params.setResponseConnection(response.header("Connection"));
params.setResponseContentEncoding(response.header("Content-Encoding"));
params.setResponseHeader(response.headers().toString());
params.setRequestHeader(request.headers().toString());
params.setResourceStatus(response.code());
params.setResourceMethod(request.method());
NetStatusBean bean = new NetStatusBean();
bean.setTcpStartTime(60000000);
// ...
FTRUMGlobalManager.get().addResource("resourceId", params, bean);
// Scenario 2: Dynamic parameters
HashMap<String, Object> map = new HashMap<>();
map.put("ft_key", "ft_value");
map.put("ft_key_will_change", "ft_value");
FTRUMGlobalManager.get().startResource("resourceId", map);
// ...
HashMap<String, Object> map = new HashMap<>();
map.put("ft_key_will_change", "ft_value_change"); // The value of ft_key_will_change will be changed to ft_value_change when stopResource is called.
FTRUMGlobalManager.get().stopResource(uuid, map);
// Scenario 1
// Request start
FTRUMGlobalManager.get().startResource("resourceId")
// Request end
FTRUMGlobalManager.get().stopResource("resourceId")
// Finally, after the request ends, send the request-related data metrics
val params = ResourceParams()
params.url = "https://guance.com"
params.responseContentType = response.header("Content-Type")
params.responseConnection = response.header("Connection")
params.responseContentEncoding = response.header("Content-Encoding")
params.responseHeader = response.headers.toString()
params.requestHeader = request.headers.toString()
params.resourceStatus = response.code
params.resourceMethod = request.method
val bean = NetStatusBean()
bean.tcpStartTime = 60000000
// ...
FTRUMGlobalManager.get().addResource("resourceId", params, bean)
// Scenario 2: Dynamic parameters
val map = hashMapOf<String, Any>(
"ft_key" to "ft_value",
"ft_key_will_change" to "ft_value"
)
FTRUMGlobalManager.get().startResource("resourceId", map)
// ...
val map = hashMapOf<String, Any>(
"ft_key_will_change" to "ft_value_change"
)
// The value of ft_key_will_change will be changed to ft_value_change when stopResource is called.
FTRUMGlobalManager.get().stopResource(uuid, map)
| Method Name | Required | Description | Notes |
|---|---|---|---|
| NetStatusBean.fetchStartTime | No | Request start time | |
| NetStatusBean.tcpStartTime | No | TCP connection start time | |
| NetStatusBean.tcpEndTime | No | TCP connection end time | |
| NetStatusBean.dnsStartTime | No | DNS start time | |
| NetStatusBean.dnsEndTime | No | DNS end time | |
| NetStatusBean.responseStartTime | No | Response start time | |
| NetStatusBean.responseEndTime | No | Response end time | |
| NetStatusBean.sslStartTime | No | SSL start time | |
| NetStatusBean.sslEndTime | No | SSL end time | |
| NetStatusBean.property | No | Additional attributes | |
| ResourceParams.url | Yes | URL address | |
| ResourceParams.requestHeader | No | Request header parameters | |
| ResourceParams.responseHeader | No | Response header parameters | |
| ResourceParams.responseConnection | No | Response connection | |
| ResourceParams.responseContentType | No | Response Content-Type | |
| ResourceParams.responseContentEncoding | No | Response Content-Encoding | |
| ResourceParams.resourceMethod | No | Request method | GET, POST, etc. |
| ResourceParams.responseBody | No | Response body content | |
| ResourceParams.property | No | Additional attributes |
User Information Binding and Unbinding¶
Use FTSdk to bind and unbind user information.
Usage¶
UserData¶
| Method Name | Description | Required | Note |
|---|---|---|---|
| setId | Set user ID | No | |
| setName | Set user name | No | |
| setEmail | Set email | No | |
| setExts | Set user extensions | No | For adding rules, see App Access |
Code Examples¶
// Call this method after the user logs in to bind user information
FTSdk.bindRumUserData("001");
UserData userData = new UserData();
userData.setName("test.user");
userData.setId("test.id");
userData.setEmail("test@mail.com");
Map<String, String> extMap = new HashMap<>();
extMap.put("ft_key", "ft_value");
userData.setExts(extMap);
FTSdk.bindRumUserData(userData);
// Call this method after the user logs out to unbind user information
FTSdk.unbindRumUserData();
// Call this method after the user logs in to bind user information
FTSdk.bindRumUserData("001")
// Bind more user data
val userData = UserData()
userData.name = "test.user"
userData.id = "test.id"
userData.email = "test@mail.com"
val extMap = HashMap<String, String>()
extMap["ft_key"] = "ft_value"
userData.setExts(extMap)
FTSdk.bindRumUserData(userData)
// Call this method after the user logs out to unbind user information
FTSdk.unbindRumUserData()