Troubleshooting¶
This article provides basic troubleshooting entry points for HarmonyOS SDK initialization and reporting issues.
Initialization and Log Diagnostics¶
Initialization Failure¶
If SDK initialization fails, we recommend checking the following first:
- Whether
datakitUrl,datawayUrl, andclientTokenare correctly configured according to your deployment method - Whether
ft_sdk.harandft_native.harare placed in thelibsdirectory and declared inoh-package.json5as@guancecloud/ft_sdkand@guancecloud/ft_native, then runohpm install - Whether the app has completed the
oh-package.json5dependency declarations as documented - Whether SDK initialization occurs during the app startup phase
Checking SDK Initialization Exceptions¶
Check hilog for logs whose Tag has the [FT-SDK] prefix. Internal logs such as SDK initialization, configuration installation, and data synchronization are output with this prefix, which can be used to locate issues such as initialization failures, configurations not taking effect, or network synchronization exceptions.
Enabling Debug Mode¶
You can enable SDK Debug mode with the following configuration. setDebug(true) is the master switch for SDK internal logs. After enabling it, the console hilog outputs SDK debug logs. You can filter by the [FT-SDK] characters to locate SDK internal logs. setSdkLogLevel(...) controls the output threshold:
| Log Level | Output |
|---|---|
SDKLogLevel.V, SDKLogLevel.D |
Outputs all current SDK diagnostic logs: D, I, W, E |
SDKLogLevel.I |
Outputs I, W, E |
SDKLogLevel.W |
Outputs W, E |
SDKLogLevel.E |
Outputs only E |
import { FTSDK, FTSDKConfig, SDKLogLevel } from '@guancecloud/ft_sdk/Index';
const sdkConfig = FTSDKConfig.builder(datawayUrl, clientToken)
.setDebug(true)
.setSdkLogLevel(SDKLogLevel.D);
FTSDK.install(sdkConfig, this.context);
We recommend disabling this configuration when releasing a Release build.
Writing SDK Internal Logs to Local Files¶
To troubleshoot production or intermittent issues, you can write SDK internal diagnostic logs to local files in the app sandbox for later export and analysis. You must enable setDebug(true) at the same time. You can use setSdkLogLevel(...) to control the log level to record.
import { FTSDK, FTSDKConfig, SDKLogLevel } from '@guancecloud/ft_sdk/Index';
const sdkConfig = FTSDKConfig.builder(datawayUrl, clientToken)
.setDebug(true)
.setSdkLogLevel(SDKLogLevel.D)
.setEnableInnerLogFile(true, {
singleFileMaxSize: 5 * 1024 * 1024,
totalFileMaxSize: 50 * 1024 * 1024,
flushBatchSize: 20,
flushIntervalMs: 200
});
FTSDK.install(sdkConfig, this.context);
FTInnerLogFileConfig¶
setEnableInnerLogFile(true, config) accepts an FTInnerLogFileConfig to adjust the internal log file writing policy:
| Field | Type | Required | Description |
|---|---|---|---|
singleFileMaxSize |
number |
No | Size of a single log file. Default 5MB, range 1MB ~ 10MB |
totalFileMaxSize |
number |
No | Total size threshold of log files. Default 50MB, range 10MB ~ 100MB. When the threshold is exceeded, cleanup starts from the earliest historical rotated files, and the current file is retained |
flushBatchSize |
number |
No | Number of entries written per batch. Default 20, range 1 ~ 100 |
flushIntervalMs |
number |
No | Flush interval. Default 200ms, range 50ms ~ 5000ms |
Log files are written by default to the filesDir/ft_sdk_logs/ directory in the app sandbox:
- Current log file:
ft_inner_current.log - Historical rotated files:
ft_inner_*.log
When the total log size exceeds the configured threshold, the SDK cleans up starting from the earliest historical rotated files, and the current log file is retained. Internal log files record only the SDK's own diagnostic logs and do not include business Logs written by FTLogger.
To ensure the completeness of internal logs, set this configuration before
FTSDK.install(...)and enablesetDebug(true)at the same time. Values outside the configured range are truncated to the allowed range and rounded by the SDK.
Data Reporting and Cache¶
No Data Reported¶
We recommend troubleshooting in the following order:
- Confirm the prerequisites are completed, especially the DataKit and RUM collector configurations
- Confirm the app device can access
datakitUrlordatawayUrl - If
setProxy(...),setProxyAuthenticator(...), orsetDns(...)is configured, confirm the proxy, authentication information, DNS server, or DoH address is correct. These configurations only affect SDK data upload requests - Refer to Enabling Debug Mode to check the initialization and reporting logs
- Confirm that RUM has executed
installRUMConfigand at least one collection item to verify is enabled - The SDK enables
deflatecompression for uploaded data by default. If you suspect server-side or network path incompatibility, you can temporarily setsetCompressIntakeRequests(false)for comparison
Cache and Synchronization¶
- The SDK auto-sync uses a 10-second aggregation window. It is normal for uploads not to be initiated immediately after collection
- If auto-sync is disabled via
FTSDKConfig.setAutoSync(false)orFTSDK.setAutoSync(false), you need to manually callFTSDK.flushSyncData()as described in SDK Initialization - After SDK initialization, you can re-enable auto-sync with
FTSDK.setAutoSync(true) FTSDK.flushSyncData()does not wait for the 10-second aggregation window. It schedules the upload immediately after flushing the pending RUM and Log worker queues as much as possible- If the local cache is abnormal, use
FTSDK.clearAllData()to clear unreported data and then verify again - When using FileStore, first confirm whether shadow mode is active. In shadow mode, SQLite still handles reading and uploading, while writes are mirrored to FileStore for pre-migration validation. See SDK Initialization for detailed configuration
- Migrating old SQLite caches for the first time requires explicitly calling
setNeedTransformOldCache(true). If capacity is insufficient or the old cache is corrupted, the source cache is retained. After fixing the conditions, restart to continue processing
RUM Automatic Collection¶
UI Block Not Collected¶
Confirm that setEnableTrackAppUIBlock(true, blockDurationMs) is enabled in the RUM configuration. HarmonyOS UI block collection relies only on the system MAIN_THREAD_JANK event. The SDK calculates the duration using the event's begin_time and end_time, and reports only foreground blocks that exceed the blockDurationMs threshold.
System events have a startup grace period, consecutive timeout requirements, and process-level reporting restrictions. Therefore, a single blocking test cannot be the sole basis for determining whether collection is effective. When troubleshooting, enable SDK Debug logs and filter hilog for [FT-UI-BLOCK] to confirm whether the system event listener is registered and whether the block has been reported.
Automatic Network Request Collection¶
HttpInterceptorChain Not Taking Effect¶
If automatic collection using HttpInterceptorChain from @kit.NetworkKit does not take effect, we recommend checking the following first:
- Whether the current device or compilation target is HarmonyOS API 22 or higher. This capability is not supported below API 22
- Whether the project has installed
ft_sdk.harandft_sdk_ext.har, declared them inoh-package.json5as@guancecloud/ft_sdkand@guancecloud/ft_sdk_ext, and completedohpm install - Whether
setEnableTraceUserResource(true)is enabled. To automatically inject Trace Headers, you also need to enablesetEnableAutoTrace(true)in the Trace configuration - It is known that in concurrent request scenarios of
@kit.NetworkKit, even when creating independentHttpRequestandHttpInterceptorChaininstances for each request, the following exception may still be triggered:{"code":2300003,"message":"Invalid URL format or missing URL"} - If you encounter the above error, we recommend falling back to serial verification first. In concurrent scenarios, you can switch to RCP or Axios compatibility mode, or temporarily avoid using
HttpInterceptorChainin high-concurrency paths
Resource Not Collected¶
If HTTP requests are created and automatic collection interceptors are attached, but SDK initialization and RUM configuration are executed afterward, requests may succeed while Resource data is not generated.
We recommend checking the following first:
- Whether
HttpRequestis created andcreateFTHttpInterceptorChain()orapplyFTHttpTrack()is called beforeFTSDK.installRUMConfig()is executed - Whether
setEnableTraceUserResource(true)is enabled in the RUM configuration
Cause:
- When
HttpInterceptorChainis created, the current RUM configuration is read immediately to determine whether to enable automatic Resource collection - If this step occurs before
FTSDK.installRUMConfig(), the SDK reads the default valuefalse - Even if SDK initialization is completed afterward, the already-created automatic collection interceptor instances will not automatically refresh to the enabled state, so
Resourcedata will not be generated
Recommended approach:
- Complete
FTSDK.install()andFTSDK.installRUMConfig()first, then createHttpRequestand attachHttpInterceptorChain - If the request object or interceptor chain was created in advance, recreate and re-attach it after SDK initialization is completed
- If you really need to create automatic collection objects before SDK initialization, explicitly pass the switches when creating them to avoid relying on default configuration values
Optional code example:
applyFTAxiosTrack(client, {
enableTraceInterceptor: true,
enableResourceInterceptor: true
});
sdk.init();
Notes:
- Explicitly passing
enableTraceInterceptorandenableResourceInterceptoronly ensures that the automatic collection mechanism itself is enabled - Requests already sent before SDK initialization is completed may still fail to generate or fill in
Resourcedata because the RUM context has not been fully initialized - Therefore, the recommended approach is still to complete SDK initialization first, and then create and use automatic collection objects
The same approach also applies to RCP and HttpInterceptorChain:
- Axios:
applyFTAxiosTrack(client, { enableTraceInterceptor: true, enableResourceInterceptor: true }) - RCP:
createFTRCPInterceptors(true, true)orcreateFTRCPTrackConfig({ enableTraceInterceptor: true, enableResourceInterceptor: true }) - HTTP:
createFTHttpInterceptorChain({ enableTraceInterceptor: true, enableResourceInterceptor: true })orapplyFTHttpTrack(request, { enableTraceInterceptor: true, enableResourceInterceptor: true })
Related Documentation¶
- Installation and entry page: See App Access
- Initialization parameters: See SDK Initialization
- RUM network collection: See RUM Configuration
- Distributed Tracing: See Trace Configuration