Skip to content

SDK Initialization

This document covers Android SDK initialization.

Application Configuration

The best place to initialize the SDK is in the onCreate method of the Application. If your application does not already have an Application class, you need to create one and declare it in AndroidManifest.xml. For an example, see here.

<application
       android:name="YourApplication">
</application>

Basic Configuration

public class DemoApplication extends Application {

    @Override
    public void onCreate() {
        // Local environment deployment, DataKit deployment
        FTSDKConfig config = FTSDKConfig.builder(datakitUrl);
        // Use the public DataWay
        FTSDKConfig config = FTSDKConfig.builder(datawayUrl, clientToken);
        // ...
        // config.setDebug(true);              // debug mode
        FTSdk.install(config);
    }
}
class DemoApplication : Application() {
    override fun onCreate() {
        // Local environment deployment, DataKit deployment
        val config = FTSDKConfig.builder(datakitUrl)
        // Use the public DataWay
        val config = FTSDKConfig.builder(datawayUrl, clientToken)
        // ...
        // config.setDebug(true)              // debug mode
        FTSdk.install(config)
    }
}
Method Name Type Required Description
datakitUrl String Yes Upload URL for local environment deployment (DataKit), e.g., http://10.0.0.1:9529, default port 9529. The device with the SDK installed must be able to access this address. Note: configure only one of datakitUrl or datawayUrl
datawayUrl String Yes Upload URL for the public Dataway. Obtain it from the [RUM] application, e.g., https://open.dataway.url. The device with the SDK installed must be able to access this address. Note: configure only one of datakitUrl or datawayUrl
clientToken String Yes Authentication token, must be configured together with datawayUrl
setDebug Boolean No Whether to enable debug mode, default false. SDK runtime logs are printed only after it is enabled
setEnv EnvType No Sets the collection environment, default EnvType.PROD
setEnv String No Sets the collection environment, default prod. Note: configure only one of the String or EnvType types
setOnlySupportMainProcess Boolean No Whether to run only in the main process, default true. Set it to false if execution in other processes is needed
setAllowWebViewHost Array No Sets the host range where WebView RUM and Log are allowed to use Bridge. null means all hosts are allowed, an empty array means Bridge is not used automatically, and configured hosts also match their subdomains. Defaults to null. Supported from ft-sdk 1.7.5 and above. See WebView Monitoring
setEnableAccessAndroidID Boolean No Enables collection of Android ID, default true. When set to false, the device_uuid field data is not collected. For marketplace privacy review, see here
addGlobalContext Dictionary No Adds SDK global attributes. See here for the adding rules
setServiceName String No Sets the service name, affecting the service field data in Log and RUM. Default df_rum_android
setAutoSync Boolean No Whether to sync data to the server automatically after collection, default true. When false, use FTSdk.flushSyncData() to manage data sync manually
setSyncPageSize Int No Sets the number of items per sync request: SyncPageSize.MINI 5 items, SyncPageSize.MEDIUM 10 items, SyncPageSize.LARGE 50 items. Default SyncPageSize.MEDIUM
setCustomSyncPageSize Enum No Sets the number of items per sync request, range [5,). Note that a larger number of items per request consumes more computational resources for data sync. Default 10. Note: configure only one of setSyncPageSize and setCustomSyncPageSize
setSyncSleepTime Int No Sets the interval between syncs, range [0,5000], in ms, default 0
enableDataIntegerCompatible Void No It is recommended to enable this when data needs to coexist with web data. This setting handles storage compatibility for web data types. Enabled by default from ft-sdk 1.6.9
setNeedTransformOldCache Boolean No Whether to convert and sync legacy cached data from versions below ft-sdk 1.6.0, default false
enableFileDataStore Void No Enables file cache for sync cache and RUM aggregation data. SQLite cache is still used by default. Supported from ft-sdk 1.7.2 and above
setUseFileDataStore Boolean No Sets whether to use file cache. Pass true to use file cache, false to use the default SQLite cache. Supported from ft-sdk 1.7.2 and above
setFileDataStoreShadow Boolean No Enables shadow write for file cache. When enabled, reads still use SQLite while writes are mirrored to the file cache, for validation before migration. Supported from ft-sdk 1.7.2 and above
setCompressIntakeRequests Boolean No Deflate-compresses uploaded sync data, enabled by default. Set to false to disable. Supported from ft-sdk 1.6.3 and above
enableLimitWithCacheSize Void, Long No Enables total cache size limit, default 100MB, in Bytes. When cacheSize is passed, the range is [30MB,). Once enabled, FTLoggerConfig.setLogCacheLimitCount and FTRUMConfig.setRumCacheLimitCount no longer take effect. Supported from ft-sdk 1.7.2 and above
setCacheDiscard CacheDiscard No Sets the discard policy when the cache reaches the size limit, default CacheDiscard.DISCARD. DISCARD discards newly appended data, DISCARD_OLDEST deletes the oldest cached data. Supported from ft-sdk 1.7.2 and above
enableLimitWithDbSize Void No Deprecated, kept for compatibility with older versions. Use enableLimitWithCacheSize instead
setEnableOkhttpRequestTag Boolean No Automatically adds a unique ResourceID to OkHttp Requests, for high-concurrency scenarios with identical requests. Supported from ft-sdk 1.6.10 and ft-plugin 1.3.5 and above
setProxy java.net.Proxy No Sets a proxy for data network sync requests. Only okhttp3 is supported. Supported from ft-sdk 1.6.10 and above
setProxyAuthenticator okhttp3.Authenticator No Sets a proxy authenticator for data sync network requests. Only okhttp3 is supported. Supported from ft-sdk 1.6.10 and above
setDns okhttp3.Dns No Supports custom DNS for domain resolution in data sync network requests. Only okhttp3 is supported. Supported from ft-sdk 1.6.10 and above
setDataModifier DataModifier No Modifies individual fields. Supported from ft-sdk 1.6.11 and above. See usage examples here
setLineDataModifier LineDataModifier No Modifies individual data lines. Supported from ft-sdk 1.6.11 and above. See usage examples here
setEnableDataFilter Boolean No Whether to enable blacklist filtering, default true. Supports filtering Logging and RUM data. Supported from ft-sdk 1.7.2 and above
setDataFilters HashMap<String, String[]> No Configures in-app blacklist rules, supporting logging and rum data types. See blacklist filtering rules for the rule syntax. Supported from ft-sdk 1.7.2 and above
setRemoteConfiguration Boolean No Whether to enable remote configuration for data collection, default false. When enabled, SDK initialization or app hot start triggers data updates. Supported from ft-sdk 1.6.12 and above. DataKit version >= 1.60 is required, or use the public Dataway
setRemoteConfigMiniUpdateInterval Int No Sets the minimum interval for data updates, in seconds, default 12 hours. Supported from ft-sdk 1.6.12 and above
setRemoteConfigurationCallBack FTRemoteConfigManager.FetchResult No Returns the remote configuration result. Code example. Supported from ft-sdk 1.6.16 and above

File Cache

From ft-sdk 1.7.2 and above, sync cache and RUM aggregation data can be written to a file cache. To ensure smooth upgrades from older versions, the SDK still uses SQLite cache by default. If you want to enable file cache, explicitly enable it in FTSDKConfig.

FTSDKConfig config = FTSDKConfig.builder(datawayUrl, clientToken)
        .enableFileDataStore();

FTSdk.install(config);
val config = FTSDKConfig.builder(datawayUrl, clientToken)
    .enableFileDataStore()

FTSdk.install(config)

If you need to validate the file cache writes first, you can enable shadow write. When enabled, the SDK still reads data from SQLite while mirroring writes to the file cache; switch to enableFileDataStore after validation.

FTSDKConfig config = FTSDKConfig.builder(datawayUrl, clientToken)
        .setFileDataStoreShadow(true);
val config = FTSDKConfig.builder(datawayUrl, clientToken)
    .setFileDataStoreShadow(true)

Cache Size Limit

From ft-sdk 1.7.2 and above, use enableLimitWithCacheSize to configure the SDK total cache size limit. Once enabled, the separate log count limit FTLoggerConfig.setLogCacheLimitCount and RUM count limit FTRUMConfig.setRumCacheLimitCount no longer take effect.

FTSDKConfig config = FTSDKConfig.builder(datawayUrl, clientToken)
        // Enable total cache size limit, 100MB in this example
        .enableLimitWithCacheSize(100 * 1024 * 1024L)
        // Delete the oldest cached data when the cache reaches the limit
        .setCacheDiscard(CacheDiscard.DISCARD_OLDEST);

FTSdk.install(config);
val config = FTSDKConfig.builder(datawayUrl, clientToken)
    // Enable total cache size limit, 100MB in this example
    .enableLimitWithCacheSize(100 * 1024 * 1024L)
    // Delete the oldest cached data when the cache reaches the limit
    .setCacheDiscard(CacheDiscard.DISCARD_OLDEST)

FTSdk.install(config)

Blacklist Filtering

From ft-sdk 1.7.2 and above, Logging and RUM data can be filtered before being written to the local cache. This capability is enabled by default and can be disabled with setEnableDataFilter(false).

Blacklist rules can be centrally configured in the blacklist of the Guance workspace and pulled automatically by the SDK from DataKit or Dataway. They can also be configured in-app with setDataFilters. Both approaches correspond to the same blacklist filtering capability and can be used simultaneously. Once any rule is matched, the data is discarded.

setDataFilters supports logging and rum rule types. Each rule is expressed as { condition } and can match data tags, fields, and data type identifier fields such as source, measurement, and class. For the complete syntax, see blacklist filtering rules.

Blacklist filtering runs after LineDataModifier and before writing to the local cache. If both setLineDataModifier and blacklist filtering are configured, the filter rules are evaluated against the modified data.

HashMap<String, String[]> filters = new HashMap<>();
filters.put("logging", new String[]{
        "{ source in ['custom_log'] and message match ['password'] }"
});
filters.put("rum", new String[]{
        "{ source in ['resource'] and status in [404, 503] }"
});

FTSDKConfig config = FTSDKConfig.builder(datawayUrl, clientToken)
        .setEnableDataFilter(true)
        .setDataFilters(filters);

FTSdk.install(config);
val filters = hashMapOf(
    "logging" to arrayOf(
        "{ source in ['custom_log'] and message match ['password'] }"
    ),
    "rum" to arrayOf(
        "{ source in ['resource'] and status in [404, 503] }"
    )
)

val config = FTSDKConfig.builder(datawayUrl, clientToken)
    .setEnableDataFilter(true)
    .setDataFilters(filters)

FTSdk.install(config)

To disable local and remote data filtering, set it explicitly:

FTSDKConfig.builder(datawayUrl, clientToken)
        .setEnableDataFilter(false);

The pull interval for workspace blacklist rules follows the pull_interval returned by the server. When the server returns no valid value, the SDK uses 10 seconds as the fallback interval. pull_interval supports a number of seconds or a string with a unit, such as 10, 30s, 2m, or 1h.

Runtime Capabilities

Shutting Down the SDK

If you need to change the SDK configuration dynamically, shut down the SDK first to avoid generating incorrect data.

FTSdk.shutDown();
FTSdk.shutDown()

Clearing SDK Cache Data

Use FTSdk to clear unsynced cached data.

FTSdk.clearAllData();
FTSdk.clearAllData()

Configuring Automatic Data Sync

From ft-sdk 1.7.3 and above, automatic sync of cached data can be dynamically enabled or disabled after SDK initialization. When disabled, the SDK still writes collected data to the local cache but does not trigger sync automatically after collection; you can manage data sync with FTSdk.flushSyncData().

// Disable automatic sync
FTSdk.setAutoSync(false);

// Enable automatic sync
FTSdk.setAutoSync(true);
// Disable automatic sync
FTSdk.setAutoSync(false)

// Enable automatic sync
FTSdk.setAutoSync(true)

Manually Syncing Data

Use FTSdk to manually sync data.

When FTSdk.setAutoSync(false) is set, you need to sync data manually.

FTSdk.flushSyncData();
FTSdk.flushSyncData()