Dynamic Configuration and Dynamic Endpoint Updates¶
Remote Configuration¶
Use remote configuration to obtain environment variables delivered by the platform and adjust the SDK collection configuration. You can register a unified callback during SDK initialization, or actively fetch the configuration when needed by your business logic and perform custom processing before the configuration is applied.
Prerequisites¶
Before FTSdk.install(sdkConfig), enable remote configuration with FTSDKConfig.setRemoteConfiguration(true) and set a valid reporting endpoint. Then initialize RUM and use FTRUMConfig.setRumAppId(...) to specify the application whose configuration is to be fetched. For complete integration steps, see SDK Initialization and RUM Configuration.
Remote sampling configuration applies to modules that have already been integrated; log and trace collection still require their respective initialization.
Update Methods¶
| Update Method | Minimum Update Interval | Callback |
|---|---|---|
| Automatically attempt an update when RUM is initialized and when the app returns to the foreground | setRemoteConfigMiniUpdateInterval, default: 12 hours |
Global callback registered during initialization |
FTSdk.updateRemoteConfig() |
Uses the interval set during initialization | Global callback |
FTSdk.updateRemoteConfig(interval, result) |
Uses the interval passed in this call, in seconds, as a non-negative integer; 0 skips the interval check |
A non-null result takes precedence; otherwise, the global callback is used |
The minimum update interval limits request frequency. The SDK does not refresh on a fixed 12-hour schedule, and restarting the app does not reset the saved request time. Active updates are asynchronous requests; passing 0 still requires initialization conditions to be met, and if an existing request is being executed, this call is skipped.
Callbacks and Custom Configuration¶
ft-sdk >= 1.6.16supports customizing remote configuration throughFetchResult.onConfigSuccessFetched.
The responsibilities of the two methods in FETCH_RESULT are as follows:
| Method | Invocation Timing and Purpose |
|---|---|
onConfigSuccessFetched(configBean, jsonConfig) |
After a valid remote configuration that has changed is obtained, called before the configuration is applied. jsonConfig is the JSON corresponding to content in the response. You can parse custom fields and return a modified configBean; if null is returned, the object passed in is used. |
onResult(success) |
Returns the result of this update: true indicates that the configuration has been applied or the remote content has not changed; false indicates an update failure, missing RUM App ID, failure to reach the minimum interval, and so on. |
A non-null callback passed in this call replaces the global callback, and the two are not executed at the same time. If the SDK is not initialized, remote configuration is not enabled, or an existing request is being executed, an active call may not receive a callback. Callbacks are not guaranteed to run on the main thread; switch to the main thread when updating the UI.
The final configuration is applied and written to the local cache. When the remote content has not changed, only onResult(true) is executed. Even if 0 is passed for an active update, onConfigSuccessFetched is not executed again; changes in local users or business conditions do not automatically trigger configuration recalculation.
Code Example
The following sampling setters require
ft-sdk >= 1.7.6. The value range is[0,100]and decimals are supported; legacy sampling methods retain the[0,1]unit. For field and compatibility details, see Environment Variables.
The example omits the creation of sdkConfig and rumConfig, and stores the callback in a location accessible to both initialization and business refresh operations. The two scenarios run at different times: register the callback at startup, and then actively update at business trigger points later.
custom_userid is a custom field delivered remotely. In the example, when this field matches, the three sampling rates are set to 100%; to adjust based on the currently logged-in user, you also need to use the user ID from the business side and handle configuration restoration after user switching.
// Core: custom remote configuration callback, shared by initialization and active updates.
final FTRemoteConfigManager.FetchResult FETCH_RESULT =
new FTRemoteConfigManager.FetchResult() {
@Override
public RemoteConfigBean onConfigSuccessFetched(
RemoteConfigBean configBean, String jsonConfig) {
// Before applying the remote configuration, you can parse custom fields and override the configuration.
try {
JSONObject json = new JSONObject(jsonConfig);
String userId = json.optString("custom_userid", "");
if ("custom_user_test6".equals(userId)) {
// Sampling rate range: 0-100; 100f indicates 100%.
configBean.setSessionSamplingRate(100f);
configBean.setLogSamplingRate(100f);
configBean.setTraceSamplingRate(100f);
}
} catch (JSONException e) {
// If custom parsing fails, retain the original configuration.
}
return configBean;
}
@Override
public void onResult(boolean success) {
// true: update succeeded or configuration unchanged.
// false: update failed, the minimum update interval was not reached, etc.
}
};
// Scenario 1: During SDK / RUM initialization, enable remote configuration and register the callback.
sdkConfig.setRemoteConfiguration(true)
.setRemoteConfigurationCallBack(FETCH_RESULT);
FTSdk.install(sdkConfig);
FTSdk.initRUMWithConfig(rumConfig); // Use an existing RUM configuration, including the RUM App ID.
// Scenario 2: Actively update as needed in subsequent business logic; 0 means ignore the minimum update interval.
// When the configuration has not changed, only onResult(true) is called; custom parsing is not executed again.
FTSdk.updateRemoteConfig(0, FETCH_RESULT);
// Core: custom remote configuration callback, shared by initialization and active updates.
val FETCH_RESULT = object : FTRemoteConfigManager.FetchResult() {
override fun onConfigSuccessFetched(
configBean: RemoteConfigBean,
jsonConfig: String
): RemoteConfigBean {
// Before applying the remote configuration, you can parse custom fields and override the configuration.
try {
val json = JSONObject(jsonConfig)
val userId = json.optString("custom_userid", "")
if (userId == "custom_user_test6") {
// Sampling rate range: 0-100; 100f indicates 100%.
configBean.setSessionSamplingRate(100f)
configBean.setLogSamplingRate(100f)
configBean.setTraceSamplingRate(100f)
}
} catch (e: JSONException) {
// If custom parsing fails, retain the original configuration.
}
return configBean
}
override fun onResult(success: Boolean) {
// true: update succeeded or configuration unchanged.
// false: update failed, the minimum update interval was not reached, etc.
}
}
// Scenario 1: During SDK / RUM initialization, enable remote configuration and register the callback.
sdkConfig.setRemoteConfiguration(true)
.setRemoteConfigurationCallBack(FETCH_RESULT)
FTSdk.install(sdkConfig)
FTSdk.initRUMWithConfig(rumConfig) // Use an existing RUM configuration, including the RUM App ID.
// Scenario 2: Actively update as needed in subsequent business logic; 0 means ignore the minimum update interval.
// When the configuration has not changed, only onResult(true) is called; custom parsing is not executed again.
FTSdk.updateRemoteConfig(0, FETCH_RESULT)
Dynamically Enable and Disable Android ID Retrieval¶
Use FTSdk to specify whether the SDK retrieves the Android ID.
Dynamically Update the Reporting Endpoint¶
Use FTSdk to dynamically switch the data reporting endpoint while the SDK is running. After the setting succeeds, subsequent data continues to be uploaded to the new endpoint.
Supported in ft-sdk >= 1.6.17. Use either
setDatakitUrlorsetDatawayUrl. When usingsetDatawayUrl, you must also pass a newclientToken.
Use Cases¶
FTSDKConfig.builder() supports initialization without passing datakitUrl or datawayUrl. In this scenario, the SDK performs data collection first but does not upload data.
After FTSdk.setDatakitUrl(...) or FTSdk.setDatawayUrl(..., ...) is subsequently called to dynamically set the reporting endpoint, the SDK starts consuming the local cache and reporting data.
Note that while no upload endpoint is set, collected data is still subject to the local cache limits. The cache limits are mainly affected by the following configurations:
FTLoggerConfig.setLogCacheLimitCountFTRUMConfig.setRumCacheLimitCount- The total cache size limit corresponding to
FTSDKConfig.enableLimitWithCacheSize
If the cache reaches its limit, data beyond the limit may be discarded. Therefore, in this mode, set the upload endpoint as soon as possible or configure the cache limits appropriately for your business scenario.
| Method Name | Type | Required | Description |
|---|---|---|---|
| setDatakitUrl | String | Yes | Dynamically sets the Datakit reporting endpoint. After the setting succeeds, the SDK continues to upload data to the new Datakit endpoint. |
| setDatawayUrl | String, String | Yes | Dynamically sets the Dataway reporting endpoint and clientToken. After the setting succeeds, the SDK continues to upload data to the new Dataway endpoint. |