Skip to content

RUM Configuration

RUM Initialization Configuration

FTRumConfig *rumConfig = [[FTRumConfig alloc] initWithAppid:appid];
rumConfig.enableTrackAppCrash = YES;
rumConfig.enableTrackAppANR = YES;
rumConfig.enableTrackAppFreeze = YES;
rumConfig.enableTraceUserAction = YES;
rumConfig.enableTraceUserView = YES;
rumConfig.enableTraceUserResource = YES;
rumConfig.errorMonitorType = FTErrorMonitorAll;
rumConfig.deviceMetricsMonitorType = FTDeviceMetricsMonitorAll;
[[FTSDKAgent sharedInstance] startRumWithConfigOptions:rumConfig];
let rumConfig = FTRumConfig(appid: appid)
rumConfig.enableTraceUserAction = true
rumConfig.enableTrackAppANR = true
rumConfig.enableTraceUserView = true
rumConfig.enableTraceUserResource = true
rumConfig.enableTrackAppCrash = true
rumConfig.enableTrackAppFreeze = true
rumConfig.errorMonitorType = .all
rumConfig.deviceMetricsMonitorType = .all
rumConfig.monitorFrequency = .rare
FTSDKAgent.sharedInstance().startRum(withConfigOptions: rumConfig)
Property Type Required Description
appid NSString Yes The unique identifier for the RUM application ID. The RUM collection function is enabled only when the RUM appid is set. How to obtain the appid
sampleRate int No Sampling rate. Value range [0,100], 0 means no collection, 100 means full collection, default value 100. The scope applies to all View, Action, LongTask, and Error data under the same session_id.
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.
enableTraceUserView BOOL No Sets whether to track user View operations, default NO.
enableTraceUserAction BOOL No Sets whether to track user Action operations, default NO.
enableTraceUserResource BOOL No Sets whether to track user network requests, default NO, only applies to native HTTP requests.
resourceUrlHandler FTResourceUrlHandler No Custom rules for Resource collection. By default, no filtering is applied. Returning NO indicates collection, returning YES indicates no collection. For detailed instructions, see Data Collection Custom Rules.
errorMonitorType FTErrorMonitorType No Supplementary error event monitoring types. Adds monitoring information to collected crash data, default is not set.
monitorFrequency FTMonitorFrequency No Sampling period for view performance monitoring.
deviceMetricsMonitorType FTDeviceMetricsMonitorType No Types of view performance monitoring. Adds corresponding monitoring item information to the collected View data, default is not set.
globalContext NSDictionary No Adds custom tags for distinguishing user monitoring data sources. If the tracing function is needed, the parameter key should be track_id and value can be any numerical value. For addition rules, refer to Custom Tag Usage.

RUM User Data Tracking

It can be enabled in automatic mode via FTRUMConfig configuration or added manually. RUM-related data is passed through the FTGlobalRumManager singleton. The related APIs are as follows.

View

If enableTraceUserView = YES is set to enable automatic collection, the SDK will automatically collect the Window lifecycle. The start of a View is defined by the Window lifecycle -becomeKeyWindow, and the end is defined by -resignKeyWindow.

The page name is set based on the priority order: NSStringFromClass(window.contentViewController.class) > NSStringFromClass(window.windowController.class) > NSStringFromClass(window).

If the views within the Window are very complex, you can use the following APIs for custom collection.

Usage

/// Create a page
///
/// Called before the `-startViewWithName` method. This method is used to record the page loading time. If the loading time cannot be obtained, this method may not be called.
/// - Parameters:
///  - viewName: Page name
///  - loadTime: Page loading time (nanoseconds)
-(void)onCreateView:(NSString *)viewName loadTime:(NSNumber *)loadTime;

/// Enter a page
/// - Parameters:
///  - viewName: Page name
///  - property: Event custom properties (optional)
-(void)startViewWithName:(NSString *)viewName property:(nullable NSDictionary *)property;

/// Leave a page
/// - Parameter property: Event custom properties (optional)
-(void)stopViewWithProperty:(nullable NSDictionary *)property;
/// Create a page
///
/// Called before the `-startViewWithName` method. This method is used to record the page loading time. If the loading time cannot be obtained, this method may not be called.
/// - Parameters:
///  - viewName: Page name
///  - loadTime: Page loading time (ns)
open func onCreateView(_ viewName: String, loadTime: NSNumber)

/// Enter a page
/// - Parameters:
///  - viewName: Page name
///  - property: Event custom properties (optional)
open func startView(withName viewName: String, property: [AnyHashable : Any]?)

/// Leave a page
/// - Parameter property: Event custom properties (optional)
open func stopView(withProperty property: [AnyHashable : Any]?)

Code Example

- (void)viewDidAppear{
  [super viewDidAppear];
  [[FTGlobalRumManager sharedManager] startViewWithName:@"TestVC"];
  [[FTGlobalRumManager sharedManager] startViewWithName:@"TestVC" property:@{@"custom_key":@"custom_value"}];
}
-(void)viewDidDisappear{
  [super viewDidDisappear];
  [[FTGlobalRumManager sharedManager] stopView];
  [[FTGlobalRumManager sharedManager] stopViewWithProperty:@{@"custom_key":@"custom_value"}];
}
override func viewDidAppear() {
    super.viewDidAppear()
    FTExternalDataManager.shared().startView(withName: "TestVC")
    FTExternalDataManager.shared().startView(withName: "TestVC", property: ["custom_key":"custom_value"])
}
override func viewDidDisappear() {
    super.viewDidDisappear()
    FTGlobalRumManager.shared().stopView()
    FTGlobalRumManager.shared().stopView(withProperty: ["custom_key":"custom_value"])
}

Action

Usage

/// Add an Action event
/// - Parameters:
///   - actionName: Event name
///   - actionType: Event type
///   - property: Event custom properties (optional)
- (void)addActionName:(NSString *)actionName actionType:(NSString *)actionType property:(nullable NSDictionary *)property;
/// Add an Action event
/// - Parameters:
///   - actionName: Event name
///   - actionType: Event type
///   - property: Event custom properties (optional)
func addActionName(String, actionType: String, property: [AnyHashable : Any]?)

Code Example

[[FTGlobalRumManager sharedManager] addActionName:@"UITableViewCell click" actionType:@"click"];
[[FTGlobalRumManager sharedManager] addActionName:@"UITableViewCell click" actionType:@"click" property:@{@"custom_key":@"custom_value"}];
FTGlobalRumManager.shared().addActionName("custom_action", actionType: "click")
FTGlobalRumManager.shared().addActionName("custom_action", actionType: "click", property: ["custom_key":"custom_value"])

Error

Usage

/// Add an Error event
/// - Parameters:
///   - type: error type
///   - message: Error message
///   - stack: Stack trace information
///   - property: Event custom properties (optional)
- (void)addErrorWithType:(NSString *)type message:(NSString *)message stack:(NSString *)stack property:(nullable NSDictionary *)property;

/// Add an Error event
/// - Parameters:
///   - type: error type
///   - state: Application running state
///   - message: Error message
///   - stack: Stack trace information
///   - property: Event custom properties (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 trace information
///   - property: Event custom properties (optional)
open func addError(withType: String, message: String, stack: String, property: [AnyHashable : Any]?)

/// Add an Error event
/// - Parameters:
///   - type: error type
///   - state: Application running state
///   - message: Error message
///   - stack: Stack trace information
///   - property: Event custom properties (optional)
open func addError(withType type: String, state: FTAppState, message: String, stack: String, property: [AnyHashable : Any]?)

Code Example

[[FTGlobalRumManager sharedManager] addErrorWithType:@"type" message:@"message" stack:@"stack"];
[[FTGlobalRumManager sharedManager] addErrorWithType:@"ios_crash" message:@"crash_message" stack:@"crash_stack" property:@{@"custom_key":@"custom_value"}];
[[FTGlobalRumManager sharedManager] addErrorWithType:@"ios_crash" state:FTAppStateUnknown message:@"crash_message" stack:@"crash_stack" property:@{@"custom_key":@"custom_value"}];
FTGlobalRumManager.shared().addError(withType: "custom_type", message: "custom_message", stack: "custom_stack")
FTGlobalRumManager.shared().addError(withType: "custom_type", message: "custom_message", stack: "custom_stack", property: ["custom_key":"custom_value"])
FTGlobalRumManager.shared().addError(withType: "custom_type", state: .unknown, message: "custom_message", stack: "custom_stack", property: ["custom_key":"custom_value"])

LongTask

Usage

/// Add a LongTask event
/// - Parameters:
///   - stack: LongTask stack trace
///   - duration: LongTask duration (nanoseconds)
///   - property: Event custom properties (optional)
- (void)addLongTaskWithStack:(NSString *)stack duration:(NSNumber *)duration property:(nullable NSDictionary *)property;
/// Add a LongTask event
/// - Parameters:
///   - stack: LongTask stack trace
///   - duration: LongTask duration (nanoseconds)
///   - property: Event custom properties (optional)
func addLongTask(withStack: String, duration: NSNumber, property: [AnyHashable : Any]?)

Code Example

[[FTGlobalRumManager sharedManager] addLongTaskWithStack:@"stack string" duration:@1000000000];
[[FTGlobalRumManager sharedManager] addLongTaskWithStack:@"stack string" duration:@1000000000 property:@{@"custom_key":@"custom_value"}];
FTGlobalRumManager.shared().addLongTask(withStack: "stack string", duration: 1000000000)
FTGlobalRumManager.shared().addLongTask(withStack: "stack string", duration: 1000000000, property: ["custom_key":"custom_value"])

Resource

Usage

/// HTTP request start
/// - Parameters:
///   - key: Request identifier
///   - property: Event custom properties (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 properties (optional)
- (void)stopResourceWithKey:(NSString *)key property:(nullable NSDictionary *)property;
/// HTTP request start
/// - Parameters:
///   - key: Request identifier
///   - property: Event custom properties (optional)
open func startResource(withKey key: String, property: [AnyHashable : Any]?)

/// HTTP request end
/// - Parameters:
///   - key: Request identifier
///   - property: Event custom properties (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

#import "FTMacOSSDK.h"

[[FTGlobalRumManager sharedManager] startResourceWithKey:key];
[[FTGlobalRumManager sharedManager] stopResourceWithKey:key];

FTResourceContentModel *content = [[FTResourceContentModel alloc] init];
content.httpMethod = request.HTTPMethod;
content.requestHeader = request.allHTTPHeaderFields;
content.responseHeader = httpResponse.allHeaderFields;
content.httpStatusCode = httpResponse.statusCode;
content.responseBody = responseBody;
content.error = error;

FTResourceMetricsModel *metricsModel = [[FTResourceMetricsModel alloc] initWithTaskMetrics:metrics];
metricsModel = [[FTResourceMetricsModel alloc] init];

[[FTGlobalRumManager sharedManager] addResourceWithKey:key metrics:metricsModel content:content];
import FTMacOSSDK

FTGlobalRumManager.shared().startResource(withKey: key)
FTGlobalRumManager.shared().stopResource(withKey: resource.key)

let contentModel = FTResourceContentModel(request: task.currentRequest!, response: task.response as? HTTPURLResponse, data: resource.data, error: error)

var metricsModel: FTResourceMetricsModel?
if let metrics = resource.metrics {
   metricsModel = FTResourceMetricsModel(taskMetrics: metrics)
}
metricsModel = FTResourceMetricsModel()

FTGlobalRumManager.shared().addResource(withKey: resource.key, metrics: metricsModel, content: contentModel)