RUM Configuration¶
This document covers the HarmonyOS RUM initialization configuration and manual data collection capabilities.
RUM Initialization Configuration¶
import {
DetectFrequency,
DeviceMetricsMonitorType,
ErrorMonitorType,
FTSDK,
FTRUMConfig
} from '@guancecloud/ft_sdk/Index';
const rumConfig = new FTRUMConfig()
.setRumAppId('your-app-id')
.setSamplingRate(1.0)
.setSessionErrorSampleRate(1.0)
.setEnableTraceUserAction(true)
.setEnableTraceUserView(true)
.setEnableTraceUserResource(true)
.setEnableTrackAppUIBlock(true)
.setEnableTrackAppANR(true)
.setEnableTrackAppCrash(true)
.setEnableTraceWebView(true)
.setDeviceMetricsMonitorType(DeviceMetricsMonitorType.ALL, DetectFrequency.DEFAULT)
.setExtraMonitorTypeWithError(ErrorMonitorType.ALL)
.addGlobalContext('rum_channel', new String('official'));
FTSDK.installRUMConfig(rumConfig);
| Method | Type | Required | Description |
|---|---|---|---|
setRumAppId |
string |
Yes | RUM Application ID; obtain it from the [RUM] application |
setSamplingRate |
number |
No | RUM sampling rate, range [0.0, 1.0], default 1.0 |
setSessionErrorSampleRate |
number |
No | Error sampling rate, range [0.0, 1.0], default 0.0 |
setEnableTraceUserAction |
boolean |
No | Whether to enable automatic action tracking, default false |
setEnableTraceUserView |
boolean |
No | Whether to enable view tracking, default false |
setEnableTraceUserResource |
boolean |
No | Whether to enable resource tracking, default false |
setEnableTrackAppUIBlock |
boolean, number |
No | Whether to enable UI block detection, default false. The second parameter blockDurationMs controls the detection time range [100,) in milliseconds, default 1000ms |
setEnableTrackAppANR |
boolean |
No | Whether to enable ANR monitoring, default false |
setEnableTrackAppCrash |
boolean |
No | Whether to enable app crash monitoring, default false. For Native Crash, depends on @guancecloud/ft_native |
setEnableTraceWebView |
boolean |
No | Whether to enable WebView data collection, default false. For full integration, see WebView Data Monitoring |
setAllowWebViewHost |
Array<string> \| null |
No | Sets the Host allowlist permitted for the WebView JavaScript Bridge. Passing null or an empty array imposes no Host restrictions. To restrict, see WebView Data Monitoring |
setActionTrackingHandler |
FTActionTrackingHandler \| null |
No | Sets the filter handler for automatic Click Actions. Takes effect only after setEnableTraceUserAction(true) is enabled. Returning null skips collection, and returning undefined keeps the default collection flow. See Custom Data Collection Rules. Supported in ft-sdk 0.1.16 and later |
setViewTrackingHandler |
handler: FTViewTrackingHandler \| null, type?: FTViewTrackingType |
No | Sets the handler for Router, Navigation, or all automatic Views. Takes effect only after setEnableTraceUserView(true) is enabled. The handler receives FTViewTrackingContext; returning HandlerView allows you to rename or add attributes, and returning null skips collection. See Custom Data Collection Rules. Supported in ft-sdk 0.1.17 and later |
setResourceUrlHandler |
FTInTakeUrlHandler |
No | Sets the URL filter handler for automatic Resources. When the handler returns true, collection is skipped. This affects only automatic RCP, Axios, and NetworkKit Resources and does not affect Trace Header injection or manual Resources. See Custom Data Collection Rules. Supported in ft-sdk 0.1.17 and later |
setDeviceMetricsMonitorType |
DeviceMetricsMonitorType, DetectFrequency(可选) |
No | Sets View monitoring information and sampling frequency, adding monitoring data during the View lifecycle. The first parameter can use bitwise OR to combine CPU, MEMORY, BATTERY, and FPS, or use ALL to enable all of them. TV devices do not support battery metrics. The optional second parameter can be DetectFrequency.DEFAULT (500ms), DetectFrequency.FREQUENT (100ms), or DetectFrequency.RARE (1000ms); if not passed, the current sampling frequency is retained, with an initial value of DEFAULT. Collection is disabled by default. Supported in ft-sdk 0.1.16 and later |
setDeviceMetricsDetectFrequency |
DetectFrequency |
No | Legacy device metrics configuration method, kept only for source compatibility. Can be used together with the single-parameter setDeviceMetricsMonitorType(...). For new integrations, it is recommended to configure the collection type and frequency at once via setDeviceMetricsMonitorType(deviceMetricsMonitorType, detectFrequency) |
setExtraMonitorTypeWithError |
ErrorMonitorType |
No | Sets additional device metrics for Error events. Can use bitwise OR to combine CPU, MEMORY, and BATTERY, or use ALL to enable all of them. When enabled, CPU, memory, and battery related fields are added to Error data. Collection is disabled by default, and TV devices do not support battery metrics. For field descriptions, see App Data Collection. Supported in ft-sdk 0.1.16 and later |
addGlobalContext |
key: string, value: object |
No | Adds RUM custom tags to distinguish user monitoring data. See here for the rules |
setRumCacheLimitCount |
number |
No | RUM data cache size limit, default 100000, minimum 10000 |
setRumCacheDiscardStrategy |
RUMCacheDiscard |
No | Sets the discard rule for RUM data after the cache limit is reached. Defaults to RUMCacheDiscard.DISCARD; DISCARD discards newly appended data, and DISCARD_OLDEST discards the oldest data |
Manual RUM Collection¶
Configure setEnableTraceUserAction, setEnableTraceUserView, setEnableTraceUserResource, setEnableTrackAppUIBlock, setEnableTrackAppCrash, and setEnableTrackAppANR in FTRUMConfig to enable automatic collection of Action, View, Resource, LongTask, and Error. If you need custom collection, you can report data manually through FTRUMGlobalManager.
View¶
Usage¶
/**
* Starts the View lifecycle.
*
* @param viewName View name.
* @param property Optional extended attributes.
*/
startView(viewName: string, property?: Record<string, object>): Promise<void>
/**
* Ends the current View lifecycle.
*
* @param property Optional extended attributes.
*/
stopView(property?: Record<string, object>): Promise<void>
/**
* Updates the load time of the current View.
*
* @param loadTime Load time in nanoseconds.
*/
updateLoadTime(loadTime: number): void
Code Example¶
import { FTRUMGlobalManager } from '@guancecloud/ft_sdk/Index';
@Entry
@Component
struct ProductPage {
async aboutToAppear() {
// Scenario 1:
await FTRUMGlobalManager.getInstance().startView('ProductPage');
// Scenario 2: With extended attributes
const viewProperty: Record<string, object> = { page_category: new String('product'), page_id: new String('12345') };
await FTRUMGlobalManager.getInstance().startView('ProductPage', viewProperty);
}
async aboutToDisappear() {
// Scenario 1:
await FTRUMGlobalManager.getInstance().stopView();
// Scenario 2:
const stopViewProperty: Record<string, object> = { view_duration: new Number(1000) };
await FTRUMGlobalManager.getInstance().stopView(stopViewProperty);
}
build() {
Column() {
Text('Product Page');
}
}
}
Action¶
Usage¶
/**
* Adds a completed Action; this data is not associated with Error, Resource, or LongTask.
*
* @param actionName Action name.
* @param actionType Action type, for example `click`.
* @param durationOrProperty Optional. When a number is passed, it represents the duration in nanoseconds; when a Record is passed, it represents extended attributes.
* @param property Optional. Pass extended attributes only when the third parameter is a duration.
*/
addAction(
actionName: string,
actionType: string,
durationOrProperty?: number | Record<string, object>,
property?: Record<string, object>
): void
/**
* Starts an Action; the SDK manages when it ends and associates nearby Resource, LongTask, and Error data.
*
* @param actionName Action name.
* @param actionType Action type, for example `click`.
* @param property Optional extended attributes.
*/
startAction(
actionName: string,
actionType: string,
property?: Record<string, object>
): void
addAction(...) is used for Actions that are completed directly and cannot be associated with Error, Resource, LongTask, or other data. duration is in nanoseconds: the third parameter can pass extended attributes directly; to pass both the duration and extended attributes, pass them as the third and fourth parameters in that order.
With startAction(...), the SDK manages the end timing and associated data. Manual control interfaces such as stopAction(...) and waiting state are not currently provided.
Code Example¶
import { FTRUMGlobalManager } from '@guancecloud/ft_sdk/Index';
// Scenario 1:
FTRUMGlobalManager.getInstance().addAction('buy_button_click', 'click');
// Scenario 2: With extended attributes
const actionProperty: Record<string, object> = {
product_id: new String('product_id'),
product_name: new String('product_name')
};
FTRUMGlobalManager.getInstance().addAction('buy_button_click', 'click', actionProperty);
// Scenario 1:
FTRUMGlobalManager.getInstance().startAction('buy_button_click', 'click');
// Scenario 2: With extended attributes
const startActionProperty: Record<string, object> = {
product_id: new String('product_id'),
product_name: new String('product_name')
};
FTRUMGlobalManager.getInstance().startAction('buy_button_click', 'click', startActionProperty);
Error¶
Usage¶
/**
* Reports an Error.
*
* @param log Error log or stack information.
* @param message Message.
* @param errorType Error type; can be an `ErrorType` enum or a string.
* @param state App running state when the error occurred.
* @param property Optional extended attributes.
*/
addError(
log: string,
message: string,
errorType: string | ErrorType,
state: AppState,
property?: Record<string, object> | null
): void
/**
* Reports an Error with a specified occurrence time.
*
* @param log Error log or stack information.
* @param message Message.
* @param dateline Error occurrence time in nanoseconds.
* @param errorType Error type; can be an `ErrorType` enum or a string.
* @param state App running state when the error occurred.
* @param property Optional extended attributes.
*/
addError(
log: string,
message: string,
dateline: number,
errorType: string | ErrorType,
state: AppState,
property?: Record<string, object> | null
): void
Use ErrorType.CUSTOM for custom Errors. dateline is the optional occurrence time in nanoseconds.
Code Example¶
import { FTRUMGlobalManager, ErrorType, AppState } from '@guancecloud/ft_sdk/Index';
import { systemDateTime } from '@kit.BasicServicesKit';
// Scenario 1:
FTRUMGlobalManager.getInstance().addError('error log', 'error message', ErrorType.CUSTOM, AppState.RUN);
// Scenario 2: For delayed reporting, pass the actual error occurrence time (in nanoseconds).
const errorTimeNs = systemDateTime.getTime(true);
FTRUMGlobalManager.getInstance().addError('error log', 'error message', errorTimeNs, ErrorType.CUSTOM, AppState.RUN);
// Scenario 3: With extended attributes.
const errorProperty: Record<string, object> = {
module: new String('checkout'),
action: new String('submit_order')
};
FTRUMGlobalManager.getInstance().addError('error log', 'error message', ErrorType.CUSTOM, AppState.RUN, errorProperty);
LongTask¶
Usage¶
/**
* Reports a LongTask.
*
* @param log Log or stack information during the freeze.
* @param duration Freeze duration in nanoseconds.
* @param property Optional extended attributes.
*/
addLongTask(log: string, duration: number, property?: Record<string, string | number | boolean>): void
duration is in nanoseconds.
Code Example¶
import { FTRUMGlobalManager } from '@guancecloud/ft_sdk/Index';
const durationMs = 350;
const durationNs = durationMs * 1000000;
const stack = new Error('checkout render long task').stack ?? 'Stack trace not available';
// Scenario 1:
FTRUMGlobalManager.getInstance().addLongTask(stack, durationNs);
// Scenario 2: With extended attributes.
const longTaskProperty: Record<string, string | number | boolean> = {
module: 'checkout',
operation: 'render_order_list',
threshold_ms: 200
};
FTRUMGlobalManager.getInstance().addLongTask(stack, durationNs, longTaskProperty);
Resource¶
Usage¶
/**
* Starts the Resource lifecycle.
*
* @param resourceId Unique resource identifier; must use the same value as `stopResource` and `addResource`.
* @param property Optional extended attributes.
*/
startResource(resourceId: string, property?: Record<string, object>): void
/**
* Ends the Resource lifecycle.
*
* @param resourceId Unique resource identifier; should use the same value as `startResource`.
* @param property Optional extended attributes.
*/
stopResource(resourceId: string, property?: Record<string, object>): void
/**
* Adds the request, response, and network performance data for a Resource.
*
* @param resourceId Unique resource identifier; should use the same value as `startResource` and `stopResource`.
* @param resourceParams Resource details such as URL, request method, response status, response length, and extended attributes.
* @param netStatusBean Network performance data such as DNS, TCP, TTFB, and response time.
*/
addResource(resourceId: string, resourceParams: ResourceParams, netStatusBean: NetStatusBean): void
Extended attributes passed to startResource(...) and stopResource(...) are merged with the attributes in ResourceParams in call order. Set the resource status code and response length through ResourceParams; they are no longer passed as parameters to stopResource(...).
Code Example¶
import {
FTRUMGlobalManager,
ResourceParams,
NetStatusBean
} from '@guancecloud/ft_sdk/Index';
const resourceId = 'https://api.example.com/data';
// Scenario 1:
// Request start
FTRUMGlobalManager.getInstance().startResource(resourceId);
// After the request completes, add request, response, and network performance data.
const resourceParams = new ResourceParams();
resourceParams.setUrl(resourceId);
resourceParams.setResourceStatus(200);
resourceParams.setResponseContentLength(1024);
resourceParams.resourceType = 'xhr';
const netStatusBean = new NetStatusBean();
netStatusBean.setResourceHostIP('192.168.1.1');
netStatusBean.setDNSTime(10000000);
netStatusBean.setTcpTime(20000000);
netStatusBean.setTTFB(50000000);
netStatusBean.setResponseTime(100000000);
FTRUMGlobalManager.getInstance().stopResource(resourceId);
FTRUMGlobalManager.getInstance().addResource(resourceId, resourceParams, netStatusBean);
// Scenario 2: With extended attributes. This is an independent request; when using it, replace the startResource and stopResource calls in Scenario 1.
const startResourceProperty: Record<string, object> = {
request_source: new String('checkout')
};
FTRUMGlobalManager.getInstance().startResource(resourceId, startResourceProperty);
const stopResourceProperty: Record<string, object> = {
response_cache: new Boolean(false)
};
FTRUMGlobalManager.getInstance().stopResource(resourceId, stopResourceProperty);
NetStatusBean Properties¶
NetStatusBean supplements network performance data for manual Resource collection. All time parameter units are nanoseconds; *StartTime represents the offset relative to the Resource start time. Unset time values default to -1 and are not written to the corresponding metrics.
| Method | Description |
|---|---|
setDNSTime |
DNS resolution time |
setDNSStartTime |
DNS resolution start offset |
setTcpTime |
TCP connection establishment time |
setConnectStartTime |
TCP connection establishment start offset |
setSSLTime |
SSL/TLS handshake time |
setSslStartTime |
SSL/TLS handshake start offset |
setTTFB |
Wait time before the first byte arrives (TTFB) |
setResponseTime |
Response transmission time |
setFirstByteTime |
First byte phase time |
setFirstByteStartTime |
First byte phase start offset |
setDownloadTime |
Response download time |
setDownloadTimeStart |
Response download start offset |
setHoleRequestTime |
Total request time (the API name retains the Hole spelling as defined by the SDK) |
setResourceHostIP |
Resource server IP address |
Automatic Resource Tracking¶
After enabling setEnableTraceUserResource(true), the SDK automatically tracks requests sent through RCP, Axios compatibility mode, or the @kit.NetworkKit HTTP interceptor.
When integrating @guancecloud/ft_sdk_ext into your app, it is recommended to import the public API from @guancecloud/ft_sdk_ext/Index to avoid deep paths such as src/main/....
RCP Automatic Tracking Integration¶
After enabling setEnableTraceUserResource in the RUM configuration, the SDK automatically collects Resource data for HTTP requests sent through RCP.
Starting from the current version, the SDK no longer automatically creates or holds a global RCP Session. Instead, it provides the following capabilities for your app to assemble:
RCPTraceInterceptor: automatically injects Trace HeadersRCPResourceInterceptor: automatically collectsResourcedata and performance metricscreateFTRCPInterceptors(): returns the default RCP interceptor list, making it easy to merge with a customSessionConfigurationcreateFTRCPTrackConfig(): quickly generates aSessionConfigurationwith default interceptors andTracingConfiguration
Recommended integration: Use the default SessionConfiguration factory function
import { rcp } from '@kit.RemoteCommunicationKit';
import { createFTRCPTrackConfig } from '@guancecloud/ft_sdk/Index';
const session = rcp.createSession(
createFTRCPTrackConfig({
baseAddress: 'https://api.example.com'
})
);
// GET request
const request = new rcp.Request('/data', 'GET');
const response = await session.fetch(request);
// POST request
const headers: rcp.RequestHeaders = { 'Content-Type': 'application/json' };
const postRequest = new rcp.Request('/data', 'POST', headers, { name: 'test' });
const postResponse = await session.fetch(postRequest);
If the project imports through the SDK root entry, you can also use:
Manually assembling interceptors
If you need full control over the Session configuration, you can also directly use the interceptors provided by the SDK:
import { rcp } from '@kit.RemoteCommunicationKit';
import { RCPTraceInterceptor, RCPResourceInterceptor } from '@guancecloud/ft_sdk/Index';
const session = rcp.createSession({
baseAddress: 'https://api.example.com',
interceptors: [
new RCPTraceInterceptor(),
new RCPResourceInterceptor()
],
requestConfiguration: {
tracing: {
collectTimeInfo: true
}
}
});
TracingConfiguration notes:
collectTimeInfo: true: recommended to enable. The SDK relies onresponse.timeInfoto calculate performance metrics such as DNS, TCP, SSL, TTFB, and download timeincomingHeader/outgoingHeader: optional, enabled by defaultincomingData/outgoingData: disabled by default to reduce additional overhead
HTTP Interceptor Integration¶
If your app makes requests using @kit.NetworkKit's http.createHttp(), you can use the HTTP interceptors provided by @guancecloud/ft_sdk_ext for automatic Trace Header injection and Resource collection. This integration requires ft_sdk_ext 0.1.14 or later and HarmonyOS API 22 or later.
First, ensure the project has installed:
ft_sdk.har, declared as@guancecloud/ft_sdkinoh-package.json5ft_sdk_ext.har, declared as@guancecloud/ft_sdk_extinoh-package.json5- If
ft_sdk_ext.haris installed via a local HAR, you also need to addoverrides["@guancecloud/ft_sdk"] = "file:./libs/ft_sdk.har"to theoh-package.json5in the project root directory to redirect its internal dependency to the local HAR
The SDK provides the following capabilities:
HttpInitialRequestInterceptor: injects Trace Headers at the start of the request and starts theResourceHttpFinalResponseInterceptor: addsResourcedata at the end of the response and ends collectioncreateFTHttpInterceptorChain(): creates a reusablehttp.HttpInterceptorChainapplyFTHttpTrack(): attaches the default interceptor chain directly to a singlehttp.HttpRequest
Two integration approaches are provided.
Approach 1: Use the default factory provided by the SDK
import { http } from '@kit.NetworkKit';
import { createFTHttpInterceptorChain } from '@guancecloud/ft_sdk_ext/Index';
const request = http.createHttp();
const interceptorChain = createFTHttpInterceptorChain();
interceptorChain.apply(request);
try {
const response = await request.request('https://httpbin.org/get', {
method: http.RequestMethod.GET,
header: {
'Accept': 'application/json'
}
});
} finally {
request.destroy();
}
If you want to append your own interceptors, you can also write:
import { http } from '@kit.NetworkKit';
import { createFTHttpInterceptorChain } from '@guancecloud/ft_sdk_ext/Index';
const request = http.createHttp();
const interceptorChain = createFTHttpInterceptorChain({
interceptors: [
new CustomAfterInterceptor()// Append custom interceptor
]
});
interceptorChain.apply(request);
The execution order is:
[
new HttpInitialRequestInterceptor(),
new HttpFinalResponseInterceptor(),
new CustomAfterInterceptor()
]
Approach 2: Manually assemble HttpInterceptorChain
If your app already has custom interceptors, or you need to freely decide the interceptor order, it is recommended to manually create the http.HttpInterceptorChain directly:
import { http } from '@kit.NetworkKit';
import {
HttpInitialRequestInterceptor,
HttpFinalResponseInterceptor
} from '@guancecloud/ft_sdk_ext/Index';
const request = http.createHttp();
const interceptorChain = new http.HttpInterceptorChain();
interceptorChain.addChain([
new CustomBeforeInterceptor(),
new HttpInitialRequestInterceptor(),
new HttpFinalResponseInterceptor()
]);
interceptorChain.apply(request);
Notes:
- HTTP interceptors rely on the interceptor capabilities provided by
@kit.NetworkKitin API 22+. For API levels below 22, use RCP or Axios compatibility mode instead - In HTTP interceptor mode using
http.createHttp()directly,HttpRequestContextcannot currently reliably obtain the actual request method, somethodinResourcemay be recorded asUNKNOWN - If your app uses the
interceptorChainmode of@ohos/axios, it is recommended to also attachapplyFTAxiosChainMethodBridge()to bridge axios's actual method, url, and headers - The
@kit.NetworkKitinterceptor callbacks do not yet expose RCPtimeInfo-level detailed timings, so onlyresourceLoadis added for now
Axios Integration¶
If your app uses @ohos/axios, you can integrate automatic tracking as follows:
@guancecloud/ft_sdk: compatibility mode based on Axiosrequest/response interceptors@guancecloud/ft_sdk_ext: versions0.1.14and later provide an enhanced mode based oninterceptorChain
@ohos/axios 2.2.4 and later¶
This integration is based on Axios's request/response interceptors.
import axios from '@ohos/axios';
import { applyFTAxiosTrack } from '@guancecloud/ft_sdk/Index';
const client = axios.create({
timeout: 10000
});
applyFTAxiosTrack(client);
This integration can coexist with your own interceptors:
import axios from '@ohos/axios';
import { applyFTAxiosTrack } from '@guancecloud/ft_sdk/Index';
const client = axios.create({
timeout: 10000
});
applyFTAxiosTrack(client);
client.interceptors.request.use((config) => {
config.headers = {
...(config.headers || {}),
Authorization: 'Bearer <token>',
'X-Signature': 'signed-value'
};
return config;
});
client.interceptors.response.use((response) => {
return response;
});
Execution order notes:
- In
@ohos/axioscompat mode,requestinterceptors behave as follows: last registered, first executed - This means multiple
request interceptorscan coexist, but the registration order affects whether FT sees the request headers before or after modification - If you want FT to collect the final request headers after your app adds authentication, signature, and other fields, the recommended order is: call
applyFTAxiosTrack(client)first, then register yourrequest interceptor - With the above order, your
request interceptorexecutes first, and FT executes afterward and reads the finalheaders - To adjust the order, simply change the registration order. For example, if you register your interceptor first and then call
applyFTAxiosTrack(client), FT executes first and your interceptor executes afterward
@ohos/axios 2.2.8 and later¶
For @ohos/axios 2.2.8 and later, it is recommended to integrate FT automatic tracking through the interceptorChain of @guancecloud/ft_sdk_ext:
import axios from '@ohos/axios';
import {
createFTHttpInterceptorChain,
applyFTAxiosChainMethodBridge
} from '@guancecloud/ft_sdk_ext/Index';
const client = axios.create({
timeout: 10000,
interceptorChain: createFTHttpInterceptorChain()
});
applyFTAxiosChainMethodBridge(client);
const response = await client.post('https://api.example.com/data', {
source: 'axios',
message: 'ft auto track'
});
For scenarios where multiple interceptors coexist, you need to manually adjust the execution order, or you need to assemble them together with your custom interceptors, refer to HTTP Interceptor Integration and combine HttpInitialRequestInterceptor and HttpFinalResponseInterceptor as needed.
To pass it per request, you can also write:
import axios from '@ohos/axios';
import { createFTHttpInterceptorChain } from '@guancecloud/ft_sdk_ext/Index';
const response = await axios.request({
url: 'https://httpbin.org/post',
method: 'post',
data: {
source: 'axios',
message: 'ft auto track'
},
responseType: 'string',
interceptorChain: createFTHttpInterceptorChain()
});
Notes:
- It is recommended to inject
interceptorChainuniformly when creating the Axios instance and callapplyFTAxiosChainMethodBridge(client)to avoid inaccurateResourcemethod records caused by a missing bridge - The
interceptorChainmode depends on@guancecloud/ft_sdk_ext(the local HAR file name remainsft_sdk_ext.har) and requires HarmonyOS API 22+ - To automatically inject Trace Headers, in addition to creating the interceptor chain, enable
setEnableAutoTrace(true)in the Trace configuration - To automatically collect
Resource, also enablesetEnableTraceUserResource(true)in the RUM configuration - If the caller already has custom HTTP/Axios interceptors, it is recommended to manually assemble the order using
HttpInitialRequestInterceptorandHttpFinalResponseInterceptorto avoid rewritingurl,method, orheadersafter FT automatic tracking - The SDK only provides interceptors and default configuration factory functions; the creation and lifecycle of the RCP Session are managed by your app itself
- If your app creates a Session directly with
rcp.createSession(), you need to add the SDK-provided interceptors yourself; otherwise, requests will not be automatically tracked - If your app directly uses
http.createHttp()or@ohos/axios, you need to explicitly attachapplyFTHttpTrack(),applyFTAxiosTrack(), orcreateFTHttpInterceptorChain(); the AxiosinterceptorChainmode also requires callingapplyFTAxiosChainMethodBridge(client)
Resource Performance Metrics¶
The HarmonyOS SDK obtains network request performance metrics through the TimeInfo interface of RCP (Remote Call Protocol), including DNS, TCP, SSL, TTFB (Time To First Byte), and more.
TTFB calculation notes:
- HarmonyOS TTFB: calculated using
startTransferTimeMs - preTransferTimeMs; it includes server processing time, network transmission time, and response header reception time -
Android TTFB: represents only response header reception time and is usually very short
-
DNS time:
nameLookupTimeMs - TCP time:
connectTimeMs - nameLookupTimeMs - SSL time:
tlsHandshakeTimeMs - connectTimeMs - TTFB:
startTransferTimeMs - preTransferTimeMs - Download time:
totalTimeMs - startTransferTimeMs
Due to limitations of the HarmonyOS RCP API, preTransferTimeMs is almost equal to the SSL completion time. As a result, HarmonyOS TTFB includes server processing time, making its value typically larger than Android's. This is an expected platform behavior difference, not an SDK implementation issue.