Skip to content

SDK Initialization

This document describes Flutter SDK initialization and related runtime capabilities.

Basic Configuration

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  // Local deployment with Datakit
  await FTMobileFlutter.sdkConfig(
    datakitUrl: datakitUrl,
  );

  // Use the public DataWay
  await FTMobileFlutter.sdkConfig(
    datawayUrl: datawayUrl,
    cliToken: cliToken,
  );
}
Field Type Required Description
datakitUrl String Yes Report URL for local deployment (Datakit), e.g., http://10.0.0.1:9529. The default port is 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 Report URL for the public DataWay, obtained 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
cliToken String Yes Authentication token. Must be configured together with datawayUrl
debug bool No Whether to allow log printing. Default: false
env String No Environment configuration. Default: prod. Any string is accepted; a single word such as test is recommended
envType enum EnvType No Environment configuration. Default: EnvType.prod. Note: configure only one of env or envType
autoSync bool No Whether to automatically sync data to the server after collection. Default: true. When set to false, use FTMobileFlutter.flushSyncData() to manage data sync manually
syncPageSize enum No Sets the number of entries per sync request. SyncPageSize.mini: 5 entries; SyncPageSize.medium: 10 entries; SyncPageSize.large: 50 entries. Default: SyncPageSize.medium
customSyncPageSize number No Sets the number of entries per sync request. Range: [5, ). A larger entry count means data sync consumes more computing resources
syncSleepTime number No Sets the interval between sync operations. Range: [0,5000]. Not set by default
globalContext object No Adds custom tags. For addition rules, see Field Conflict Description
serviceName String No Service name
customHttpOverrides HttpOverrides No Custom HTTP Overrides. When HTTP automatic collection is enabled and your project has customized HttpOverrides.global, pass in your custom implementation through this parameter. The SDK reuses this implementation in the collection pipeline
enableLimitWithDbSize boolean No Enables limiting data size using the database. Default: 100MB (unit: byte), disabled by default. Once enabled, logCacheLimitCount and rumCacheLimitCount become ineffective. Supported from SDK 0.5.3-pre.2 and above
dbCacheLimit number No DB cache size limit. Range: [30MB, ). Default: 100MB (unit: byte). Supported from SDK 0.5.3-pre.2 and above
dbCacheDiscard string No Sets the data discard rule in the database. FTDBCacheDiscard.discard discards new data (default); FTDBCacheDiscard.discardOldest discards the oldest data. Supported from SDK 0.5.3-pre.2 and above
enableLimitWithCacheSize boolean No Enables limiting data size by cache size. Android uses the total cache size limit; iOS maps to the DB cache size limit. When enabled, cacheLimit takes priority; if not set, dbCacheLimit is used as a fallback
cacheLimit number No Cache size limit, in bytes. Android: total cache size; iOS: DB cache limit
cacheDiscard enum FTCacheDiscard No Sets the cache data discard rule. Android uses the cache discard policy; iOS maps to the DB data discard rule. FTCacheDiscard.discard discards new data (default); FTCacheDiscard.discardOldest discards the oldest data
enableFileDataStore boolean No Android: whether to enable FileStore file caching
needTransformOldCache boolean No Android: whether to migrate old SQLite cache data when FileStore is enabled
fileDataStoreShadow boolean No Android: whether to write to FileStore synchronously when using the SQLite read path
compressIntakeRequests boolean No Compresses upload sync data with deflate. Supported from SDK 0.5.3-pre.2 and above. Disabled by default
enableDataIntegerCompatible boolean No Recommended when the data needs to coexist with Web data. Used to handle Web data type storage compatibility. Enabled by default from 0.5.4-pre.1 and above
dataModifier Map No Modifies individual fields. For usage examples, see Data Collection Masking
lineDataModifier Map> No Modifies individual data entries. For usage examples, see Data Collection Masking
enableDataFilter bool No Whether to enable SDK-side blacklist filtering. Default: true. Supports filtering Log and RUM data. Supported from SDK 0.5.7 and above. For usage examples, see Blacklist Filtering
dataFilters Map> No Configures in-app blacklist rules. Supports logging and rum data. Supported from SDK 0.5.7 and above. For rule syntax, see Rule Syntax
enableRemoteConfiguration boolean No Whether to enable remote configuration. When enabled, the SDK pulls remote configuration at the configured interval and applies it to the current runtime
remoteConfigMiniUpdateInterval number No Minimum update interval for remote configuration. Must be used together with enableRemoteConfiguration
remoteConfigOverrideRules List> No Local override rules for remote configuration, used to override remote configuration results during debugging or in specific scenarios
iOSGroupIdentifiers List No iOS App Group identifier list, used to share cached data between Extensions and the main App

Blacklist Filtering

Flutter SDK 0.5.7 and above supports filtering RUM and Log data before it is written to the local cache. This capability is enabled by default. You can disable SDK-side filtering by setting enableDataFilter: false.

Blacklist rules can be configured centrally in the Blacklist page of a Guance workspace, and the SDK pulls them automatically from DataKit or DataWay. They can also be configured in-app via FTMobileFlutter.sdkConfig(dataFilters: ...). Both methods correspond to the same blacklist filtering capability and can be used together. If any rule matches, the data entry is discarded.

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

enableDataFilter only controls rule pulling and filtering on the SDK side. Once set to false, the SDK no longer applies dataFilters or pulls workspace rules. When reporting via DataKit, workspace blacklists may still be enforced on the DataKit side.

Data Filter operates on the SDK data write pipeline. Too many rules or overly complex regular expressions may affect data write performance. It is recommended to configure only necessary rules.

await FTMobileFlutter.sdkConfig(
  datawayUrl: datawayUrl,
  cliToken: cliToken,
  enableDataFilter: true,
  dataFilters: {
    'logging': [
      "{ source in [ 'df_rum_ios_log', 'df_rum_android_log' ] and message match [ 'timeout' ] }",
    ],
    'rum': [
      "{ resource_status match [ '5..' ] }",
    ],
  },
);

The SDK pulls workspace blacklist rules immediately upon initialization. Subsequent pull intervals follow the pull_interval returned by the server. If the server does not return a valid value, the SDK uses 10 seconds as a fallback interval. pull_interval supports plain seconds or unit-qualified strings, such as 10, 30s, 2m, and 1h.

Rule Syntax

The Data Filter rule syntax is basically the same as the blacklist filtering rule syntax. For the complete syntax, see Blacklist Filtering Rules.

The key of dataFilters indicates the data category. The SDK currently supports:

Category Description
logging Log data
rum RUM data

Each rule is expressed as { condition }. Data under a category is filtered when it matches any rule. Rules can use the tag and field fields of the data, as well as the source and measurement fields that identify the data type.

For field value formats and operator semantics, refer to Field Value Format Description and Operator Description in the blacklist filtering rules.

Field values in SDK rule strings should use the array format. The negative operators support not in and not match, and are compatible with notin, notmatch, and not_in used in server-delivered rules.

{ status in [ 'debug' ] and env not in [ 'prod' ] and message not match [ '.*error.*' ] }

Binding and Unbinding User Information

Usage

/// Binds a user
///
/// [userid] User ID
/// [userName] User name
/// [userEmail] User email
/// [userExt] Extended data
static Future<void> bindRUMUserData(String userId,
    {String? userName, String? userEmail, Map<String, String>? ext})

/// Unbinds a user
static Future<void> unbindRUMUserData()

Code Example

FTMobileFlutter.bindRUMUserData("flutterUser");

FTMobileFlutter.unbindRUMUserData();

For rules on adding to ext, see Field Conflict Description.

Runtime Capabilities

Manual Data Sync

FTMobileFlutter.flushSyncData();

Manual data sync is only required when autoSync: false.

Feedback

Is this page helpful?