HarmonyOS App Integration¶
Collect metrics data from HarmonyOS apps to analyze app performance visually.
Reading Path¶
- First-time integration: start with Choose an Integration Method; for manual integration, see Quick Start
- Full integration: continue reading this document
- Legacy package name migration: see Legacy Configuration Migration
- HAR package download: see How to Obtain HAR
- Initialization parameters: see SDK Initialization, RUM Configuration, Log Configuration, Trace Configuration
- Advanced capabilities: see the dedicated pages under the Advanced Scenarios group
- Session Replay: see HarmonyOS Session Replay (Experimental)
- Data model: see App Data Collection
- Issue diagnosis: see Troubleshooting
Prerequisites¶
Note
If you have already enabled the RUM Headless service, the prerequisites are configured automatically, and you can integrate your app directly.
When deploying in a local environment, complete the following data receiver configuration. When using the public DataWay, you do not need to deploy DataKit yourself.
- Install DataKit
- Configure the RUM Collector
- Configure DataKit to be publicly accessible and install the IP geolocation database
App Integration¶
- Go to RUM > Create App > HarmonyOS
- Enter the app name and app ID
- In "Choose Integration Method", select Agent Auto-Integration or Manual Integration, then complete "Integration Configuration".
Choose an Integration Method¶
On the app configuration page, choose "Agent Auto-Integration" or "Manual Integration", then complete "Integration Configuration". For an existing app, go directly to the configuration page to continue the integration.
| Integration Method | Use Cases | Entry Point |
|---|---|---|
| Agent Auto-Integration | Want a coding assistant to analyze the project and complete the SDK integration | Copy the prompt generated in the console and hand it to the coding assistant in the app code repository |
| Manual Integration | Want to install the SDK and configure parameters yourself | Confirm the data reporting method, then complete the configuration as described in this document and Quick Start |
Agent Auto-Integration¶
- On the configuration page of the current app, choose "Agent Auto-Integration".
- Copy the complete prompt from "Integration Configuration", and make sure it uses the integration information of the current app.
- Open the coding assistant in the app code repository, paste the prompt, and let the Agent analyze the project according to the integration guide and complete the SDK configuration.
- Build and run the app, trigger operations such as page views, and confirm that data is received in the Explorer of the current app.
If the page indicates that your personal API Key or temporary authorization code is not ready, complete it as prompted and copy the prompt again.
Manual Integration¶
On the app configuration page, choose "Manual Integration" and confirm the data reporting method:
- Public DataWay: receives RUM data directly; no need to install the DataKit collector
- Local environment deployment: receives RUM data after the prerequisites are met
Follow Installation and Quick Start below to install, initialize, and verify the SDK. If an SDK configuration already exists, check and reuse it first to avoid duplicate initialization.
Installation¶
Add the Hvigor Plugin Configuration¶
Automatic collection of console.* and hilog.* and automatic cold start collection rely on @cloudcare/hvigor-ohos-plugin. This plugin is a build-time toolkit and is not a runtime dependency of the app module's oh-package.json5.
Note: Cold start measurement ends when the first UI frame is rendered.
@cloudcare/hvigor-ohos-plugin0.1.1 requiresft_sdk0.1.17 or later; HarmonyOS API 22 and later collects the real first frame. Below API 22, a completelaunch_coldAction and the total cold start duration cannot be generated.
Add the plugin dependency in the project-level hvigor/hvigor-config.json5:
Then register the plugin in the hvigorfile.ts of the app's HAP module:
import { hapTasks } from '@ohos/hvigor-ohos-plugin';
import { ftConsoleLogPlugin } from '@cloudcare/hvigor-ohos-plugin';
export default {
system: hapTasks,
plugins: [ftConsoleLogPlugin()]
};
The plugin only transforms calls in the app's src/main/ets; it does not rewrite the source code on disk or the SDK dependencies. The generated cold start code references ft_sdk, so the app still needs to keep the ft_sdk runtime dependency. After completing the configuration, perform a clean build. If the plugin is not installed, console, hilog, and cold start data are not collected automatically.
Automatic collection in ft_sdk 0.1.18 and later requires the Hvigor plugin. Each source module that needs instrumentation (HAP, HAR, or HSP) must declare ft_sdk in the dependencies of its own oh-package.json5; Replay automatic collection also requires declaring ft_session_replay. Declaring it only in the project root, in another module, or in devDependencies does not enable automatic collection for that module. For details, see Session Replay Integration.
For cold start, install RUM as early as possible at the entry point and enable setEnableTraceUserAction(true). It is recommended to configure AbilityStage as srcEntry in the HAP's module.json5 to obtain the complete app initialization phase; without this configuration, the new plugin can only provide approximate phase timings.
Note: Use the callback form
windowStage.loadContent('pages/Index', (err) => { ... }). The plugin attempts to register the first-frame listener at the beginning ofonWindowStageCreate()and makes an additional attempt in the page load success callback. Without the callback, it only attempts registration once at the beginning ofonWindowStageCreate().
In 0.1.18, each process reports launch_cold at most once, after the first UI frame of that process is rendered. The duration is measured from process start to the first frame and includes background waiting time before the first frame; switching between foreground and background does not reset the recorded phase boundaries. Processes that never render a first UI frame do not generate a cold start Action. Launch Actions are still subject to Session sampling and Action filtering.
Add the SDK¶
Depending on how your project integrates, choose either of the following installation options.
Option 1: Install via ohpm¶
If the third-party repository has already been configured, you can install directly with ohpm:
ohpm install @guancecloud/ft_sdk
ohpm install @guancecloud/ft_sdk_ext # Optional
ohpm install @guancecloud/ft_native # Optional
ohpm install @guancecloud/ft_session_replay # Optional, Session Replay (Experimental)
Option 2: Install via a local HAR¶
According to the official HarmonyOS documentation (HAR Package Import Guide), first prepare the installation packages as described in How to Obtain HAR, then place the HAR files in the project's libs directory and add scoped dependencies in oh-package.json5 as needed.
{
"dependencies": {
"@guancecloud/ft_sdk": "file:../libs/ft_sdk.har",
"@guancecloud/ft_sdk_ext": "file:../libs/ft_sdk_ext.har", // Optional
"@guancecloud/ft_native": "file:../libs/ft_native.har", // Optional
"@guancecloud/ft_session_replay": "file:../libs/ft_session_replay.har" // Optional, Session Replay (Experimental)
}
}
If you use HAR package dependencies, it is recommended to also add overrides in the oh-package.json5 at the project root to redirect the module's internal remote dependency to the local HAR, so that ft_sdk_ext does not continue resolving @guancecloud/ft_sdk from the remote repository:
Then run:
After installation, the HAR packages are installed in the project's oh_modules/ directory. When using scoped dependencies, the directories usually appear as oh_modules/@guancecloud/ft_sdk, oh_modules/@guancecloud/ft_sdk_ext, oh_modules/@guancecloud/ft_native, oh_modules/@guancecloud/ft_session_replay.
Bytecode HAR Build Configuration¶
The ft_sdk 0.1.15, ft_sdk_ext 0.1.15, and ft_native 0.1.1 release packages use bytecode HAR. When integrating any of these packages, make sure that:
- The project uses HarmonyOS API 12 or later; the
HttpInterceptorChaincapability offt_sdk_extrequires HarmonyOS API 22 or later. - In the
build-profile.json5at the project root, enable normalized OHMUrl for the products actually built. If a configuration with the same name already exists, just merge thestrictModecontent:
{
"app": {
"products": [
{
"name": "default",
"buildOption": {
"strictMode": {
"useNormalizedOHMUrl": true
}
}
}
]
}
}
- The dependency names in
oh-package.json5should match the SDK package names; import APIs only from each package's publicIndexentry, and avoid internal paths such assrc/main/.... - The Release packages have ArkGuard obfuscation enabled and preserve public APIs through the consumer obfuscation rules shipped with the HAR. Do not delete or replace
consumer-rules.txtin the SDK package; when obfuscation is enabled for the app itself, the SDK's public capabilities can still be called normally.
How to Obtain HAR¶
Obtaining New HAR Packages¶
- First open the corresponding ohpm page
- Then locate the
dist.tarballof the target version - Download and extract the corresponding HAR package from
dist.tarball
Corresponding URLs:
@guancecloud/ft_sdk: https://repo.harmonyos.com/ohpm/@guancecloud/ft_sdk@guancecloud/ft_sdk_ext: https://repo.harmonyos.com/ohpm/@guancecloud/ft_sdk_ext@guancecloud/ft_native: https://repo.harmonyos.com/ohpm/@guancecloud/ft_native
Note:
- When downloading with the new method, choose the
dist.tarballthat matches the version integrated in your project - Keep
ft_sdk_extandft_sdkat the same version - The downloaded HAR files can still be placed in the project's
libs/directory and integrated as local HAR packages
Obtaining Legacy HAR Packages¶
- Download the legacy
ft_sdk.harfile: Download URL - Optionally download the
ft_sdk_ext.harfile: Download URL - Optionally download the
ft_native.harfile: Download URL
Package Description¶
Import the packages you need for the capabilities you use:
ft_sdk.haris the core package and must be installed; when installing from the third-party repository, the corresponding package name is@guancecloud/ft_sdkft_sdk_ext.haris an extension package. Install it when you need theHttpInterceptorChainautomatic collection capability based on@kit.NetworkKit. This capability requires HarmonyOS API 22 or later; when installing from the third-party repository, the corresponding package name is@guancecloud/ft_sdk_extft_native.haris an optional package; install it only when you need native capabilities such as Native Crash; when installing from the third-party repository, the corresponding package name is@guancecloud/ft_nativeft_session_replay.haris an optional Session Replay package that depends on the core SDK; for version requirements, installation, and initialization, see HarmonyOS Session Replay (Experimental)- Place only the HAR files you actually use in the
libs/directory; if the directory does not exist, create it first; if the HAR files are currently in the project root, move them to thelibs/directory first
Import Methods¶
You can import as follows:
To use the HTTP automatic collection capability based on HttpInterceptorChain, import from @guancecloud/ft_sdk_ext:
Notes:
@guancecloud/ft_sdk: the import entry for the default integration and Axios-compatible mode@guancecloud/ft_sdk_ext: the import entry forHttpInterceptorChainautomatic collection (requires HarmonyOS API 22 or later)- Axios-compatible paths such as
applyFTAxiosTrackare still exported from@guancecloud/ft_sdk
Permissions¶
The SDK already includes the following permission declarations automatically; no additional manual configuration is required:
| Permission | Purpose |
|---|---|
ohos.permission.INTERNET |
Network access permission, used for data reporting and network request tracing |
ohos.permission.GET_WIFI_INFO |
Retrieves Wi-Fi information, used for network type detection and signal strength collection |
ohos.permission.GET_NETWORK_INFO |
Retrieves network information, used for network status monitoring and type identification |
Detailed Configuration Entries¶
Advanced Scenarios¶
- Custom Tags and Global Context
- Custom Rules for Data Collection
- Data Masking
- Dynamic Configuration and Dynamic Update URL
- WebView Monitoring
- HarmonyOS Session Replay (Experimental)
Legacy Configuration Migration¶
This document describes how to migrate the HarmonyOS SDK from legacy package names and deep-path imports to the current scoped package names and public Index entries. It applies to the following three types of projects:
- Projects integrated via local HAR that have used
ft_sdk.har,ft_sdk_ext.har, andft_native.har - Projects installed via
ohpmthat still use legacy unscoped package name configurations or deep-path imports - Projects already migrated to the
@guancecloud/scoped package names but whose code still imports from deep paths such as@guancecloud/ft_sdk/src/main/...or@guancecloud/ft_sdk_ext/src/main/...
Migration Overview¶
ft_sdk->@guancecloud/ft_sdkft_sdk_ext->@guancecloud/ft_sdk_extft_native->@guancecloud/ft_native@guancecloud/ft_sdk/src/main/...->@guancecloud/ft_sdk/Index@guancecloud/ft_sdk_ext/src/main/...->@guancecloud/ft_sdk_ext/Index
Note:
- HAR file names can remain
ft_sdk.har,ft_sdk_ext.har, andft_native.har - What needs to change are the dependency names in
oh-package.json5and the import paths in the code; it is recommended to use the SDK's publicIndexentries consistently - Whether installed via local HAR or via
ohpm, dependency names should be migrated to scoped package names, and code imports should be migrated to the publicIndexentries @guancecloud/.../src/main/...is the scoped deep-path form used by previous versions; it can still serve as a migration reference but is not the latest recommended integration method- To re-obtain local HAR packages, see How to Obtain HAR
Configuration File Changes¶
Legacy form:
//root/entry/oh-package.json5
{
"dependencies": {
"ft_sdk": "file:../libs/ft_sdk.har",
"ft_sdk_ext": "file:../libs/ft_sdk_ext.har",
"ft_native": "file:../libs/ft_native.har"
}
}
Previous scoped deep-path form:
//root/entry/oh-package.json5
{
"dependencies": {
"@guancecloud/ft_sdk": "file:../libs/ft_sdk.har",
"@guancecloud/ft_sdk_ext": "file:../libs/ft_sdk_ext.har",
"@guancecloud/ft_native": "file:../libs/ft_native.har"
}
}
//root/oh-package.json5
{
"overrides": {
"@guancecloud/ft_sdk": "file:./libs/ft_sdk.har"
}
}
If you installed via ohpm, the dependency names also need to change to scoped package names, for example:
ohpm install @guancecloud/ft_sdk
ohpm install @guancecloud/ft_sdk_ext
ohpm install @guancecloud/ft_native
Comparison notes:
- The new form changes the dependency names from the legacy
ft_sdk,ft_sdk_ext, andft_nativeto scoped package names - If installing via
ohpm, run the install commands with the new scoped package names as well overridesmust be configured in theoh-package.json5at the project root- When the project integrates
ft_sdk_ext.haras a local HAR,overrides["@guancecloud/ft_sdk"]redirects its internal remote dependency to the localft_sdk.har - If you only use
ft_sdk.harorft_native.har, keep the correspondingdependenciesas needed
Code Import Changes¶
Legacy form:
import { FTSDK } from 'ft_sdk/src/main/ets/components/FTSDK';
import { FTSDKConfig } from 'ft_sdk/src/main/ets/components/Configs';
import { createFTHttpInterceptorChain } from 'ft_sdk_ext/src/main/ets/components/network/FTHttpAutoTrackExt';
New form:
import { FTSDK } from '@guancecloud/ft_sdk/src/main/ets/components/FTSDK';
import { FTSDKConfig } from '@guancecloud/ft_sdk/src/main/ets/components/Configs';
import { createFTHttpInterceptorChain } from '@guancecloud/ft_sdk_ext/src/main/ets/components/network/FTHttpAutoTrackExt';
New form:
import { FTSDK, FTSDKConfig } from '@guancecloud/ft_sdk/Index';
import { createFTHttpInterceptorChain } from '@guancecloud/ft_sdk_ext/Index';
Migration Steps¶
- Place the HAR files in the project's
libs/directory - Change the dependency names in the project from the legacy package names to the new scoped package names
- If the project uses
ft_sdk_ext.haras a local HAR, addoverridesin theoh-package.json5at the project root - If the project installs via
ohpm, rerun the install commands with the new scoped package names; if the project installs via local HAR, runohpm install - Replace legacy import paths or the previous
@guancecloud/.../src/main/...scoped deep paths in the code with the publicIndexentries
FAQ¶
How to Avoid Conflicting Fields When Adding Global Variables¶
To avoid conflicts between custom fields and SDK data, add a business prefix to tag names, for example df_tag_name. When a field with the same name exists in both the SDK global variables and RUM or Log data, the field in RUM or Log overrides the SDK global variable.
For how to use custom tags, see Custom Tags and Global Context.