RUM Configuration¶
RUM Initialization Configuration¶
//Enable rum
FTRumConfig *rumConfig = [[FTRumConfig alloc]initWithAppid:appid];
rumConfig.enableTraceUserView = YES;
rumConfig.deviceMetricsMonitorType = FTDeviceMetricsMonitorAll;
rumConfig.monitorFrequency = FTMonitorFrequencyRare;
rumConfig.enableTraceUserAction = YES;
rumConfig.enableTraceUserResource = YES;
rumConfig.enableTrackAppFreeze = YES;
rumConfig.enableTrackAppCrash = YES;
rumConfig.enableTrackAppANR = YES;
rumConfig.errorMonitorType = FTErrorMonitorAll;
[[FTMobileAgent sharedInstance] startRumWithConfigOptions:rumConfig];
let rumConfig = FTRumConfig(appid: appid)
rumConfig.enableTraceUserView = true
rumConfig.deviceMetricsMonitorType = .all
rumConfig.monitorFrequency = .rare
rumConfig.enableTraceUserAction = true
rumConfig.enableTraceUserResource = true
rumConfig.enableTrackAppFreeze = true
rumConfig.enableTrackAppCrash = true
rumConfig.enableTrackAppANR = true
rumConfig.errorMonitorType = .all
FTMobileAgent.sharedInstance().startRum(withConfigOptions: rumConfig)
| Property | Type | Required | Description |
|---|---|---|---|
| appid | NSString | Yes | The unique identifier for the RUM application ID. Setting the RUM appid enables the RUM collection feature. How to get appid |
| samplerate | int | No | Sampling rate. Value range [0,100], 0 means no collection, 100 means full collection, default is 100. Scope is all View, Action, LongTask, Error data under the same session_id |
| sessionOnErrorSampleRate | int | No | Sets the 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,100], 0 means no collection, 100 means full collection, default is 0. Scope is all View, Action, LongTask, Error data under the same session_id. Supported from SDK 1.5.16 |
| enableTrackAppCrash | BOOL | No | Sets whether to collect crash logs. Default NO |
| enableTrackAppANR | BOOL | No | Collects ANR (Application Not Responding) events. Default NO |
| enableTrackAppFreeze | BOOL | No | Collects UI freeze events. Default NO. Can be enabled and the freeze threshold set via the -setEnableTrackAppFreeze:freezeDurationMs: method |
| freezeDurationMs | long | No | Sets the UI freeze threshold. Value range [100,), unit is milliseconds, default is 250ms. Supported from SDK version 1.5.7 |
| enableTraceUserView | BOOL | No | Sets whether to trace user View operations. Default NO |
| enableTraceUserAction | BOOL | No | Sets whether to trace user Action operations. Default NO. Can customize action_name via view.accessibilityIdentifier |
| enableTraceUserResource | BOOL | No | Sets whether to trace user network requests. Default NO, only works for native http. Note: Network requests initiated via [NSURLSession sharedSession] cannot collect performance data; SDK 1.5.9 and above support collecting network requests initiated via Swift's URLSession async/await APIs |
| resourceUrlHandler | FTResourceUrlHandler | No | Customizes resource collection rules. Default is no filtering. Returns NO to collect, YES to not collect |
| errorMonitorType | FTErrorMonitorType | No | Error event monitoring supplement type. Adds monitoring information to collected crash data. FTErrorMonitorBattery for battery level, FTErrorMonitorMemory for memory usage, FTErrorMonitorCpu for CPU usage, default is not set |
| deviceMetricsMonitorType | FTDeviceMetricsMonitorType | No | View performance monitoring type, default is not set. Adds corresponding monitoring item information to collected View data. FTDeviceMetricsMonitorMemory monitors current app memory usage, FTDeviceMetricsMonitorCpu monitors CPU ticks, FTDeviceMetricsMonitorFps monitors screen frame rate |
| monitorFrequency | FTMonitorFrequency | No | View performance monitoring sampling period. FTMonitorFrequencyDefault 500ms (default), FTMonitorFrequencyFrequent 100ms, FTMonitorFrequencyRare 1000ms |
| enableResourceHostIP | BOOL | No | Whether to collect the IP address of the requested target domain. Supported under >= iOS 13.0, >= tvOS 13.0 |
| globalContext | NSDictionary | No | Adds custom tags for distinguishing user monitoring data sources. If tracking functionality is needed, then the parameter key is track_id, value is any value. Addition rules can be found here |
| rumCacheLimitCount | int | No | RUM maximum cache count. Default is 100_000, supported from SDK version 1.5.8 |
| rumDiscardType | FTRUMCacheDiscard | No | Sets RUM discard rules. Default is FTRUMCacheDiscard. FTRUMCacheDiscard discards appended data when RUM data count exceeds the maximum; FTRUMDiscardOldest discards old data when RUM data exceeds the maximum. Supported from SDK version 1.5.8 |
| resourcePropertyProvider | FTResourcePropertyProvider | No | Adds RUM Resource custom attributes via block callback. Supported from SDK version 1.5.10. Priority is lower than URLSession custom collection |
| enableTraceWebView | BOOL | No | Sets whether to enable WebView data collection, default YES. Supported from SDK 1.5.17 |
| allowWebViewHost | NSArray | No | Sets allowed WebView host addresses for data tracking, nil means collect all, default is nil. Supported from SDK 1.5.17 |
| sessionTaskErrorFilter | FTSessionTaskErrorFilter | No | Sets whether to intercept URLSessionTask Error, returns YES to confirm interception, NO to not intercept, intercepted errors are not collected by RUM-Error. Supported from SDK 1.5.17 |
| viewTrackingHandler | FTViewTrackingHandler | No | Customizes View tracking logic, used to decide which ViewControllers need to be monitored as RUM Views and to customize View Name. Effective condition: enableTraceUserView = YES. Supported from SDK 1.5.18, usage example can be seen here |
| actionTrackingHandler | FTActionTrackingHandler | No | Customizes Action tracking logic, used to filter RUM Action events that need to be recorded and to customize Action Name. Effective condition: enableTraceUserAction = YES. Supported from SDK 1.5.18, usage example can be seen here |
| crashMonitoring | FTCrashMonitorType | No | Configures the type scope of SDK crash monitoring, default is FTCrashMonitorTypeHighCompatibility (high compatibility mode preset macro). Effective condition: enableTrackAppCrash = YES. Note: Need to specify FTCrashMonitorTypeSystem | FTCrashMonitorTypeApplicationState, these provide important information for reports. Supported from SDK 1.5.19 |
RUM User Data Tracking¶
Configure FTRUMConfig with enableTraceUserAction, enableTraceUserView, enableTraceUserResource, enableTrackAppFreeze, enableTrackAppCrash, and enableTrackAppANR to achieve automatic collection tracking for Action, View, Resource, LongTask, and Error data. For custom collection, data can be reported via FTExternalDataManager.
View¶
Usage¶
/// Create a View
///
/// Call this method before `-startViewWithName`. This method is used to record the View loading time. If the loading time cannot be obtained, this method can be omitted.
/// - Parameters:
/// - viewName: View name
/// - loadTime: View loading time (nanoseconds)
-(void)onCreateView:(NSString *)viewName loadTime:(NSNumber *)loadTime;
/// Enter a View
/// - Parameters:
/// - viewName: View name
/// - property: Event custom attributes (optional)
-(void)startViewWithName:(NSString *)viewName property:(nullable NSDictionary *)property;
/// Update the loading time of the current RUM View.
/// Must be called between `-startView` and `-stopView` methods to take effect.
/// - Parameter duration: Loading duration (nanoseconds).
-(void)updateViewLoadingTime:(NSNumber *)duration;
/// Leave a View
/// - Parameter property: Event custom attributes (optional)
-(void)stopViewWithProperty:(nullable NSDictionary *)property;
/// Create a View
///
/// Call this method before `-startViewWithName`. This method is used to record the View loading time. If the loading time cannot be obtained, this method can be omitted.
/// - Parameters:
/// - viewName: View name
/// - loadTime: View loading time (ns)
open func onCreateView(_ viewName: String, loadTime: NSNumber)
/// Enter a View
/// - Parameters:
/// - viewName: View name
/// - property: Event custom attributes (optional)
open func startView(withName viewName: String, property: [AnyHashable : Any]?)
/// Update the loading time of the current RUM View.
/// Must be called between `-startView` and `-stopView` methods to take effect.
/// - Parameter duration: Loading duration (nanoseconds).
open func updateViewLoadingTime(_ duration: NSNumber)
/// Leave a View
/// - Parameter property: Event custom attributes (optional)
open func stopView(withProperty property: [AnyHashable : Any]?)
Code Example¶
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
// Scenario 1:
[[FTExternalDataManager sharedManager] startViewWithName:@"TestVC"];
// Scenario 2: Dynamic parameters
[[FTExternalDataManager sharedManager] startViewWithName:@"TestVC" property:@{@"custom_key":@"custom_value"}];
}
-(void)viewDidDisappear:(BOOL)animated{
[super viewDidDisappear:animated];
// Scenario 1:
[[FTExternalDataManager sharedManager] stopView];
// Scenario 2: Dynamic parameters
[[FTExternalDataManager sharedManager] stopViewWithProperty:@{@"custom_key":@"custom_value"}];
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
// Scenario 1:
FTExternalDataManager.shared().startView(withName: "TestVC")
// Scenario 2: Dynamic parameters
FTExternalDataManager.shared().startView(withName: "TestVC",property: ["custom_key":"custom_value"])
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
// Scenario 1:
FTExternalDataManager.shared().stopView()
// Scenario 2: Dynamic parameters
FTExternalDataManager.shared().stopView(withProperty: ["custom_key":"custom_value"])
}
Action¶
Usage¶
/// Start a RUM Action.
///
/// RUM will bind Resource, Error, LongTask events that may be triggered by this Action. Avoid adding multiple times within 0.1 s. Only one Action can be associated with the same View at the same time. If the previous Action has not ended, new Actions will be discarded.
/// Does not affect Actions added via the `addAction:actionType:property` method.
///
/// - Parameters:
/// - actionName: Event name
/// - actionType: Event type
/// - property: Event custom attributes (optional)
- (void)startAction:(NSString *)actionName actionType:(NSString *)actionType property:(nullable NSDictionary *)property;
/// Add an Action event. No duration, no discard logic.
///
/// Does not affect RUM Actions started via `startAction:actionType:property:`.
/// - Parameters:
/// - actionName: Event name
/// - actionType: Event type
/// - property: Event custom attributes (optional)
- (void)addAction:(NSString *)actionName actionType:(NSString *)actionType property:(nullable NSDictionary *)property;
/// Start a RUM Action.
///
/// RUM will bind Resource, Error, LongTask events that may be triggered by this Action. Avoid adding multiple times within 0.1 s. Only one Action can be associated with the same View at the same time. If the previous Action has not ended, new Actions will be discarded.
/// Does not affect Actions added via the `addAction:actionType:property` method.
///
/// - Parameters:
/// - actionName: Event name
/// - actionType: Event type
/// - property: Event custom attributes (optional)
open func startAction(_ actionName: String, actionType: String, property: [AnyHashable : Any]?)
/// Add an Action event. No duration, no discard logic.
///
/// Does not affect RUM Actions started via `startAction:actionType:property:`.
/// - Parameters:
/// - actionName: Event name
/// - actionType: Event type
/// - property: Event custom attributes (optional)
open func addAction(_ actionName: String, actionType: String, property: [AnyHashable : Any]?)
Code Example¶
Error¶
Usage¶
/// Add an Error event
/// - Parameters:
/// - type: error type
/// - message: error message
/// - stack: stack information
/// - property: event custom attributes (optional)
- (void)addErrorWithType:(NSString *)type message:(NSString *)message stack:(NSString *)stack property:(nullable NSDictionary *)property;
/// Add an Error event
/// - Parameters:
/// - type: error type
/// - state: program running state
/// - message: error message
/// - stack: stack information
/// - property: event custom attributes (optional)
- (void)addErrorWithType:(NSString *)type state:(FTAppState)state message:(NSString *)message stack:(NSString *)stack property:(nullable NSDictionary *)property;
/// Add an Error event
/// - Parameters:
/// - type: error type
/// - message: error message
/// - stack: stack information
/// - property: event custom attributes (optional)
open func addError(withType: String, message: String, stack: String, property: [AnyHashable : Any]?)
/// Add an Error event
/// - Parameters:
/// - type: error type
/// - state: program running state
/// - message: error message
/// - stack: stack information
/// - property: event custom attributes (optional)
open func addError(withType type: String, state: FTAppState, message: String, stack: String, property: [AnyHashable : Any]?)
Code Example¶
// Scenario 1
[[FTExternalDataManager sharedManager] addErrorWithType:@"type" message:@"message" stack:@"stack"];
// Scenario 2: Dynamic parameters
[[FTExternalDataManager sharedManager] addErrorWithType:@"ios_crash" message:@"crash_message" stack:@"crash_stack" property:@{@"custom_key":@"custom_value"}];
// Scenario 3: Dynamic parameters
[[FTExternalDataManager sharedManager] addErrorWithType:@"ios_crash" state:FTAppStateUnknown message:@"crash_message" stack:@"crash_stack" property:@{@"custom_key":@"custom_value"}];
// Scenario 1
FTExternalDataManager.shared().addError(withType: "custom_type", message: "custom_message", stack: "custom_stack")
// Scenario 2: Dynamic parameters
FTExternalDataManager.shared().addError(withType: "custom_type", message: "custom_message", stack: "custom_stack",property: ["custom_key":"custom_value"])
// Scenario 3: Dynamic parameters
FTExternalDataManager.shared().addError(withType: "custom_type", state: .unknown, message: "custom_message", stack: "custom_stack", property: ["custom_key":"custom_value"])
LongTask¶
Usage¶
Code Example¶
Resource¶
Usage¶
/// HTTP request start
/// - Parameters:
/// - key: Request identifier
/// - property: Event custom attributes (optional)
- (void)startResourceWithKey:(NSString *)key property:(nullable NSDictionary *)property;
/// Add HTTP request data
///
/// - Parameters:
/// - key: Request identifier
/// - metrics: Request-related performance attributes
/// - content: Request-related data
- (void)addResourceWithKey:(NSString *)key metrics:(nullable FTResourceMetricsModel *)metrics content:(FTResourceContentModel *)content;
/// HTTP request end
/// - Parameters:
/// - key: Request identifier
/// - property: Event custom attributes (optional)
- (void)stopResourceWithKey:(NSString *)key property:(nullable NSDictionary *)property;
/// HTTP request start
/// - Parameters:
/// - key: Request identifier
/// - property: Event custom attributes (optional)
open func startResource(withKey key: String, property: [AnyHashable : Any]?)
/// HTTP request end
/// - Parameters:
/// - key: Request identifier
/// - property: Event custom attributes (optional)
open func stopResource(withKey key: String, property: [AnyHashable : Any]?)
/// Add HTTP request data
///
/// - Parameters:
/// - key: Request identifier
/// - metrics: Request-related performance attributes
/// - content: Request-related data
open func addResource(withKey key: String, metrics: FTResourceMetricsModel?, content: FTResourceContentModel)
Code Example¶
//Step 1: Before request starts
[[FTExternalDataManager sharedManager] startResourceWithKey:key];
//Step 2: Request completed
[[FTExternalDataManager sharedManager] stopResourceWithKey:key];
//Step 3: Assemble Resource data
//FTResourceContentModel data
FTResourceContentModel *content = [[FTResourceContentModel alloc]init];
content.httpMethod = request.HTTPMethod;
content.requestHeader = request.allHTTPHeaderFields;
content.responseHeader = httpResponse.allHeaderFields;
content.httpStatusCode = httpResponse.statusCode;
content.responseBody = responseBody;
//ios native
content.error = error;
//If time data for each phase can be obtained
//FTResourceMetricsModel
//ios native obtains NSURLSessionTaskMetrics data, directly use FTResourceMetricsModel's initialization method
FTResourceMetricsModel *metricsModel = [[FTResourceMetricsModel alloc]initWithTaskMetrics:metrics];
//Other platforms, all time data in nanoseconds
FTResourceMetricsModel *metricsModel = [[FTResourceMetricsModel alloc]init];
//Step 4: add resource, if no time data, pass nil for metrics
[[FTExternalDataManager sharedManager] addResourceWithKey:key metrics:metricsModel content:content];
//Step 1: Before request starts
FTExternalDataManager.shared().startResource(withKey: key)
//Step 2: Request completed
FTExternalDataManager.shared().stopResource(withKey: resource.key)
//Step 3: ① Assemble Resource data
let contentModel = FTResourceContentModel(request: task.currentRequest!, response: task.response as? HTTPURLResponse, data: resource.data, error: error)
//② If time data for each phase can be obtained
//FTResourceMetricsModel
//ios native obtains NSURLSessionTaskMetrics data, directly use FTResourceMetricsModel's initialization method
var metricsModel:FTResourceMetricsModel?
if let metrics = resource.metrics {
metricsModel = FTResourceMetricsModel(taskMetrics:metrics)
}
//Other platforms, all time data in nanoseconds
metricsModel = FTResourceMetricsModel()
...
//Step 4: add resource, if no time data, pass nil for metrics
FTExternalDataManager.shared().addResource(withKey: resource.key, metrics: metricsModel, content: contentModel)