Real User Monitoring (RUM) provides SDK configuration items, allowing you to set parameters to meet specific requirements. This article describes the common SDK configuration items for iOS applications.
Startup configuration
Set endpoint address
Each app must be associated with a corresponding endpoint address. This method must be called before calling start:.
@objc
public static func setEndpoint(_ endpoint: String)Parameter | Description | Constraints | On failure |
endpoint | The endpoint address. | The string length must be greater than 0 and less than 256. | The API call fails, and SDK stops. |
Set workspace address
Each app must be associated with a corresponding workspace. This method must be called before calling start:.
@objc
public static func setWorkspace(_ workspace: String)Parameter | Description | Constraints | On failure |
workspace | The workspace address. | The string length must be greater than 0 and less than 256. | The API call fails, and SDK initialization fails. |
Start API
Call the start: method to initialize the SDK.
@objc(start:)
public static func start(_ serviceId: String)Parameter | Description | Constraints | On failure |
serviceId | The unique app ID generated by the RUM platform. | — | The API call fails, and SDK stops. |
Set custom device ID
Call this method to set a custom device ID. After a custom device ID is set, the SDK uses this ID instead of the default, automatically acquired ID.
@objc
public static func setDeviceID(_ deviceID: String)Parameter | Description | Constraints | On failure |
deviceID | The custom device ID. | The string length must be greater than 0 and less than 256. The string can contain only letters, digits, colons (:), spaces, underscores (_), hyphens (-), periods (.), and at signs (@). | The API call fails and the setting is ignored. |
Set custom app version
The SDK reports the app version you set with this method instead of the default, auto-detected version.
@objc
public static func setAppVersion(_ appVersion: String)Parameter | Description | Constraints | On failure |
appVersion | The custom app version. | The string length must be greater than 0 and less than 64. | The API call fails and the setting is ignored. |
Set channel ID
This method specifies the application's distribution channel.
@objc
public static func setChannelID(_ channelID: String)Parameter | Description | Constraints | On failure |
channelID | The custom channel ID. | The string length must be greater than 0 and less than 256. | The API call fails and the setting is ignored. |
Exclude specific classes
This method adds the specified class name to a swizzling exclusion set. The SDK then skips automatic analysis and instrumentation for any class whose name contains the specified substring. Call this method to exclude a class if you do not want to collect its data or if you encounter compatibility issues. You can call this method multiple times.
Note: This method must be called before SDK initialization. Use the exclusion keyword with caution to avoid unintentionally excluding classes that match the substring.
@objc(excludeClassFromTracking:)
public static func excludeClassFromTracking(_ className: String)Parameter | Description | Constraints | On failure |
className | The name of the class to exclude. | The class name cannot be empty. | The setting is not applied. |
Example:
// Excludes all classes whose names contain StoreKit2ViewController.
[AlibabaCloudRUM excludeClassFromTracking:@"StoreKit2ViewController"];
// Excludes all classes whose names contain BTDemoStoreKit2MixedBridge.
[AlibabaCloudRUM excludeClassFromTracking:@"BTDemoStoreKit2MixedBridge"];Disable or enable modules
These methods disable or enable specific data collection modules. Local configurations take precedence over remote configurations. The settings are cumulative across multiple calls.
Note: These methods must be called before SDK initialization. Local configurations take precedence over remote configurations, so use these settings with caution.
@objc(disableModule:)
public static func disableModule(_ module: AlibabaCloudModule)
@objc(enableModule:)
public static func enableModule(_ module: AlibabaCloudModule)
@objc(AlibabaCloudModule)
public enum AlibabaCloudModule: Int {
case crash = 0
case network = 1
case view = 2
case action = 3
case webView = 4
case longTask = 5
case appLaunch = 6
case appState = 7
case netState = 8
case customEvent = 9
case customLog = 10
case customMetric = 11
case oom = 12
case sessionReplay = 13
}Parameter | Description | Constraints | On failure |
module | The data collection module to disable or enable. | Must be a value from the AlibabaCloudModule enumeration. | The setting is not applied. |
Objective-C example:
// Enables the OOM data collection module.
[AlibabaCloudRUM enableModule:AlibabaCloudModuleOOM];
// Disables the network data collection module.
[AlibabaCloudRUM disableModule:AlibabaCloudModuleNetwork];
// Session Replay depends on the View module. We recommend that you explicitly enable both.
[AlibabaCloudRUM enableModule:AlibabaCloudModuleView];
[AlibabaCloudRUM enableModule:AlibabaCloudModuleSessionReplay];Swift example:
// Session Replay depends on the View module. We recommend that you explicitly enable both.
AlibabaCloudRUM.enableModule(.view)
AlibabaCloudRUM.enableModule(.sessionReplay)Disable or enable self-monitoring
The SDK collects self-monitoring data to continuously improve SDK performance and user experience. By default, the SDK collects self-monitoring data. Use this toggle to disable or re-enable this capability.
Note: This method must be called before SDK initialization.
+ (void)setSelfMonitorEnabled:(BOOL)enabled NS_SWIFT_NAME(setSelfMonitorEnabled(_:));Parameter | Description | Constraints | On failure |
enabled | Specifies whether to enable or disable SDK self-monitoring data collection. | Must be of type | The setting is not applied. |
Example:
// Enable SDK self-monitoring data collection.
[AlibabaCloudRUM setSelfMonitorEnabled:YES];Set app environment
This method specifies the application environment, such as LOCAL, DAILY, or PROD.
@objc
public static func setEnvironment(_ env: Env)Parameter | Description | Constraints | On failure |
env | The enum value for the application environment. This method must be called before the | Env enum values:
| The API call fails, and the setting is ignored. |
Capture resource snapshots
The SDK can capture the headers and bodies of HTTP requests and responses. By default, the SDK does not capture any resource snapshots. You must explicitly enable this feature using the API described in this section.
To capture snapshots from the HttpClient library, you must explicitly enable the feature by setting a ResourceSnapshotProvider.
void setResourceSnapshotProvider(ResourceSnapshotProvider? provider)Parameter | Description | Type | Return value |
onRequestHeaders | A callback that receives an HttpClientRequest object. | Map<String, Object>? | Returns the request headers to capture. If |
onRequestPayload | A callback that receives an HttpClientRequest object. | String? | Returns the request body to capture. If |
onResponseHeaders | A callback that receives an HttpClientResponse object. | Map<String, Object>? | Returns the response headers to capture. If |
onResponsePayload | A callback that receives an HttpClientResponse object. | String? | Returns the response body to capture. If |
The ResourceSnapshotUtils utility class
The HttpClientRequest object is a write-only stream, and the HttpClientResponse object is a read-only stream. Therefore, you must use this utility class to cache their bodies before they are consumed.
Method | Description |
| Caches the request body. You must call this method before calling |
| Gets the cached request body. |
| Caches the response body. Call this method after you read from the response stream. |
| Gets the cached response body. |
Due to limitations in the HttpClient library and the SDK implementation, capturing the response body is not currently supported.
You must use the
ResourceSnapshotUtilsclass to capture the request body.
Example:
AlibabaCloudRUM().setResourceSnapshotProvider(
ResourceSnapshotProvider(
onRequestHeaders: (request) {
return {
'content-type': request.headers.value('content-type') ?? '',
};
},
onRequestPayload: (request) {
// Because the request object does not expose its body, you must manually cache it.
// Call `ResourceSnapshotUtils.cacheRequestBody` when the request is initiated to cache the body.
final body = ResourceSnapshotUtils.getCachedRequestBody(request);
if (body == null) return null;
// Note: Data masking is required.
return body.replaceAll(RegExp(r'"password":\s*"[^"]*"'), '"password":"***"');
},
onResponsePayload: (response) {
// Capturing the response body is not currently supported.
return null;
},
),
);Usage notes
By default, the SDK does not capture any headers or bodies. You must explicitly enable this feature using the API.
You are responsible for data masking. The SDK does not automatically filter any sensitive information, such as passwords or personal data.
Session replay
Session replay records the page content and user interactions in a user session, which helps you troubleshoot page exceptions and user experience issues.
Enable session replay
Enable the session replay module before the RUM SDK is initialized, and start session replay after initialization is complete.
Swift
AlibabaCloudRUM.enableModule(.sessionReplay)
AlibabaCloudRUM.start(serviceId)
AlibabaCloudSessionReplay.start()Objective-C
[AlibabaCloudRUM enableModule:AlibabaCloudModuleSessionReplay];
[AlibabaCloudRUM start:serviceId];
[AlibabaCloudSessionReplay start];Configure session replay
In most cases, call AlibabaCloudSessionReplay.start() to use the default configurations. By default, the sample rate is 100%, all text and images are masked, and touch positions are hidden.
To adjust the sample rate or the privacy policy, use AlibabaCloudSessionReplayConfiguration. This class contains the following read-only configuration items, all of which must be specified during initialization.
Configuration item | Value | Description |
|
| The session replay sample rate, in percent. |
|
| Masks static text, input content, and hint text. |
| Keeps static text and hint text, and masks all input content. | |
| Keeps static text, hint text, and regular input. Masks only the input in
| |
|
| Masks all images. |
| Displays images that can be identified as app bundled resources or as system context, and masks dynamic images and images whose source cannot be determined. | |
| Does not mask images. A capturable | |
|
| Does not record touch positions. |
| Records touch positions and displays them during replay. |
Custom configuration example:
let configuration = AlibabaCloudSessionReplayConfiguration(
sampleRate: 10,
textAndInputPrivacy: .maskAll,
imagePrivacy: .maskAll,
touchPrivacy: .hide
)
AlibabaCloudSessionReplay.start(configuration)Stop session replay
Call stop() to stop session replay. This method stops the SDK from receiving new replay data. Data that has already been received is still processed and reported asynchronously as usual.
Swift
AlibabaCloudSessionReplay.stop()Objective-C
[AlibabaCloudSessionReplay stop];Privacy compliance notes
(Recommended) Keep
.maskAllfor text and images and.hidefor touch positions, and relax these settings only after you complete a privacy assessment..maskSensitiveInputsrelies on system information such assecureTextEntryandUITextContentTypeto identify sensitive fields. It is not a substitute for your own privacy review of page content and input fields.imagePrivacy: .maskNonedisables image masking. For a capturableUIImageView.image(backed by aCGImage), the SDK encodes the actual image as a replay resource and reports it, instead of recording only the image area. As a result, content such as avatars, order images, or business screenshots may be included in the replay data.touchPrivacy: .showrecords the touch positions of users. Assess the associated risks before you enable this option.Disclose the collection purpose, data scope, usage, and retention of session replay in your app privacy policy and App Store privacy labels, and obtain user consent in accordance with applicable laws and regulations.
Custom information
Set user ID
Associate monitoring data with a user ID to enable filtering and analysis by user.
@objc
public static func setUserName(_ userID: String)Parameter | Description | Constraints | On failure |
userID | A string that uniquely identifies the user. | The string can be null or an empty string. The string must not exceed 256 characters. It can contain only letters, digits, spaces, and the following characters: :, /, _, -, ., and @. | The call fails without applying the setting. |
Set user metadata
Attach key-value metadata to the current user to support per-user analysis.
@objc(setUserExtraInfo:)
public static func setUserExtraInfo(_ extraInfo: [String: AnyObject])Parameter | Description | Constraints | On failure |
extraInfo | User metadata as key-value pairs. | The map can be null or empty. The serialized JSON string must not exceed 7,000 characters. | The method call fails, and the setting is not applied. |
Set custom global properties
Once set, custom global properties are automatically attached to all subsequent data. Use these business properties to segment and analyze your data.
// Replaces all existing global properties
@objc(setExtraInfo:)
public static func setExtraInfo(_ extraInfo: [String: AnyObject])
// Appends to existing global properties
@objc(addExtraInfo:)
public static func addExtraInfo(_ extraInfo: [String: AnyObject])Parameter | Description | Constraints | On failure |
extraInfo | The properties to set, as key-value pairs. | The map can be | The API call fails, and the properties are not set. |
Calling setExtraInfo replaces all existing properties. To preserve existing properties while adding new ones, use addExtraInfo.
Custom exception
Call this interface to report custom exception data.
@objc(setCustomException:causeBy:errorDump:)
public static func setCustomException(_ exceptionType: String, _ causeBy: String, _ errorDump: String)Parameter | Description | Constraints | On failure |
exceptionType | The exception type. This parameter is required. | The string must contain 1 to 256 characters. | The call fails, and the exception is not reported. |
causeBy | A description of the exception's cause. | Can be null or an empty string. Strings longer than 512 characters are truncated. | N/A |
errorDump | The error dump. For example, a stack trace. | Can be null or an empty string. Strings longer than 10,000 characters are truncated. | N/A |
Custom event
The SDK lets you report custom events. Call the appropriate method with its parameters to collect the data.
@objc(setCustomEvent:)
public static func setCustomEvent(_ name: String)Parameter | Description | Constraints | On failure |
name | event name (required) | The string must contain 1 to 256 characters. | The call fails, and the event is not reported. |
@objc(setCustomEvent:group:)
public static func setCustomEvent(_ name: String, group: String? = nil)Parameter | Description | Constraints | On failure |
name | event name (required) | The string must contain 1 to 256 characters. | The call fails, and the event is not reported. |
group | event group | Can be Strings longer than 256 characters are truncated. | N/A |
@objc(setCustomEvent:group:snapshots:)
public static func setCustomEvent(_ name: String, group: String? = nil, snapshots: String? = nil)Parameter | Description | Constraints | On failure |
name | event name (required) | The string must contain 1 to 256 characters. | The call fails, and the event is not reported. |
group | event group | Can be Strings longer than 256 characters are truncated. | N/A |
snapshots | event snapshot | Can be Strings longer than 7,000 characters are truncated. | N/A |
@objc(setCustomEvent:group:value:)
public static func setCustomEvent(_ name: String, group: String? = nil, value: Double = 0)Parameter | Description | Constraints | On failure |
name | event name (required) | The string must contain 1 to 256 characters. | The call fails, and the event is not reported. |
group | event group | Can be Strings longer than 256 characters are truncated. | N/A |
value | event value | A value of the | N/A |
@objc(setCustomEvent:group:info:)
public static func setCustomEvent(_ name: String, group: String? = nil, info: [String: String]? = nil)Parameter | Description | Constraints | On failure |
name | event name (required) | The string must contain 1 to 256 characters. | The call fails, and the event is not reported. |
group | event group | Can be Strings longer than 256 characters are truncated. | N/A |
info | metadata | The map can be | The call fails, and the event is not reported. |
@objc(setCustomEvent:group:snapshots:value:)
public static func setCustomEvent(_ name: String, group: String? = nil, snapshots: String? = nil, value: Double = 0) Parameter | Description | Constraints | On failure |
name | event name (required) | The string must contain 1 to 256 characters. | The call fails, and the event is not reported. |
group | event group | Can be Strings longer than 256 characters are truncated. | N/A |
snapshots | event snapshot | Can be Strings longer than 7,000 characters are truncated. | N/A |
value | event value | A value of the | N/A |
@objc(setCustomEvent:group:snapshots:info:)
public static func setCustomEvent(_ name: String, group: String? = nil, snapshots: String? = nil, info: [String: String]? = nil)Parameter | Description | Constraints | On failure |
name | event name (required) | The string must contain 1 to 256 characters. | The call fails, and the event is not reported. |
group | event group | Can be Strings longer than 256 characters are truncated. | N/A |
snapshots | event snapshot | Can be Strings longer than 7,000 characters are truncated. | N/A |
info | metadata | The map can be | The call fails, and the event is not reported. |
@objc(setCustomEvent:group:value:info:)
public static func setCustomEvent(_ name: String, group: String? = nil, value: Double = 0, info: [String: String]? = nil) Parameter | Description | Constraints | On failure |
name | event name (required) | The string must contain 1 to 256 characters. | The call fails, and the event is not reported. |
group | event group | Can be Strings longer than 256 characters are truncated. | N/A |
value | event value | A value of the | N/A |
info | metadata | The map can be | The call fails, and the event is not reported. |
@objc(setCustomEvent:group:snapshots:value:info:)
public static func setCustomEvent(_ name: String, group: String? = nil, snapshots: String? = nil, value: Double = 0, info: [String: String]? = nil)Parameter | Description | Constraints | On failure |
name | event name (required) | The string must contain 1 to 256 characters. | The call fails, and the event is not reported. |
group | event group | Can be Strings longer than 256 characters are truncated. | N/A |
snapshots | event snapshot | Can be Strings longer than 7,000 characters are truncated. | N/A |
value | event value | A value of the | N/A |
info | metadata | The map can be | The call fails, and the event is not reported. |
Custom log
The SDK lets you report custom logs. To record a log, call the appropriate method with the required parameters.
@objc(setCustomLog:)
public static func setCustomLog(_ logInfo: String)Parameter | Description | Constraints | Failure result |
logInfo | The log message. This parameter is required. | Must be between 1 and 10,000 characters. Longer strings are truncated. | The API call fails, and the log is discarded. |
@objc(setCustomLog:name:)
public static func setCustomLog(_ logInfo: String, name: String? = nil) Parameter | Description | Constraints | Failure result |
logInfo | The log message. This parameter is required. | Must be between 1 and 10,000 characters. Longer strings are truncated. | The API call fails, and the log is discarded. |
name | The log name for categorization. | Must be between 1 and 256 characters. | N/A |
@objc(setCustomLog:name:snapshots:)
public static func setCustomLog(_ logInfo: String, name: String? = nil, snapshots: String? = "") Parameter | Description | Constraints | Failure result |
logInfo | The log message. This parameter is required. | Must be between 1 and 10,000 characters. Longer strings are truncated. | The API call fails, and the log is discarded. |
name | The log name for categorization. | Must be between 1 and 256 characters. | N/A |
snapshots | A log snapshot of relevant data. | Can be Maximum 7,000 characters. Longer strings are truncated. | N/A |
@objc(setCustomLog:name:snapshots:level:info:)
public static func setCustomLog(_ logInfo: String, name: String? = nil, snapshots: String? = "", level: String? = "INFO", info: [String: String]? = nil)Parameter | Description | Constraints | Failure result |
logInfo | The log message. This parameter is required. | Must be between 1 and 10,000 characters. Longer strings are truncated. | The API call fails, and the log is discarded. |
name | The log name for categorization. | Must be between 1 and 256 characters. | N/A |
snapshots | A log snapshot of relevant data. | Can be Maximum 7,000 characters. Longer strings are truncated. | N/A |
level | The log level. | Must be between 1 and 256 characters. Defaults to | N/A |
info | Additional log metadata. | Can be When serialized to a JSON string, the length of | The API call fails, and the log is discarded. |
Custom resource
The SDK allows you to report data for custom network resource requests and record detailed information for HTTP/HTTPS requests, including request status, performance metrics, and tracing. The SDK offers two overloaded methods for basic and advanced use cases.
Basic scenario
@objc(setCustomResource:success:url:method:statusCode:errorMessage:)
public static func setCustomResource(_ type: String, success: Bool, url: String, method: String, statusCode: Int, errorMessage: String?) -> BoolParameter | Type | Description | Constraints |
type | String | The resource type, such as | Length: 1 to 64 characters. Longer strings are truncated. |
success | Bool | Indicates whether the request was successful. |
|
url | String | The full URL of the request. | Length: 1 to 1,024 characters. Longer strings are truncated. |
method | String | The HTTP request method, such as | Length: 1 to 24 characters. Longer strings are truncated. |
statusCode | Int | The HTTP status code. | Examples: 200, 404, 500. |
errorMessage | String? | The error message, provided only when the request fails. | Length: 1 to 256 characters. Longer strings are truncated. Can be |
Return value: Bool - A boolean value that indicates whether the API call succeeded. true is returned on success, and false is returned on failure (for example, if the SDK is not initialized or the parameters are invalid).
Example
// Swift - Successful GET request
let result = AlibabaCloudRUM.setCustomResource(
"API",
success: true,
url: "https://api.example.com/users",
method: "GET",
statusCode: 200,
errorMessage: nil
)
// Swift - Failed POST request
let result2 = AlibabaCloudRUM.setCustomResource(
"API",
success: false,
url: "https://api.example.com/login",
method: "POST",
statusCode: 401,
errorMessage: "Unauthorized access"
)// Objective-C - Successful GET request
BOOL result = [AlibabaCloudRUM setCustomResource:@"API"
success:YES
url:@"https://api.example.com/users"
method:@"GET"
statusCode:200
errorMessage:nil];
// Objective-C - Failed POST request
BOOL result2 = [AlibabaCloudRUM setCustomResource:@"API"
success:NO
url:@"https://api.example.com/login"
method:@"POST"
statusCode:401
errorMessage:@"Unauthorized access"];
Advanced scenario
For advanced scenarios, this method overload lets you report detailed performance metrics and tracing data.
@objc(setCustomResource:success:url:method:statusCode:errorMessage:provider:tracing:measure:)
public static func setCustomResource(_ type: String, success: Bool, url: String, method: String, statusCode: Int, errorMessage: String?, provider: String?, tracing: AlibabaCloudTracingContext?, measure: AlibabaCloudResourceMeasure?) -> BoolParameter | Type | Description | Constraints |
type | String | The resource type. | Length: 1 to 64 characters. Longer strings are truncated. |
success | Bool | Specifies if the request was successful. |
|
url | String | The full URL of the request. | Length: 1 to 1,024 characters. Longer strings are truncated. |
method | String | The HTTP request method. | Length: 1 to 24 characters. Longer strings are truncated. |
statusCode | Int | The HTTP response status code. | A standard HTTP status code, such as |
errorMessage | String? | The error message. | The value can be |
provider | String? | The identifier of the service provider, such as | The string length must be greater than 0 and less than or equal to 256. Strings that exceed this length are truncated. The value can be |
tracing | AlibabaCloudTracingContext? | The tracing context. | The type is AlibabaCloudTracingContext. The value can be |
measure | AlibabaCloudResourceMeasure? | The resource performance metric. | The AlibabaCloudResourceMeasure type can be |
Return value: Bool - Indicates whether the API call was successful. true indicates success, and false indicates failure.
Example:
// Swift - Create a resource performance metric object
let measure = AlibabaCloudResourceMeasure.measure()
measure.duration = 850
measure.size = 10240
measure.dnsDuration = 30
measure.connectDuration = 80
measure.sslDuration = 120
measure.firstByteDuration = 250
measure.downloadDuration = 370
// Create a tracing context
let traceId = AlibabaCloudTraceGenerator.generateTraceId(.SkywalkingV3)
let spanId = AlibabaCloudTraceGenerator.generateTraceId(.SkywalkingV3)
let tracing = AlibabaCloudTracingContext(traceId: traceId, spanId: spanId, tracingProtocol: .SkywalkingV3)
// Report the complete resource data
let result = AlibabaCloudRUM.setCustomResource(
"HTTPS",
success: true,
url: "https://api.example.com/v2/data",
method: "POST",
statusCode: 200,
errorMessage: nil,
provider: "Aliyun",
tracing: tracing,
measure: measure
)// Objective-C - Create a resource performance metric object
AlibabaCloudResourceMeasure *measure = [AlibabaCloudResourceMeasure measure];
measure.duration = 850;
measure.size = 10240;
measure.dnsDuration = 30;
measure.connectDuration = 80;
measure.sslDuration = 120;
measure.firstByteDuration = 250;
measure.downloadDuration = 370;
// Create a tracing context
NSString *traceId = [AlibabaCloudTracingGenerator generateTraceId:AlibabaCloudTracingProtocolW3C];
NSString *spanId = [AlibabaCloudTracingGenerator generateSpanId:AlibabaCloudTracingProtocolW3C];
AlibabaCloudTracingContext *tracing = [AlibabaCloudTracingContext contextWithTraceId:traceId
spanId:spanId
protocol:AlibabaCloudTracingProtocolW3C
];
// Report the complete resource data
BOOL result = [AlibabaCloudRUM setCustomResource:@"HTTPS"
success:YES
url:@"https://api.example.com/v2/data"
method:@"POST"
statusCode:200
errorMessage:nil
provider:@"Aliyun"
tracing:tracing
measure:measure];Helper types
AlibabaCloudTracingContext
Stores the context for distributed tracing. Supports both the W3C Trace Context and SkyWalking V3 protocols.
Creating an instance:
// Swift - Generate a TraceId and SpanId
let traceId = AlibabaCloudTracingGenerator.generateTraceId(.SkywalkingV3)
let spanId = AlibabaCloudTracingGenerator.generateSpanId(.SkywalkingV3)
// Swift - Create a tracing context
let tracingContext = AlibabaCloudTracingContext(traceId: traceId, spanId: spanId, protocol: .SkywalkingV3)// Objective-C - Generate a TraceId and SpanId
NSString *traceId = [AlibabaCloudTracingGenerator generateTraceId:AlibabaCloudTracingProtocolW3C];
NSString *spanId = [AlibabaCloudTracingGenerator generateSpanId:AlibabaCloudTracingProtocolW3C];
// Objective-C - Create a context
AlibabaCloudTracingContext *context = [AlibabaCloudTracingContext contextWithTraceId:traceId
spanId:spanId
tracingProtocol:AlibabaCloudTracingProtocolW3C
];Supported protocols:
W3C: The W3C Trace Context protocol.SkywalkingV3: The Apache SkyWalking V3 protocol.
AlibabaCloudResourceMeasure
Records performance metrics for a network request.
Parameter | Type | Description |
duration | NSUInteger | The total duration, in milliseconds. |
size | NSUInteger | The response size, in bytes. |
connectDuration | NSUInteger | The TCP connection duration, in milliseconds. |
sslDuration | NSUInteger | The SSL/TLS handshake duration, in milliseconds. |
dnsDuration | NSUInteger | The DNS resolution duration, in milliseconds. |
redirectDuration | NSUInteger | The redirect duration, in milliseconds. |
firstByteDuration | NSUInteger | The time to first byte (TTFB), in milliseconds. |
downloadDuration | NSUInteger | The download duration, in milliseconds. |
Creating an instance:
// Swift
let measure = AlibabaCloudResourceMeasure.measure()
measure.duration = 1200
measure.size = 5120
measure.dnsDuration = 50
measure.connectDuration = 100
measure.sslDuration = 150
measure.firstByteDuration = 300
measure.downloadDuration = 600// Objective-C
AlibabaCloudResourceMeasure *measure = [AlibabaCloudResourceMeasure measure];
measure.duration = 1200;
measure.size = 5120;
measure.dnsDuration = 50;
measure.connectDuration = 100;
measure.sslDuration = 150;
measure.firstByteDuration = 300;
measure.downloadDuration = 600;Notes
Return Value Check: Check the method's return value. A return value of
falseindicates a call failure.Asynchronous reporting: A successful API call that returns
trueonly indicates that the SDK has accepted the data. The actual data reporting is an asynchronous operation.