Dynamic Configuration and Dynamic Update Endpoints¶
Proactively Synchronize Dynamic Configuration¶
Use FTSdk to proactively synchronize dynamic configuration. When automatic updates do not meet requirements, adjust the update timing by actively calling the method.
Supported in ft-sdk >= 1.6.16. You can parse environment variables yourself via
FetchResult.onConfigSuccessFetched(RemoteConfigBean configBean, String jsonConfig).
/**
* Proactively update remote configuration. The call frequency is affected by FTSDKConfig.setRemoteConfigMiniUpdateInterval.
*/
FTSdk.updateRemoteConfig();
/**
* Proactively update remote configuration. This method ignores the FTSDKConfig.setRemoteConfigMiniUpdateInterval configuration.
*
* @param remoteConfigMiniUpdateInterval Remote configuration update interval, in seconds [0,)
* @param result Returns the update result.
*/
FTSdk.updateRemoteConfig(int remoteConfigMiniUpdateInterval, FTRemoteConfigManager.FetchResult result);
/**
* Proactively update remote configuration. The call frequency is affected by FTSDKConfig.setRemoteConfigMiniUpdateInterval.
*/
FTSdk.updateRemoteConfig()
/**
* Proactively update remote configuration. This method ignores the FTSDKConfig.setRemoteConfigMiniUpdateInterval configuration.
*
* @param remoteConfigMiniUpdateInterval Remote configuration update interval, in seconds [0,)
* @param result Returns the update result.
*/
FTSdk.updateRemoteConfig(remoteConfigMiniUpdateInterval, result)
Code Sample¶
FTSdk.updateRemoteConfig(0, new FTRemoteConfigManager.FetchResult() {
@Override
public void onResult(boolean success) {
//
}
@Override
public RemoteConfigBean onConfigSuccessFetched(RemoteConfigBean configBean, String jsonConfig) {
// Optional extension: custom parsing and modification of local configuration.
boolean isVip = false;
try {
JSONObject jsonObject = new JSONObject(jsonConfig);
String userid = jsonObject.optString("custom_userid");
isVip = (userid.equals("custom_user_test6"));
} catch (JSONException e) {
}
if (isVip) {
configBean.setRumSampleRate(1f);
configBean.setLogSampleRate(1f);
configBean.setTraceSampleRate(1f);
}
return configBean;
}
});
FTSdk.updateRemoteConfig(0, object : FTRemoteConfigManager.FetchResult {
override fun onResult(success: Boolean) {
//
}
override fun onConfigSuccessFetched(
configBean: RemoteConfigBean,
jsonConfig: String
): RemoteConfigBean {
// Optional extension: custom parsing and modification of local configuration.
var isVip = false
try {
val jsonObject = JSONObject(jsonConfig)
val userId = jsonObject.optString("custom_userid")
isVip = userId == "custom_user_test6"
} catch (e: JSONException) {
// ignore
}
if (isVip) {
configBean.setRumSampleRate(1f)
}
return configBean
}
})
Dynamically Enable and Disable AndroidID Retrieval¶
Use FTSdk to set whether the SDK retrieves the Android ID.
Dynamically Update Upload Endpoint¶
Use FTSdk to dynamically switch the data upload endpoint during SDK runtime. After successful setting, subsequent data will continue to be uploaded to the new address.
Supported in ft-sdk >= 1.6.17. Use either
setDatakitUrlorsetDatawayUrl. When usingsetDatawayUrl, a newclientTokenmust also be provided.
Use Cases¶
FTSDKConfig.builder() supports initialization without providing datakitUrl or datawayUrl. In this scenario, the SDK will perform data collection but will not upload it.
When FTSdk.setDatakitUrl(...) or FTSdk.setDatawayUrl(..., ...) is subsequently called to dynamically set the upload endpoint, the SDK will begin consuming the local cache and performing data upload.
It is important to note that data collected during the period when no upload address is set is still subject to local cache limits. The cache limit is primarily influenced by the following configurations:
FTLoggerConfig.setLogCacheLimitCountFTRUMConfig.setRumCacheLimitCount- The total cache size limit corresponding to
FTSDKConfig.enableLimitWithCacheSize
If the cache reaches its limit, data exceeding the limit may be discarded. Therefore, it is recommended to promptly provide the upload address in this mode, or reasonably set cache limits based on business scenarios.
| Method Name | Type | Required | Meaning |
|---|---|---|---|
| setDatakitUrl | String | Yes | Dynamically sets the Datakit upload endpoint. After successful setting, the SDK will continue uploading data to the new Datakit address. |
| setDatawayUrl | String, String | Yes | Dynamically sets the Dataway upload endpoint and clientToken. After successful setting, the SDK will continue uploading data to the new Dataway address. |