RUM Configuration¶
Sampling field migration (
ft-sdk >= 1.7.6):setSessionSamplingRateuses a floating-point percentage from 0 to 100; the oldsetSamplingRateretains the 0–1 unit, so multiply the value by 100 when migrating. The new field takes precedence only when explicitly set; invalid values throw an exception and do not change the previous valid value. Versions below this release continue to use the old method; deprecation does not mean removal, and the old method retains its original unit and behavior.
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 | Sets the RUM AppId. RUM collection is enabled only when the RUM appid is set. How to get the appid |
| setSessionSamplingRate | Float | No | Sampling percentage, range [0,100], default 100; decimals are supported, for example 0.1 means 0.1%. 0 means no sampling, 100 means full sampling. When explicitly set, the new field takes precedence over the old field regardless of the order of configuration. Supported in ft-sdk >= 1.7.6. |
| setSamplingRate | Float | No | Deprecated since ft-sdk 1.7.6, kept for compatibility. Sets the sampling rate in the range [0,1]. 0 means no sampling, 1 means full sampling; the default value is 1. The scope covers all View, Action, LongTask, and Error data under the same session_id |
| setSessionOnErrorSamplingRate | float | No | Error session sampling percentage, range [0,100], default 0; decimals are supported. When a normal session is not sampled and an error occurs, data covering the 1 minute before the error is additionally sampled at this percentage; the explicitly set new field takes precedence over the old field. Supported in ft-sdk >= 1.7.6. |
| setSessionErrorSampleRate | Float | No | Deprecated since ft-sdk 1.7.6, 0–1 compatibility retained. Sets the error sampling rate. When a session is not sampled by setSamplingRate, data covering the 1 minute before an error can be collected if an error occurs during the session. Range [0,1]; 0 means no sampling, 1 means full sampling, default 0. The scope covers 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 false. When enabled, error stack data is displayed in Error Analytics. For converting obfuscated content in crash logs, see Symbol file upload. In ft-sdk 1.5.1 and above, extraLogCatWithJavaCrash and extraLogCatWithNativeCrash can be used to control whether logcat is shown for Java Crash and Native Crash |
| setIssueDataProvider | FTIssueDataProvider | No | Adds validated custom fields to auto-collected Java/Native Crash and watchdog/native ANR Error, including historical recovery data. Not set by default. Supported in ft-sdk 1.7.5 and above. See Crash/ANR custom fields |
| setExtraMonitorTypeWithError | Array | No | Sets auxiliary monitoring information and adds additional monitoring data to RUM crash data. ErrorMonitorType.BATTERY is battery level, ErrorMonitorType.MEMORY is memory usage, and ErrorMonitorType.CPU is CPU usage. Not set by default |
| setDeviceMetricsMonitorType | Array | No | Sets View monitoring information and adds monitoring data during the View lifecycle. DeviceMetricsMonitorType.BATTERY monitors the maximum current output of the current page, DeviceMetricsMonitorType.MEMORY monitors memory used by the current app, DeviceMetricsMonitorType.CPU monitors CPU jitter count, and DeviceMetricsMonitorType.FPS monitors screen frame rate. Monitoring frequency options: DetectFrequency.DEFAULT (500 ms), DetectFrequency.FREQUENT (100 ms), DetectFrequency.RARE (1 s). Not set by default |
| setEnableTrackAppANR | Boolean | No | Whether to enable ANR collection. Default false. Starting with ft-sdk 1.7.5, Android 11 (API 30) and above recover fatal ANRs via ApplicationExitInfo at subsequent process startup, and do not collect non-fatal real-time ANRs; Android 10 (API 29) and below continue to use real-time watchdog/native ANR collection. extraLogCatWithANR applies only to the real-time collection path for API 29 and below |
| setEnableTrackAppUIBlock | Boolean, long | No | Whether to enable UI blocking detection. Default false. In ft-sdk 1.6.4 and above, blockDurationMs controls the detection time range [100,), in milliseconds, default 1 second |
| setEnableTraceUserAction | Boolean | No | Whether to automatically track user actions; currently supports only app launches and click actions. This configuration depends on ft-plugin. Default false |
| setEnableTraceUserView | Boolean | No | Whether to automatically track user views. This configuration depends on ft-plugin. Default false |
| setEnableTraceUserViewInFragment | Boolean | No | Whether to automatically track Fragment view data. This configuration depends on ft-plugin. Default false. Supported in ft-sdk 1.6.11 and above |
| setInitialResourceIdentifier | FTInitialResourceIdentifier | No | Sets the Resource matching rule that participates in the native View network_settled_time calculation; a 100 ms time window is used by default. null is not accepted. A rule returning false only excludes the contribution to this metric and does not discard the Resource event. See View timing metric custom rules |
| setLastInteractionIdentifier | FTLastInteractionIdentifier | No | Sets the previous-page interaction matching rule for the native View interaction_to_next_view_time. By default, the time difference must be greater than 0 and less than 3000 ms. Pass null to disable automatic INV. See View timing metric custom rules |
| setEnableTraceUserResource | Boolean | No | Whether to collect network request Resources. Default false. Supports OkHttp, HttpURLConnection / HttpsURLConnection, and OkHttp WebSocket handshake. See Resource automatic collection for integration requirements of each method |
| setEnableHttpURLConnectionResource | Boolean | No | Whether to automatically collect HttpURLConnection / HttpsURLConnection Resources. Default false. Requires setEnableTraceUserResource(true) to be enabled at the same time, and requires ft-sdk >= 1.7.6-alpha03 and ft-plugin >= 1.3.9-alpha01. See URLConnection automatic collection |
| setEnableResourceHostIP | Boolean | No | Whether to collect the IP address of the request target domain. Scope: only affects the default OkHttp collection when enableTraceUserResource is true; does not apply to URLConnection. For custom Resource collection, use FTResourceEventListener.FTFactory(true) to enable this feature. In addition, a single OkHttp instance caches IPs for the same domain; with the same OkHttpClient, as long as the server IP does not change, the IP is resolved only once |
| setResourceUrlHandler | Callback | No | Sets the conditions for filtering Resources; no filtering by default |
| setOkHttpEventListenerHandler | Callback | No | Sets a global OkHttp EventListener via ASM; not set by default |
| setOkHttpResourceContentHandler | Callback | No | Sets a global FTResourceInterceptor.ContentHandlerHelper via ASM; not set by default. Supported in ft-sdk 1.6.7 and above. Custom Resource |
| addGlobalContext | Dictionary | No | Adds custom tags to distinguish RUM data sources. If you need to use the Trace feature, set the key parameter to track_id and value to any number. For notes on the adding rules, see here |
| setVisitorIdConfig | FTVisitorIdConfig | No | Configures the anonymous visitor identifier Visitor ID. Default null (disabled). It is enabled after a valid configuration is passed. OkHttp Header injection is independent of RUM/Trace sampling and the Resource collection switch. Supported in ft-sdk >= 1.7.6-alpha04. See Visitor ID |
| setRumCacheLimitCount | int | No | Maximum number of RUM events in the local cache, range [10_000,), default 100_000. Supported in ft-sdk 1.6.6 and above |
| setEnableTraceWebView | Boolean | No | Whether to enable WebView data collection through the Android SDK. Default true. Supported in ft-sdk 1.6.12 and above |
| setAllowWebViewHost | Array | No | Sets the WebView host addresses allowed for data tracking; null collects all hosts. Default null. Supported in ft-sdk 1.6.12 and above. This method is deprecated; starting with ft-sdk 1.7.5, use FTSDKConfig.setAllowWebViewHost to configure WebView RUM and Log together |
| setViewActivityTrackingHandler | FTViewActivityTrackingHandler | No | Customizes how Activity views are tracked. When an Activity lifecycle event occurs, this handler is called to decide how to track the Activity. No handling by default. Supported in ft-sdk 1.6.13 and above |
| setViewFragmentTrackingHandler | FTViewFragmentTrackingHandler | No | Customizes how Fragment views are tracked. When a Fragment lifecycle event occurs, this handler is called to decide how to track the Fragment. No handling by default. Supported in ft-sdk 1.6.13 and above |
| setActionTrackingHandler | FTActionTrackingHandler | No | Customizes how user actions are tracked. When a user performs an action, this handler is called to decide how to track it. No handling by default. Supported in ft-sdk 1.6.13 and above |
RUM Manual Instrumentation¶
Configure enableTraceUserAction, enableTraceUserView, enableTraceUserResource, setEnableTrackAppUIBlock, setEnableTrackAppCrash, and setEnableTrackAppANR in FTRUMConfig to enable automatic collection of Action, View, Resource, LongTask, and Error events. If you need custom collection, you can manually report events through FTRUMGlobalManager.
Action¶
Usage¶
/**
* Add an Action
*
* @param actionName Action name
* @param actionType Action type
* @param property Additional property parameters (optional)
*/
public void startAction(String actionName, String actionType, HashMap<String, Object> property)
/**
* Add an Action. This kind 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 properties (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 property parameters (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 properties (optional)
*/
fun addAction(actionName: String, actionType: String, duration: Long, property: HashMap<String, Any>)
startActionhas a built-in timing algorithm. During the timing window, it attempts to associate with nearbyResource,LongTask, andErrorevents, and is protected by a 100 ms frequent-trigger guard; it is recommended for user-action type events. If you need frequent calls, useaddAction. Events added this way do not conflict withstartActionand are not associated with the surroundingResource,LongTask, orErrorevents.
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¶
/**
* Start of a view
*
* @param viewName Current view name
* @param property Additional property parameters (optional)
*/
public void startView(String viewName, HashMap<String, Object> property)
/**
* End of a view
*
* @param property Additional property parameters (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)
/**
* Start of a view
*
* @param viewName Current view name
* @param property Additional property parameters (optional)
*/
fun startView(viewName: String, property: HashMap<String, Any>)
/**
* End of a view
*
* @param property Additional property parameters (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 state
* @param dateline Occurrence time, in nanoseconds (optional)
* @param property Additional properties (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 state
* @param dateline Occurrence time, in nanoseconds (optional)
* @param property Additional properties (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 state
* @param dateline Occurrence time, in nanoseconds (optional)
* @param property Additional properties (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 state
* @param dateline Occurrence time, in nanoseconds (optional)
* @param property Additional properties (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: Report the error with a delayed timestamp; this time is usually when the error occurred
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: Report the error with a delayed timestamp; this time is usually when the error occurred
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¶
/**
* Start of a resource
*
* @param resourceId Resource ID
* @param property Additional property parameters (optional)
*/
public void startResource(String resourceId, HashMap<String, Object> property)
/**
* End of a resource
*
* @param resourceId Resource ID
* @param property Additional property parameters (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)
/**
* Start of a resource
*
* @param resourceId Resource ID (optional)
*/
fun startResource(resourceId: String, property: HashMap<String, Any>)
/**
* End of a resource
*
* @param resourceId Resource ID
* @param property Additional property parameters (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 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: Using 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 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: Using 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 start time | |
| NetStatusBean.tcpEndTime | No | TCP 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 properties | |
| 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 ContentType | |
| ResourceParams.responseContentEncoding | No | Response ContentEncoding | |
| ResourceParams.resourceMethod | No | Request method | GET, POST, etc. |
| ResourceParams.responseBody | No | Response body content | |
| ResourceParams.property | No | Additional properties |
Resource Automatic Collection¶
To automatically collect network requests, integrate ft-plugin and enable setEnableTraceUserResource(true) during RUM initialization. Resource URL filtering and RUM sampling rules apply to all of the following collection methods.
OkHttp¶
When setEnableTraceUserResource(true) is enabled, the SDK automatically collects OkHttp HTTP/HTTPS requests instrumented by the plugin, with no need to change request code. Complete SDK initialization before creating the OkHttpClient.
If the plugin is not used, you can configure it via manual OkHttp Resource / Trace integration.
HttpURLConnection / HttpsURLConnection¶
Requires ft-sdk >= 1.7.6-alpha03 and ft-plugin >= 1.3.9-alpha01. Before creating connections, enable both of the following switches:
- Collection scope: HTTP/HTTPS requests from
URL.openConnection()andopenConnection(Proxy)instrumented by the plugin. The plugin optioninstrumentHttpURLConnectionis enabled by default; calls through reflection, system internals, or excluded from instrumentation are not collected. - Collected data: URL, method, request headers, response headers, status code, actual bytes read and written, and total duration. The response body, DNS/TCP/TLS phase durations, and target IP are not collected. Total duration includes the time the app spends reading the response stream; if the response is not fully read, the byte count may be smaller than the full response size.
- Usage notes: Read and close the response stream properly, and call
disconnect()after the request completes. It is recommended to filter long-lived connections such as SSE; when used together with other collection layers, avoid duplicate reporting. - Correlation capabilities: Trace Header injection and RUM trace correlation require separate configuration; see URLConnection Trace. Visitor ID Header injection is not supported (Visitor ID).
WebSocket Handshake Resource¶
Requires ft-sdk >= 1.7.5 and ft-plugin >= 1.3.8. When setEnableTraceUserResource(true) is enabled, handshake requests from OkHttp newWebSocket() are automatically collected, with no additional switches required.
Each handshake generates one Resource that records whether the handshake succeeded, was rejected, or failed. Connection lifetime is not counted, and message content is not collected. If you are not using a plugin that supports automatic collection, you can use FTWebSocket for manual integration.