HarmonyOS Application Integration¶
Collect metrics data from HarmonyOS applications and analyze application performance visually.
Reading Path¶
- First-time integration: Start with Quick Start
- Full integration: Continue reading this article
- Old package name migration: See Old Configuration Migration
- HAR package download: See HAR Acquisition Methods
- Initialization parameters: See SDK Initialization, RUM Configuration, Log Configuration, Trace Configuration
- Custom tags: See Custom Tags and Global Context
- Advanced scenarios: See WebView Data Monitoring
- Data model: See Application Data Collection
- Troubleshooting: See Troubleshooting
Prerequisites¶
Note
If you have already activated the RUM Headless service, the prerequisites are automatically configured, and you can directly integrate the application.
- Install DataKit
- Configure the RUM Collector
- Configure DataKit to be accessible via the public network and install the IP geolocation database
Application Integration¶
- Go to RUM > Create > HarmonyOS
- Enter the application name and application ID
- Select the application integration method:
- Public network DataWay: Directly receives RUM data without installing the DataKit collector
- Local environment deployment: Receives RUM data after meeting the prerequisites
Installation¶
Choose any of the following installation methods based on the project integration method.
Method 1: Install via ohpm¶
If the third-party repository is already configured, you can install directly via ohpm:
ohpm install @guancecloud/ft_sdk
ohpm install @guancecloud/ft_sdk_ext #Optional
ohpm install @guancecloud/ft_native #Optional
Method 2: Install via local HAR¶
According to the HarmonyOS official documentation (HAR Package Import Guide), first refer to HAR Acquisition Methods to prepare the installation package, then place the HAR file in the project's libs directory, and add scoped dependencies as needed in oh-package.json5.
{
"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
}
}
If using HAR package dependencies, it is recommended to also add overrides in the project root directory's oh-package.json5 to rewrite the internal remote dependencies of the module to the local HAR, preventing ft_sdk_ext from continuing to resolve @guancecloud/ft_sdk from the remote repository:
Then execute:
After installation, the HAR package will be installed in the project's oh_modules/ directory. When using scoped dependencies, the directory typically appears as oh_modules/@guancecloud/ft_sdk, oh_modules/@guancecloud/ft_sdk_ext, oh_modules/@guancecloud/ft_native.
HAR Acquisition Methods¶
New HAR Acquisition Method¶
- First, go to the corresponding ohpm page
- Then, find the
dist.tarballfor the target version - Download from
dist.tarballand extract the corresponding HAR package
Corresponding addresses:
@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
Please note:
- When downloading using the new method, select the
dist.tarballconsistent with the project integration version ft_sdk_extandft_sdkare recommended to maintain the same version- The downloaded HAR file can still be placed in the project's
libs/directory and integrated via the local HAR method
Old HAR Download Method¶
- Download the old
ft_sdk.harfile: Download Link - Download the
ft_sdk_ext.harfile as needed: Download Link - Download the
ft_native.harfile as needed: Download Link
Package Description¶
Please introduce related packages as needed based on actual capabilities:
ft_sdk.haris the core package and must be installed; when installed via a third-party repository, the corresponding package name is@guancecloud/ft_sdkft_sdk_ext.haris an extension package, installed only when automatic collection capability based on@kit.NetworkKit'sHttpInterceptorChainis needed.HttpInterceptorrelated capabilities are supported from0.1.14-alpha03onwards and depend on HarmonyOS API 22 or higher; when installed via a third-party repository, the corresponding package name is@guancecloud/ft_sdk_extft_native.haris an optional package, installed only when native capabilities such as Native Crash are needed; when installed via a third-party repository, the corresponding package name is@guancecloud/ft_native- Only place the HAR files actually used into the
libs/directory; if the directory does not exist, create it first. If the HAR file is currently in the project root directory, move it to thelibs/directory first
Import Methods¶
You can import in the following ways:
If you need to use HTTP automatic collection capability based on HttpInterceptorChain, import from @guancecloud/ft_sdk_ext:
Explanation:
@guancecloud/ft_sdk: Default integration and Axios-compatible mode import entry@guancecloud/ft_sdk_ext:HttpInterceptorChainautomatic collection related import entry- Axios-compatible paths such as
applyFTAxiosTrackare still exported from@guancecloud/ft_sdk
Permission Description¶
The SDK already automatically includes the following permission declarations, no need for manual additional configuration:
| Permission Name | Purpose Description |
|---|---|
ohos.permission.INTERNET |
Network access permission, used for data reporting and network request tracking |
ohos.permission.GET_WIFI_INFO |
Get WiFi information, used for network type detection and signal strength collection |
ohos.permission.GET_NETWORK_INFO |
Get network information, used for network status monitoring and type identification |
Detailed Configuration Entries¶
Advanced Scenarios¶
Old Configuration Migration¶
This article explains how to migrate HarmonyOS SDK from old package names and deep path imports to the current scoped package names and public Index entry. It applies to the following three types of projects:
- Already integrated via local HAR method and have used
ft_sdk.har,ft_sdk_ext.har,ft_native.har - Already installed via
ohpm, but still using old unscoped package name configurations or deep path imports - Already migrated to
@guancecloud/scoped package names, but the code still imports from@guancecloud/ft_sdk/src/main/...or@guancecloud/ft_sdk_ext/src/main/...deep paths
Migration Content 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
Please note:
- The HAR file names themselves can continue to be used as
ft_sdk.har,ft_sdk_ext.har,ft_native.har - What needs adjustment are the dependency names in
oh-package.json5and the import paths in the code; it is recommended to uniformly use the SDK's publicIndexentry - Whether installed via local HAR or via
ohpm, dependency names should be uniformly migrated to scoped package names, and code imports should be uniformly migrated to the publicIndexentry @guancecloud/.../src/main/...belongs to the scoped deep path writing method of previous versions and can continue to be used as a migration reference, but is not the latest recommended integration method- If you need to reacquire local HAR packages, refer to HAR Acquisition Methods
Configuration File Changes¶
Old writing:
//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"
}
}
New writing:
//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 installed via ohpm, the dependency name also needs to be changed to the scoped package name, for example:
ohpm install @guancecloud/ft_sdk
ohpm install @guancecloud/ft_sdk_ext
ohpm install @guancecloud/ft_native
Comparison explanation:
- The new writing changes the dependency names from the old
ft_sdk,ft_sdk_ext,ft_nativeto scoped package names - If installed via
ohpm, the new scoped package name should also be used for the installation command overridesneeds to be configured in the project root directory'soh-package.json5- When the project integrates
ft_sdk_ext.harvia the local HAR method,overrides["@guancecloud/ft_sdk"]is used to rewrite its internal remote dependency to the localft_sdk.har - If only using
ft_sdk.harorft_native.har, you can keep the correspondingdependenciesas needed
Code Import Changes¶
Old writing:
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';
Previous scoped deep path writing:
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 writing:
import { FTSDK, FTSDKConfig } from '@guancecloud/ft_sdk/Index';
import { createFTHttpInterceptorChain } from '@guancecloud/ft_sdk_ext/Index';
Migration Steps¶
- Place the HAR file in the project's
libs/directory - Change the dependency names in the project from the old package names to the new scoped package names
- If the project uses
ft_sdk_ext.harvia the local HAR method, addoverridesin the project root directory'soh-package.json5 - If the project is installed via
ohpm, re-execute the installation command using the new scoped package name; if the project is installed via local HAR, executeohpm install - Replace the old import paths or previous
@guancecloud/.../src/main/...scoped deep paths in the code with the publicIndexentry
Common Questions¶
How to Avoid Conflict Fields When Adding Global Variables¶
To avoid conflicts between custom fields and SDK data, it is recommended to add a business prefix to tag names, for example, df_tag_name. When there are fields with the same name in SDK global variables and RUM, Log, the fields in RUM, Log will override the SDK global variables.
For the usage of custom tags, continue reading Custom Tags and Global Context.