Troubleshooting¶
This document provides a starting point for basic troubleshooting when HarmonyOS SDK initialization or reporting is abnormal.
Initialization and Log Diagnostics¶
Initialization Failure¶
If SDK initialization fails, check the following first:
- Whether
datakitUrl,datawayUrl, andclientTokenare correctly configured according to the deployment method. - Whether
ft_sdk.harandft_native.harhave been correctly placed in thelibsdirectory and declared inoh-package.json5as@guancecloud/ft_sdkand@guancecloud/ft_native, respectively, and then runohpm install. - Whether the app has completed the dependency declaration in
oh-package.json5according to the documentation. - Whether SDK initialization occurs during the app startup phase.
SDK Initialization Exception Verification¶
Check hilog to confirm whether there are logs whose Tag has the [FT-SDK] prefix. Internal SDK logs such as initialization, configuration installation, and data synchronization are output with this prefix, and can be used to locate issues such as initialization failure, configuration not taking effect, or network synchronization anomalies.
Enable Debug Mode¶
You can enable SDK Debug mode with the following configuration. setDebug(true) is the master switch for SDK internal logs. After it is enabled, hilog outputs SDK debug logs to the console. You can filter on [FT-SDK] to locate SDK internal logs. setSdkLogLevel(...) controls the output threshold:
| Log level | Output |
|---|---|
SDKLogLevel.V, SDKLogLevel.D |
Output all current SDK diagnostic logs: D, I, W, E |
SDKLogLevel.I |
Output I, W, E |
SDKLogLevel.W |
Output W, E |
SDKLogLevel.E |
Output 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);
It is recommended to disable this configuration when releasing a Release version.
Print Custom Logs to HiLog¶
To also view the content of FTLogger.logBackground(...) during debugging, enable setPrintCustomLogToConsole(true). This feature does not require the Hvigor plugin and is independent of automatic collection by setEnableConsoleLog(...).
import {
FTSDK, FTSDKConfig, FTLoggerConfig, FTLogger, SDKLogLevel, Status
} from '@guancecloud/ft_sdk/Index';
const sdkConfig = FTSDKConfig.builder('YOUR_DATAKIT_URL')
.setDebug(true)
.setSdkLogLevel(SDKLogLevel.D);
FTSDK.install(sdkConfig, this.context);
FTSDK.installLogConfig(new FTLoggerConfig()
.setEnableCustomLog(true)
.setPrintCustomLogToConsole(true));
FTLogger.logBackground('登录成功', Status.INFO);
Write SDK Internal Logs to Local Files¶
When troubleshooting production or intermittent issues, you can write SDK internal diagnostic logs to a local file in the app sandbox for later export and analysis. setDebug(true) must also be enabled. You can use setSdkLogLevel(...) to control the log levels recorded.
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 FTInnerLogFileConfig to adjust the internal log file writing strategy:
| Field | Type | Required | Description |
|---|---|---|---|
singleFileMaxSize |
number |
No | Size of a single log file. Default: 5MB. Range: 1MB ~ 10MB. |
totalFileMaxSize |
number |
No | Total size threshold for 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 records written per batch. Default: 20. Range: 1 ~ 100. |
flushIntervalMs |
number |
No | Flush interval. Default: 200ms. Range: 50ms ~ 5000ms. |
By default, log files are written 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 starts cleanup 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 internal log integrity, set this configuration before
FTSDK.install(...)and also enablesetDebug(true). Values outside the configured range are clamped by the SDK to the allowed range and rounded.
Data Reporting and Caching¶
No Data Reported¶
Troubleshoot in the following order:
- Confirm that Prerequisites are complete, especially the DataKit and RUM collector configuration.
- Confirm that the app device can access
datakitUrlordatawayUrl. - If
setProxy(...),setProxyAuthenticator(...), orsetDns(...)is configured, confirm that the proxy, authentication information, DNS server, or DoH address is correct. These configurations affect only SDK data upload requests. - Refer to Enable Debug Mode and check the initialization and reporting logs.
- Confirm that RUM has executed
installRUMConfigand that at least one collection item to be verified is enabled. - By default, the SDK enables
deflatecompression for uploaded data. If you suspect server or network link incompatibility, temporarily setsetCompressIntakeRequests(false)for comparison verification. 0.1.18and later versions initialize only in the main process by default. If installation is executed in a child process, confirm whethersetOnlySupportMainProcess(false)needs to be called before installation.- Check the actual sampling values and remote overrides. In the new percentage API,
1means 1%, while the oldsetSamplingRate(1)means 100%. See RUM Initialization Configuration for details.
Caching and Synchronization¶
- SDK automatic synchronization uses a 10-second aggregation window. It is normal for uploads not to start immediately after collection.
- If automatic synchronization is disabled via
FTSDKConfig.setAutoSync(false)orFTSDK.setAutoSync(false), manually callFTSDK.flushSyncData()as described in SDK Initialization. - After SDK initialization, you can re-enable automatic synchronization via
FTSDK.setAutoSync(true). FTSDK.flushSyncData()does not wait for the 10-second aggregation window. It immediately schedules upload 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 it is in shadow mode: shadow mode still uses SQLite for reading and uploading while mirroring writes to FileStore for pre-migration validation. For detailed configuration, see SDK Initialization.
- The first migration of the old SQLite cache requires an explicit call to
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¶
Plugin Installed but Automatic Collection Not Taking Effect¶
With ft_sdk 0.1.18 and later, the plugin determines SDK dependencies based on the oh-package.json5 of the module that owns the source code. Each HAP, HAR, or HSP that needs automatic collection should declare the core package in its own dependencies; Replay also needs to declare the Replay package. Declaring it only in the project root, in another module, or in devDependencies will not enable instrumentation for the current module.
Confirm that the HAP's hvigorfile.ts has registered ftConsoleLogPlugin(), and then perform a clean build. At runtime, you also need to enable the log, Action, or Replay configuration separately. sdk_pkg_info.track can be used to verify the registered plugin version; optional chaining forms such as console?.info(...) and hilog.info?.(...) are not covered by automatic log collection.
Search for [GuanceBuild] in the Build output of DevEco Studio or in .hvigor/outputs/build-logs/build.log to view the feature name, source file, line and column positions, and skip reason. These build-time messages do not depend on FTSDKConfig.setDebug(true).
Cold Launch Action Does Not Appear¶
- Confirm that the plugin is effective and that the entry completes SDK and RUM installation as early as possible and enables
setEnableTraceUserAction(true). - Automatic first-frame collection requires API 22+. If the first UI frame is not observed, a complete cold launch Action is not reported.
- Background-origin launches wait for the first UI display in the same process;
0.1.18retainsapp_launch_type=background, and the duration includes background waiting. Processes that never display UI do not generate this Action. - Check Session sampling and whether
setActionTrackingHandler(...)filters launch events. A custom Handler should usegetSourceType()to distinguish the launch source; the launch event'sgetSource()isnull. - If the app initialization phase is incomplete, check whether the HAP's
module.json5configuresAbilityStageassrcEntry; if not configured, only approximate phase timing is available.
Page or Session Attribution Differs from Expectation¶
First confirm the foreground/background state when the event occurred. The new SDK uses ApplicationLaunch for launch events and BackgroundView or RootView for background or no-page events; these are SDK-managed Views. Sessions are refreshed after more than 15 minutes without user interaction or after lasting more than 4 hours.
When automatic View is enabled, avoid also calling manual startView(...) for the same page. Starting from 0.1.18, manually starting a View with the same name repeatedly also creates a new record; see Manual View Collection for usage.
UI Jank Not Collected¶
Confirm that setEnableTrackAppUIBlock(true, blockDurationMs) is enabled in the RUM configuration. HarmonyOS UI jank collection relies only on the system MAIN_THREAD_JANK event: the SDK uses the event's begin_time and end_time to calculate the duration and reports only foreground jank that exceeds the blockDurationMs threshold.
System events have a startup grace period, consecutive timeout requirements, and process-level reporting limits, so a single blocking test cannot be the only basis for determining whether collection is working. During troubleshooting, enable SDK Debug logs and filter for [FT-UI-BLOCK] in hilog to confirm whether the system event listener is registered and whether jank has been reported.
Automatic Collection for Network Requests¶
HttpInterceptorChain Not Taking Effect¶
If automatic collection using HttpInterceptorChain from @kit.NetworkKit is not working, check the following first:
- Whether the current device or build target is HarmonyOS API 22 or later; this capability is not supported below API 22.
- Whether the project has installed
ft_sdk.harandft_sdk_ext.harand declared them inoh-package.json5as@guancecloud/ft_sdkand@guancecloud/ft_sdk_ext, then completedohpm install. - Whether
setEnableTraceUserResource(true)is enabled; if automatic Trace Headers injection is required,setEnableAutoTrace(true)in the Trace configuration also needs to be enabled. - It is known that in concurrent request scenarios with
@kit.NetworkKit, even if an independentHttpRequestandHttpInterceptorChainare created for each request, an exception may still be triggered:{"code":2300003,"message":"Invalid URL format or missing URL"} - If you encounter the above error, fall back to serial verification first; in concurrent scenarios, use RCP or Axios compatibility mode, or temporarily avoid using
HttpInterceptorChainin high-concurrency paths.
Resource Cannot Be Collected¶
If an HTTP request has already been created and the automatic collection interceptor has been attached, but SDK initialization and RUM configuration are performed later, the request may succeed but no Resource data is generated.
Check the following first:
- Whether
HttpRequestwas created first,createFTHttpInterceptorChain()orapplyFTHttpTrack()was called, and only laterFTSDK.installRUMConfig()was executed. - Whether
setEnableTraceUserResource(true)is enabled in the RUM configuration.
Cause:
- When
HttpInterceptorChainis created, it immediately reads the current RUM configuration to decide whether to enable automatic Resource collection. - If this step occurs before
FTSDK.installRUMConfig(), the default value read by the SDK isfalse. - Even if SDK initialization is completed later, the already-created automatic collection interceptor instance will not automatically refresh to the enabled state, so no
Resourceis generated.
Recommended handling:
- Complete
FTSDK.install()andFTSDK.installRUMConfig()first, then createHttpRequestand attachHttpInterceptorChain. - If the request object or interceptor chain was created in advance, recreate and reattach it after SDK initialization is complete.
- If you really need to create automatic collection objects before SDK initialization, explicitly pass the switches at creation time to avoid relying on default configuration values.
Optional example:
applyFTAxiosTrack(client, {
enableTraceInterceptor: true,
enableResourceInterceptor: true
});
// Then complete FTSDK.install(...) and FTSDK.installRUMConfig(...), and then initiate a business request.
Note:
- Explicitly passing
enableTraceInterceptorandenableResourceInterceptoronly ensures that the automatic collection mechanism itself is enabled. - Requests already sent before SDK initialization is complete may still be unable to generate or complete
Resourcedata because the RUM context has not been fully initialized. - Therefore, the more recommended approach is still to complete SDK initialization first, then create and use automatic collection objects.
Similar handling 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 })
Resource Exists but No Network Error¶
If the request has no HTTP response, first check FTRUMConfig.setNetworkErrorHandler(...) and the integration-level networkErrorHandler. If the Handler returns true, the Resource with status code 0 is retained, and only its derived Network Error is skipped. HTTP 4xx/5xx are not affected by this filter; see Local Network Failure Filtering for details.
Missing Network Phases or Request Size¶
RCP requires the platform to provide timeInfo; HTTP/Axios require performanceTiming. If the platform does not expose them, the timing order is abnormal, or connection reuse occurs, some phases may be missing; the SDK does not fabricate values. Since 0.1.18, HTTPS connection time includes TLS and must no longer be added to SSL time.
Request size, protocol, and connection reuse also depend on valid values provided by the platform or integrator; missing values cannot be interpreted as zero or false. Bandwidth, verification status, and signal at request start are also not available on every device. See Resource Performance Notes and Application Data Collection.
Session Replay¶
- Check the core package, Replay package, and plugin versions, and complete installation according to HarmonyOS Session Replay (Experimental).
- Confirm that you first initialize the SDK and RUM, then initialize Replay and pass the private
filesDir; after configuringsetDelayInit(true), you need to explicitly callstart(). - Confirm that sampling is hit. Replay's
setSampleRate(10)means 10% and is configured independently of RUM sampling; in errors-only sampling mode, an associated RUM Error must be present before entering the upload queue. - Check whether the plugin has processed the current module and pages; if the plugin is not used, confirm that you have manually registered the root node of the visible page. Neither initialization nor
isEnabled()returningtrueproves that valid replay frames have been saved. - Text, images, and touch are masked by default. When screen content is masked or touch positions are missing, verify the privacy policy first before determining whether there is a collection anomaly.
- ArkWeb also requires the native WebView RUM Bridge and the web Browser SDK to start recording. Native Replay should be ready before the web SDK loads; reload the web page if necessary.
- Confirm that the core upload address is valid; when using a local DataKit, check the replay receiving configuration.
disable() only stops new collection; accepted frames are still saved and automatic upload continues draining; the presence of upload requests after stopping does not mean recording is still ongoing.
Related Documentation¶
- Installation and entry page: See Application Access
- Initialization parameters: See SDK Initialization
- RUM network collection: See RUM Configuration
- Trace Distributed Tracing: See Trace Configuration