Troubleshooting¶
This article provides basic troubleshooting steps for HarmonyOS SDK initialization and reporting exceptions.
Initialization Failure¶
If SDK initialization fails, it is recommended to first check:
- 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_nativerespectively, followed by executingohpm install. - Whether the application has completed the dependency declaration in
oh-package.json5as per the documentation. - Whether SDK initialization occurs during the application startup phase.
No Data Reporting¶
It is recommended to troubleshoot in the following order:
- Confirm that the prerequisites have been completed, especially the DataKit and RUM collector configurations.
- Confirm that the application device can access
datakitUrlordatawayUrl. - Enable
setDebug(true)and check the initialization and reporting logs. - Confirm that RUM has executed
installRUMConfigand at least one collection item requiring verification is enabled.
HttpInterceptorChain Not Working¶
If the automatic collection using @kit.NetworkKit's HttpInterceptorChain does not take effect, it is recommended to first check:
- Whether the current device or compilation target is HarmonyOS API 22 or higher; this capability is not supported below API 22.
- Whether
ft_sdk.harandft_sdk_ext.harhave been installed in the project, and declared inoh-package.json5as@guancecloud/ft_sdkand@guancecloud/ft_sdk_extrespectively, followed by completingohpm install. - Whether
setEnableTraceUserResource(true)has been enabled; if automatic injection of Trace Headers is needed, also enablesetEnableAutoTrace(true)in the Trace configuration. - It is known that in concurrent request scenarios using
@kit.NetworkKit, even if independentHttpRequestandHttpInterceptorChainare created for each request, an exception may still be triggered:{"code":2300003,"message":"Invalid URL format or missing URL"}. - If encountering the above error, it is recommended to first downgrade to serial verification for validation; in concurrent scenarios, consider switching to RCP or Axios compatibility mode, or temporarily avoid using
HttpInterceptorChainin high-concurrency links.
Resource Not Collected¶
If an HTTP request has been created and the automatic collection interceptor is mounted, but the SDK initialization and RUM configuration are executed later, it is possible that the request succeeds but Resource data is not generated.
It is recommended to first check:
- Whether
HttpRequestwas created first,createFTHttpInterceptorChain()orapplyFTHttpTrack()was called, and thenFTSDK.installRUMConfig()was executed later. - Whether
setEnableTraceUserResource(true)has been enabled in the RUM configuration.
Reason explanation:
- 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. - Subsequently, even if SDK initialization is completed later, the already created automatic collection interceptor instance will not automatically refresh to the enabled state, and therefore will not generate
Resource.
Recommended handling methods:
- Complete
FTSDK.install()andFTSDK.installRUMConfig()first, then createHttpRequestand mountHttpInterceptorChain. - If the request object or interceptor chain has been created in advance, it needs to be recreated and remounted after SDK initialization is completed.
- If it is indeed necessary to create the automatic collection object before SDK initialization, you can explicitly pass the switch when creating it to avoid relying on the default configuration value.
Optional writing example:
applyFTAxiosTrack(client, {
enableTraceInterceptor: true,
enableResourceInterceptor: true
});
sdk.init();
Note:
- Explicitly passing
enableTraceInterceptorandenableResourceInterceptorcan only ensure that the automatic collection mechanism itself is in an enabled state. - Requests already sent before SDK initialization is completed may still fail to generate or complete
Resourcedata because the RUM context has not been initialized yet. - Therefore, the more recommended approach is still to complete SDK initialization first, then create and use the automatic collection object.
Similar handling methods also apply 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 })
Cache and Synchronization¶
- If automatic synchronization is turned off, i.e.,
autoSync = false, you need to manually callFTSDK.flushSyncData()mentioned in SDK Initialization. - If local cache is abnormal, you can use
FTSDK.clearAllData()to clean up unreported data and then re-verify.
Related Documents¶
- Installation and Entry Page: See Application Access.
- Initialization Parameters: See SDK Initialization.
- RUM Network Collection: See RUM Configuration.
- Trace Link Tracking: See Trace Configuration.