Android Application Integration¶
By collecting metrics data from Android applications, analyze application performance visually.
Prerequisites¶
Note
If the RUM Headless service has been activated, the prerequisites are automatically configured, and the application can be directly integrated.
- Install DataKit;
- Configure the RUM Collector;
- Configure DataKit to be accessible over the public network and install the IP geolocation database.
Application Integration¶
- Go to User Access Monitoring > Create Application > Android;
- Enter the application name;
- Enter the application ID;
-
Select the application integration method:
- Public DataWay: Directly receives RUM data without installing the DataKit collector.
- Local Environment Deployment: Receives RUM data after meeting the prerequisites.
Installation¶
Source Code: https://github.com/GuanceCloud/datakit-android
Demo: https://github.com/GuanceDemo/guance-app-demo
Gradle Configuration¶
- Add the
SDK
remote repository address in the root directory'sbuild.gradle
file
buildscript {
//...
repositories {
//...
//Add the SDK remote repository address
maven {
url 'https://mvnrepo.jiagouyun.com/repository/maven-releases'
}
}
dependencies {
//...
//Add the Plugin dependency, requires AGP 7.4.2 or above, Gradle 7.2.0 or above
classpath 'com.cloudcare.ft.mobile.sdk.tracker.plugin:ft-plugin:[latest_version]'
// For AGP versions below 7.4.2, use ft-plugin-legacy
//classpath 'com.cloudcare.ft.mobile.sdk.tracker.plugin:ft-plugin-legacy:[latest_version]'
}
}
allprojects {
repositories {
//...
//Add the SDK remote repository address
maven {
url 'https://mvnrepo.jiagouyun.com/repository/maven-releases'
}
}
}
//setting.gradle
pluginManagement {
repositories {
google()
mavenCentral()
gradlePluginPortal()
//Add the SDK remote repository address
maven {
url('https://mvnrepo.jiagouyun.com/repository/maven-releases')
}
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
//Add the SDK remote repository address
maven {
url('https://mvnrepo.jiagouyun.com/repository/maven-releases')
}
}
}
//build.gradle
plugins{
//Add the Plugin dependency, requires AGP 7.4.2 or above, Gradle 7.2.0 or above
id 'com.cloudcare.ft.mobile.sdk.tracker.plugin' version '[lastest_version]' apply false
// For AGP versions below 7.4.2, use ft-plugin-legacy
//id 'com.cloudcare.ft.mobile.sdk.tracker.plugin.legacy' version '[lastest_version]' apply false
}
- Add the
SDK
dependency andPlugin
usage in the main moduleapp
'sbuild.gradle
file.
dependencies {
//Add the SDK dependency
implementation 'com.cloudcare.ft.mobile.sdk.tracker.agent:ft-sdk:[latest_version]'
//Dependency for capturing native layer crash information, must be used with ft-sdk and cannot be used alone
implementation 'com.cloudcare.ft.mobile.sdk.tracker.agent:ft-native:[latest_version]'
// json serialization
implementation 'com.google.code.gson:gson:2.8.+'
//Optional, required if automatic network request collection and automatic tracing are needed, minimum compatible version 3.12.+
implementation 'com.squareup.okhttp3:okhttp:4.+'
}
//Apply the plugin in the app build.gradle, missing configuration will affect the following automatic collection functions.
//
// Plugin` configuration functions:
// * Automatic configuration collection: App startup, OkHttp requests, WebView activities, Activity navigation
// * Automatic collection of View click events, Console Logcat
// * Automatic collection of Console Logcat
apply plugin: 'ft-plugin' //If using ft-plugin-legacy, use this configuration as well
//Configure plugin usage parameters (optional)
FTExt {
//Whether to display Plugin logs, default is false
//showLog = true
//Set ASM version, supports asm7 - asm9, default is asm9
//asmVersion='asm7'
//ASM ignore path configuration, . and / are equivalent in the path
//ignorePackages=['com.ft','com/ft']
}
android{
//...omitted code
defaultConfig {
//...omitted code
ndk {
//When using ft-native to capture native layer crash information, the supported abi architectures should be selected based on the application's adaptation to different platforms
//Currently, the abi architectures included in ft-native are 'arm64-v8a',
// 'armeabi-v7a', 'x86', 'x86_64'
abiFilters 'armeabi-v7a'
}
}
compileOptions {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
}
For the latest version, refer to the version names of ft-sdk, ft-plugin, and ft-native above.
Application Configuration¶
The best place to initialize the SDK is in the Application
's onCreate
method. If your application does not yet have an Application
, you need to create one and declare it in AndroidManifest.xml
. For an example, refer to here.
R8 / Proguard Obfuscation Configuration¶
If minifyEnabled
= true is set in android.buildTypes
, the following configuration needs to be enabled:
-dontwarn com.ft.sdk.**
### ft-sdk library
-keep class com.ft.sdk.**{*;}
### ft-native library
-keep class ftnative.*{*;}
### Prevent class names from being obfuscated when obtaining action_name in Action ###
-keepnames class * extends android.view.View
-keepnames class * extends android.view.MenuItem
SDK Initialization¶
Basic Configuration¶
public class DemoApplication extends Application {
@Override
public void onCreate() {
//Local environment deployment, Datakit deployment
FTSDKConfig config = FTSDKConfig.builder(datakitUrl);
//Use public DataWay
FTSDKConfig config = FTSDKConfig.builder(datawayUrl, clientToken);
//...
//config.setDebug(true); //debug mode
config.setCompressIntakeRequests(true); //Compress intake requests
FTSdk.install(config);
}
}
class DemoApplication : Application() {
override fun onCreate() {
//Local environment deployment, Datakit deployment
val config = FTSDKConfig.builder(datakitUrl)
//Use public DataWay
val config = FTSDKConfig.builder(datawayUrl, clientToken)
//...
//config.setDebug(true); //debug mode
config.setCompressIntakeRequests(true) //Compress intake requests
FTSdk.install(config)
}
}
Method Name | Type | Required | Meaning |
---|---|---|---|
datakitUrl | String | Yes | Local environment deployment (Datakit) intake URL address, example: http://10.0.0.1:9529, default port is 9529, the device installing the SDK must be able to access this address. Note: Only one of datakitUrl and datawayUrl can be configured |
datawayUrl | String | Yes | Public DataWay intake URL address, obtained from the [User Access Monitoring] application, example: https://open.dataway.url, the device installing the SDK must be able to access this address. Note: Only one of datakitUrl and datawayUrl can be configured |
clientToken | String | Yes | Authentication token, must be configured with datawayUrl |
setDebug | Boolean | No | Whether to enable debug mode. Default is false , enabling it will print SDK runtime logs |
setEnv | EnvType | No | Set the collection environment, default is EnvType.PROD , |
setEnv | String | No | Set the collection environment, default is prod . Note: Only one of String or EnvType type needs to be configured |
setOnlySupportMainProcess | Boolean | No | Whether to only support running in the main process, default is true , if it needs to run in other processes, set this field to false |
setEnableAccessAndroidID | Boolean | No | Enable obtaining Android ID , default is true , setting it to false will not collect data for the device_uuid field, for market privacy audit related information see here |
addGlobalContext | Dictionary | No | Add SDK global attributes, for adding rules see here |
setServiceName | String | No | Set the service name, affects the service field data in Log and RUM, default is df_rum_android |
setAutoSync | Boolean | No | Whether to automatically sync data to the server after collection, default is true . When false , use FTSdk.flushSyncData() to manage data synchronization manually |
setSyncPageSize | Int | No | Set the number of entries per sync request, SyncPageSize.MINI 5 entries, SyncPageSize.MEDIUM 10 entries, SyncPageSize.LARGE 50 entries, default is SyncPageSize.MEDIUM |
setCustomSyncPageSize | Enum | No | Set the number of entries per sync request, range [5,), note that a larger number of entries means more computational resources are used for data synchronization, default is 10 Note: Only one of setSyncPageSize and setCustomSyncPageSize needs to be configured |
setSyncSleepTime | Int | No | Set the sync interval time, range [0,5000], default is not set |
enableDataIntegerCompatible | Void | No | Recommended to enable when coexisting with web data. This configuration is used to handle web data type storage compatibility issues. Enabled by default in version 1.6.9 |
setNeedTransformOldCache | Boolean | No | Whether to be compatible with old cache data from ft-sdk versions below 1.6.0, default is false |
setCompressIntakeRequests | Boolean | No | Compress intake request data using deflate, default is off, supported in ft-sdk version 1.6.3 and above |
enableLimitWithDbSize | Void | No | Enable limiting data size using db, default is 100MB, unit is Byte, larger database means more disk pressure, default is off. Note: After enabling, FTLoggerConfig.setLogCacheLimitCount and FTRUMConfig.setRumCacheLimitCount will become invalid. Supported in ft-sdk version 1.6.6 and above |
setEnableOkhttpRequestTag | bool | No | Automatically add a unique ResourceID to Okhttp Request, used for high concurrency scenarios with the same request. Supported in ft-sdk 1.6.10 and above, ft-plugin 1.3.5 and above |
setProxy | java.net.Proxy | No | Set Proxy for data network sync requests, only supports okhttp3, supported in ft-sdk 1.6.10 and above |
setProxyAuthenticator | okhttp3.Authenticator | No | Set Proxy for data sync network requests, only supports okhttp3, supported in ft-sdk 1.6.10 and above |
setDns | okhttp3.Dns | No | Data sync network requests support custom Dns for domain name resolution, only supports okhttp3, supported in ft-sdk 1.6.10 and above |
setDataModifier | DataModifier | No | Modify a single field. Supported in ft-sdk 1.6.11 and above, for usage examples see here |
setLineDataModifier | LineDataModifier | No | Modify a single line of data. Supported in ft-sdk 1.6.11 and above, for usage examples see here |
setRemoteConfiguration | Int | No | Whether to enable remote configuration for data collection, default is false . When enabled, SDK initialization or application hot start will trigger data updates. Supported in ft-sdk 1.6.12 and above. datakit version requirement >=1.60 or using public dataway |
setRemoteConfigMiniUpdateInterval | Int | No | Set the minimum update interval for data updates, unit is seconds, default is 12 hours. Supported in ft-sdk 1.6.12 and above |
RUM Configuration¶
FTSdk.initRUMWithConfig(
new FTRUMConfig()
.setRumAppId(RUM_APP_ID)
.setEnableTraceUserView(true)
.setDeviceMetricsMonitorType(DeviceMetricsMonitorType.ALL.getValue())
.setEnableTraceUserAction(true)
.setEnableTraceUserResource(true)
.setEnableTrackAppUIBlock(true)
.setEnableTrackAppCrash(true)
.setEnableTrackAppANR(true)
.setExtraMonitorTypeWithError(ErrorMonitorType.ALL.getValue())
);
FTSdk.initRUMWithConfig(
FTRUMConfig()
.setRumAppId(RUM_APP_ID)
.setEnableTraceUserView(true)
.setDeviceMetricsMonitorType(DeviceMetricsMonitorType.ALL.getValue())
.setEnableTraceUserAction(true)
.setEnableTraceUserResource(true)
.setEnableTrackAppUIBlock(true)
.setEnableTrackAppCrash(true)
.setEnableTrackAppANR(true)
.setExtraMonitorTypeWithError(ErrorMonitorType.ALL.getValue())
)
Method Name | Type | Required | Meaning |
---|---|---|---|
setRumAppId | String | Yes | Set Rum AppId . Corresponds to setting the RUM appid , which enables the RUM collection function, how to get appid |
setSamplingRate | Float | No | Set the collection rate, range [0,1], 0 means no collection, 1 means full collection, default is 1. Scope is all View, Action, LongTask, Error data under the same session_id |
setSessionErrorSampleRate | Float | No | Set the error collection rate, when the session is not sampled by setSamplingRate , if an error occurs during the session, data from the 1 minute before the error can be collected, range [0,1], 0 means no collection, 1 means full collection, default is 0. Scope is all View, Action, LongTask, Error data under the same session_id. Supported in ft-sdk 1.6.11 and above |
setEnableTrackAppCrash | Boolean | No | Whether to report App crash logs, default is false , enabling it will display error stack data in error analysis.About converting obfuscated content in crash logs. ft-sdk 1.5.1 and above, can use extraLogCatWithJavaCrash , extraLogCatWithNativeCrash to set whether to display logcat in Java Crash and Native Crash |
setExtraMonitorTypeWithError | Array | No | Set auxiliary monitoring information, add additional monitoring data to Rum crash data, ErrorMonitorType.BATTERY for battery level, ErrorMonitorType.MEMORY for memory usage, ErrorMonitorType.CPU for CPU usage, default is not set |
setDeviceMetricsMonitorType | Array | No | Set View monitoring information, add monitoring data during the View lifecycle, DeviceMetricsMonitorType.BATTERY monitors the maximum output current of the current page, DeviceMetricsMonitorType.MEMORY monitors the memory usage of the current application, DeviceMetricsMonitorType.CPU monitors CPU jumps, DeviceMetricsMonitorType.FPS monitors screen frame rate. Monitoring cycle, DetectFrequency.DEFAULT 500 milliseconds, DetectFrequency.FREQUENT 100 milliseconds, DetectFrequency.RARE 1 second, default is not set |
setEnableTrackAppANR | Boolean | No | Whether to enable ANR detection, default is false .ft-sdk 1.5.1 and above, can use extraLogCatWithANR to set whether to display logcat in ANR |
setEnableTrackAppUIBlock | Boolean, long | No | Whether to enable UI block detection, default is false , ft-sdk 1.6.4 and above can use blockDurationMs to control the detection time range [100,), unit is milliseconds, default is 1 second |
setEnableTraceUserAction | Boolean | No | Whether to automatically trace user actions, currently only supports user startup and click actions, default is false |
setEnableTraceUserView | Boolean | No | Whether to automatically trace user page actions, default is false |
setEnableTraceUserViewInFragment | Boolean | No | Whether to automatically trace Fragment type page data, default is false , supported in ft-sdk 1.6.11 and above |
setEnableTraceUserResource | Boolean | No | Whether to automatically trace user network requests, only supports Okhttp , default is false |
setEnableResourceHostIP | Boolean | No | Whether to collect the IP address of the request target domain. Scope: only affects the default collection when EnableTraceUserResource is true. Custom Resource collection needs to use FTResourceEventListener.FTFactory(true) to enable this function. Additionally, a single Okhttp has an IP caching mechanism for the same domain, the same OkhttpClient , when the server IP does not change, will only generate once |
setResourceUrlHandler | Callback | No | Set the conditions for filtering Resource, default is no filter |
setOkHttpEventListenerHandler | Callback | No | ASM set global Okhttp EventListener, default is not set |
setOkHttpResourceContentHandler | Callback | No | ASM set global FTResourceInterceptor.ContentHandlerHelper , default is not set, supported in ft-sdk 1.6.7 and above, custom Resource |
addGlobalContext | Dictionary | No | Add custom tags, used to distinguish user monitoring data sources, if tracing function is needed, the parameter key is track_id , value is any value, for adding rule precautions see here |
setRumCacheLimitCount | int | No | Local cache RUM limit count [10_000,), default is 100_000. Supported in ft-sdk 1.6.6 and above |
setEnableTraceWebView | Boolean | No | Configure whether to enable WebView data collection through Android SDK, default is true. Supported in ft-sdk 1.6.12 and above |
setAllowWebViewHost | Array | No | Set the WebView host addresses allowed for data tracing, null means full collection, default is null. Supported in ft-sdk 1.6.12 and above |
Log Configuration¶
Method Name | Type | Required | Meaning |
---|---|---|---|
setSamplingRate | Float | No | Set the collection rate, range [0,1], 0 means no collection, 1 means full collection, default is 1. |
setEnableConsoleLog | Boolean | No | Whether to report console logs, default false , log level correspondenceLog.v -> ok; Log.i -> info; Log.d -> debug; Log.e -> error; Log.w -> warning, prefix is the prefix filter parameter, default is no filter. Note: Android console logs are voluminous, to avoid affecting application performance and reduce unnecessary resource waste, it is recommended to use prefix to filter out valuable logs. ft-plugin 1.3.5 and above, supports capturing logs printed by Log.println |
setEnableLinkRUMData | Boolean | No | Whether to associate with RUM data, default is false |
setEnableCustomLog | Boolean | No | Whether to upload custom logs, default is false |
setLogLevelFilters | Array | No | Set log level filters, default is not set |
addGlobalContext | Dictionary | No | Add log global attributes, for adding rules see here |
setLogCacheLimitCount | Int | No | Local cache maximum log entry count limit [1000,), larger logs mean more disk cache pressure, default is 5000 |
setLogCacheDiscardStrategy | LogCacheDiscard | No | Set the log discard rule when the log limit is reached, default is LogCacheDiscard.DISCARD , DISCARD discards appended data, DISCARD_OLDEST discards old data |
Trace Configuration¶
Method Name | Type | Required | Meaning |
---|---|---|---|
setSamplingRate | Float | No | Set the collection rate, range [0,1], 0 means no collection, 1 means full collection, default is 1. |
setTraceType | TraceType | No | Set the trace type, default is DDTrace , currently supports Zipkin , Jaeger , DDTrace , Skywalking (8.0+), TraceParent (W3C), if integrating OpenTelemetry, please check the supported types and agent related configurations |
setEnableLinkRUMData | Boolean | No | Whether to associate with RUM data, default is false |
setEnableAutoTrace | Boolean | No | Set whether to enable automatic http trace, currently only supports OKhttp automatic tracing, default is false |
setOkHttpTraceHeaderHandler | Callback | No | ASM set global FTTraceInterceptor.HeaderHandler , default is not set, supported in ft-sdk 1.6.8 and above, example reference custom Trace |
RUM User Data Tracing¶
In FTRUMConfig
configuration enableTraceUserAction
, enableTraceUserView
, enableTraceUserResource
,setEnableTrackAppUIBlock
,setEnableTrackAppCrash
and setEnableTrackAppANR
to achieve automatic collection tracing of Action
, View
, Resource
, LongTask
, Error
data. If you want to customize collection, you can use FTRUMGlobalManager
to report data, examples are as follows:
Action¶
Usage¶
/**
* Add Action
*
* @param actionName action name
* @param actionType action type
* @param property additional property parameters (optional)
*/
public void startAction(String actionName, String actionType, HashMap<String, Object> property)
/**
* Add Action, this type of data cannot associate Error, Resource, LongTask data
*
* @param actionName action name
* @param actionType action type
* @param duration nanoseconds, duration (optional)
* @param property additional properties (optional)
*/
public void addAction(String actionName, String actionType, long duration, HashMap<String, Object> property)
/**
* Add action
*
* @param actionName action name
* @param actionType action type
* @param property additional property parameters (optional)
*/
fun startAction(actionName: String, actionType: String, property: HashMap<String, Any>)
/**
* Add Action
*
* @param actionName action name
* @param actionType action type
* @param duration nanoseconds, duration (optional)
* @param property additional properties (optional)
*/
fun addAction(actionName: String, actionType: String, duration: Long, property: HashMap<String, Any>)
startAction internally has a time-consuming calculation algorithm, during the calculation period it will try to associate with nearby Resource, LongTask, Error data, there is a 100 ms frequent trigger protection, it is recommended to use for user operation type data. If there is a need for frequent calls, please use addAction, this data will not conflict with startAction, and will not associate with current Resource, LongTask, Error data
Code Example¶
// Scenario 1
FTRUMGlobalManager.get().startAction("login", "action_type");
// Scenario 2: Dynamic parameters
HashMap<String, Object> map = new HashMap<>();
map.put("ft_key", "ft_value");
FTRUMGlobalManager.get().startAction("login", "action_type", map);
// Scenario 1
FTRUMGlobalManager.get().addAction("login", "action_type");
// Scenario 2: Dynamic parameters
HashMap<String, Object> map = new HashMap<>();
map.put("ft_key", "ft_value");
FTRUMGlobalManager.get().addAction("login", "action_type", map);
// Scenario 1
FTRUMGlobalManager.get().startAction("login", "action_type")
// Scenario 2: Dynamic parameters
val map = HashMap<String,Any>()
map["ft_key"]="ft_value"
FTRUMGlobalManager.get().startAction("login","action_type",map)
// Scenario 1
FTRUMGlobalManager.get().startAction("login", "action_type")
// Scenario 2: Dynamic parameters
val map = HashMap<String,Any>()
map["ft_key"]="ft_value"
FTRUMGlobalManager.get().startAction("login","action_type",map)
View¶
Usage¶
/**
* view start
*
* @param viewName current page name
* @param property additional property parameters (optional)
*/
public void startView(String viewName, HashMap<String, Object> property)
/**
* view end
*
* @param property additional property parameters (optional)
*/
public void stopView(HashMap<String, Object> property)
/**
* view start
*
* @param viewName current page name
* @param property additional property parameters (optional)
*/
fun startView(viewName: String, property: HashMap<String, Any>)
/**
* view end
*
* @param property additional property parameters (optional)
*/
fun stopView(property: HashMap<String, Any>)
Code Example¶
@Override
protected void onResume() {
super.onResume();
// Scenario 1
FTRUMGlobalManager.get().startView("Current Page Name");
// Scenario 2: Dynamic parameters
HashMap<String, Object> map = new HashMap<>();
map.put("ft_key", "ft_value");
map.put("ft_key_will_change", "ft_value");
FTRUMGlobalManager.get().startView("Current Page Name", map);
}
@Override
protected void onPause() {
super.onPause();
// Scenario 1
FTRUMGlobalManager.get().stopView();
// Scenario 2 : Dynamic parameters
HashMap<String, Object> map = new HashMap<>();
map.put("ft_key_will_change", "ft_value_change"); //ft_key_will_change this value will be modified to ft_value_change when stopView
FTRUMGlobalManager.get().startView("Current Page Name", map);
}
override fun onResume() {
super.onResume()
// Scenario 1
FTRUMGlobalManager.get().startView("Current Page Name")
// Scenario 2: Dynamic parameters
val map = HashMap<String, Any>()
map["ft_key"] = "ft_value"
map["ft_key_will_change"] = "ft_value"
FTRUMGlobalManager.get().startView("Current Page Name", map)
}
override fun onPause() {
super.onPause()
// Scenario 1
FTRUMGlobalManager.get().stopView()
// Scenario 2 : Dynamic parameters
val map = HashMap<String, Any>()
map["ft_key_will_change"] = "ft_value_change" //ft_key_will_change this value will be modified to ft_value_change when stopView
FTRUMGlobalManager.get().startView("Current Page Name", map)
}
Error¶
Usage¶
/**
* Add error information
*
* @param log log
* @param message message
* @param errorType error type, ErrorType
* @param state program running state
* @param dateline occurrence time, nanoseconds (optional)
* @param property additional properties (optional)
*/
public void addError(String log, String message, long dateline, ErrorType errorType,
AppState state, HashMap<String, Object> property)
/**
* Add error information
*
* @param log log
* @param message message
* @param errorType error type, String
* @param state program running state
* @param dateline occurrence time, nanoseconds (optional)
* @param property additional properties (optional)
*/
public void addError(String log, String message, long dateline, String errorType,
AppState state, HashMap<String, Object> property)
/**
* Add error information
*
* @param log log
* @param message message
* @param errorType error type, ErrorType
* @param state program running state
* @param dateline occurrence time, nanoseconds (optional)
* @param property additional properties (optional)
*/
fun addError(log: String, message: String, dateline: Long, errorType: ErrorType,state: AppState, property: HashMap<String, Any>)
/**
* Add error information
*
* @param log log
* @param message message
* @param errorType error type, String
* @param state program running state
* @param dateline occurrence time, nanoseconds (optional)
* @param property additional properties (optional)
*/
fun addError(log: String, message: String, dateline: Long, errorType: String,state: AppState, property: HashMap<String, Any>)
Code Example¶
// Scenario 1:
FTRUMGlobalManager.get().addError("error log", "error msg", ErrorType.JAVA, AppState.RUN);
// Scenario 2: Delay recording the occurred error, the time here is generally the time the error occurred
FTRUMGlobalManager.get().addError("error log", "error msg", 16789000000000000000L, ErrorType.JAVA, AppState.RUN);
// Scenario 3:Dynamic parameters
HashMap<String, Object> map = new HashMap<>();
map.put("ft_key", "ft_value");
FTRUMGlobalManager.get().addError("error log", "error msg", ErrorType.JAVA, AppState.RUN, map);
// Scenario 1:
FTRUMGlobalManager.get().addError("error log", "error msg", ErrorType.JAVA, AppState.RUN)
// Scenario 2: Delay recording the occurred error, the time here is generally the time the error occurred
FTRUMGlobalManager.get().addError("error log", "error msg", 16789000000000000000, ErrorType.JAVA, AppState.RUN)
// Scenario 3:Dynamic parameters
val map = HashMap<String, Any>()
map["ft_key"] = "ft_value"
FTRUMGlobalManager.get().addError("error log", "error msg",ErrorType.JAVA,AppState.RUN,map)
LongTask¶
Usage¶
Code Example¶
Resource¶
Usage¶
/**
* resource start
*
* @param resourceId resource Id
* @param property additional property parameters (optional)
*/
public void startResource(String resourceId, HashMap<String, Object> property)
/**
* resource end
*
* @param resourceId resource Id
* @param property additional property parameters (optional)
*/
public void stopResource(final String resourceId, HashMap<String, Object> property)
/**
* Set network transmission content
*
* @param resourceId
* @param params
* @param netStatusBean
*/
public void addResource(String resourceId, ResourceParams params, NetStatusBean netStatusBean)
/**
* resource start
*
* @param resourceId resource Id (optional)
*/
fun startResource(resourceId: String, property: HashMap<String, Any>)
/**
* resource end
*
* @param resourceId resource Id
* @param property additional property parameters (optional)
*/
fun stopResource(resourceId: String, property: HashMap<String, Any>)
/**
* Set network transmission content
*
* @param resourceId
* @param params
* @param netStatusBean
*/
fun addResource(resourceId: String, params: ResourceParams, netStatusBean: NetStatusBean)
Code Example¶
// Scenario 1
// Request start
FTRUMGlobalManager.get().startResource("resourceId");
//...
// Request end
FTRUMGlobalManager.get().stopResource("resourceId");
// Finally, after the request ends, send the request-related data metrics
ResourceParams params = new ResourceParams();
params.setUrl("https://truewatch.com");
params.setResponseContentType(response.header("Content-Type"));
params.setResponseConnection(response.header("Connection"));
params.setResponseContentEncoding(response.header("Content-Encoding"));
params.setResponseHeader(response.headers().toString());
params.setRequestHeader(request.headers().toString());
params.setResourceStatus(response.code());
params.setResourceMethod(request.method());
NetStatusBean bean = new NetStatusBean();
bean.setTcpStartTime(60000000);
//...
FTRUMGlobalManager.get().addResource("resourceId", params, bean);
// Scenario 2 :Dynamic parameters usage
HashMap<String, Object> map = new HashMap<>();
map.put("ft_key", "ft_value");
map.put("ft_key_will_change", "ft_value");
FTRUMGlobalManager.get().startResource("resourceId",map);
//...
HashMap<String, Object> map = new HashMap<>();
map.put("ft_key_will_change", "ft_value_change"); //ft_key_will_change this value will be modified to ft_value_change when stopResource
FTRUMGlobalManager.get().stopResource(uuid,map);
// Scenario 1
//Request start
FTRUMGlobalManager.get().startResource("resourceId")
//Request end
FTRUMGlobalManager.get().stopResource("resourceId")
//Finally, after the request ends, send the request-related data metrics
val params = ResourceParams()
params.url = "https://truewatch.com"
params.responseContentType = response.header("Content-Type")
arams.responseConnection = response.header("Connection")
params.responseContentEncoding = response.header("Content-Encoding")
params.responseHeader = response.headers.toString()
params.requestHeader = request.headers.toString()
params.resourceStatus = response.code
params.resourceMethod = request.method
val bean = NetStatusBean()
bean.tcpStartTime = 60000000
//...
FTRUMGlobalManager.get().addResource("resourceId",params,bean)
// Scenario 2 :Dynamic parameters usage
val map = hashMapOf<String, Any>(
"ft_key" to "ft_value",
"ft_key_will_change" to "ft_value"
)
FTRUMGlobalManager.get().startResource("resourceId", map)
//...
val map = hashMapOf<String, Any>(
"ft_key_will_change" to "ft_value_change"
)
// ft_key_will_change this value will be modified to ft_value_change when stopResource
FTRUMGlobalManager.get().stopResource(uuid, map)
Method Name | Required | Meaning | Description |
---|---|---|---|
NetStatusBean.fetchStartTime | No | Request start time | |
NetStatusBean.tcpStartTime | No | tcp connection time | |
NetStatusBean.tcpEndTime | No | tcp end time | |
NetStatusBean.dnsStartTime | No | dns start time | |
NetStatusBean.dnsEndTime | No | dns end time | |
NetStatusBean.responseStartTime | No | Response start time | |
NetStatusBean.responseEndTime | No | Response end time | |
NetStatusBean.sslStartTime | No | ssl start time | |
NetStatusBean.sslEndTime | No | ssl end time | |
NetStatusBean.property | No | Additional properties | |
ResourceParams.url | Yes | url address | |
ResourceParams.requestHeader | No | Request header parameters | |
ResourceParams.responseHeader | No | Response header parameters | |
ResourceParams.responseConnection | No | Response connection | |
ResourceParams.responseContentType | No | Response ContentType | |
ResourceParams.responseContentEncoding | No | Response ContentEncoding | |
ResourceParams.resourceMethod | No | Request method | GET,POST etc. |
ResourceParams.responseBody | No | Return body content | |
ResourceParams.property | No | Additional properties |
Logger Log Printing¶
Use FTLogger
for custom log output, requires enabling FTLoggerConfig.setEnableCustomLog(true)
.
Currently, the log content is limited to 30 KB, characters beyond this limit will be truncated.
Usage¶
/**
* Store a single log data locally and sync
*
* @param content log content
* @param status log level, enum Status
* @param property additional properties (optional)
*/
public void logBackground(String content, Status status, HashMap<String, Object> property)
/**
* Store a single log data locally and sync
*
* @param content log content
* @param status log level, String
* @param property additional properties (optional)
*/
public void logBackground(String content, String status, HashMap<String, Object> property)
/**
* Store multiple log data locally and sync
*
* @param logDataList {@link LogData} list
*/
public void logBackground(List<LogData> logDataList)
/**
* Store a single log data locally and sync
*
* @param content log content
* @param status log level
* @param property log properties (optional)
*/
fun logBackground(content: String, status: Status, property: HashMap<String, Any>)
/**
* Store a single log data locally and sync
*
* @param content log content
* @param status log level
* @param property log properties (optional)
*/
fun logBackground(content: String, status: String, property: HashMap<String, Any>)
/**
* Store multiple log data locally and sync
*
* @param logDataList log data list
*/
fun logBackground(logDataList: List<LogData>)
Log Levels¶
Method Name | Meaning |
---|---|
Status.DEBUG | Debug |
Status.INFO | Info |
Status.WARNING | Warning |
Status.ERROR | Error |
Status.CRITICAL | Critical |
Status.OK | Recovery |
Code Example¶
// Upload a single log
FTLogger.getInstance().logBackground("test", Status.INFO);
// Pass parameters to HashMap
HashMap<String, Object> map = new HashMap<>();
map.put("ft_key", "ft_value");
FTLogger.getInstance().logBackground("test", Status.INFO, map);
// Batch upload logs
List<LogData> logList = new ArrayList<>();
logList.add(new LogData("test", Status.INFO));
FTLogger.getInstance().logBackground(logList);
//Upload a single log
FTLogger.getInstance().logBackground("test", Status.INFO)
//Pass parameters to HashMap
val map = HashMap<String,Any>()
map["ft_key"]="ft_value"
FTLogger.getInstance().logBackground("test", Status.INFO,map)
//Batch upload logs
FTLogger.getInstance().logBackground(mutableListOf(LogData("test",Status.INFO)))
Tracer Network Trace¶
FTTraceConfig
configuration enables enableAutoTrace
to automatically add trace data, or manually use FTTraceManager
to add Propagation Header
in Http requests, examples are as follows:
String url = "https://request.url";
String uuid = "uuid";
// Get trace header parameters
Map<String, String> headers = FTTraceManager.get().getTraceHeader(uuid, url);
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(chain -> {
Request original = chain.request();
Request.Builder requestBuilder = original.newBuilder();
// Add trace header parameters in the request
for (String key : headers.keySet()) {
requestBuilder.header(key, headers.get(key));
}
Request request = requestBuilder.build();
Response response = chain.proceed(request);
if (response != null) {
Map<String, String> requestHeaderMap = new HashMap<>();
Map<String, String> responseHeaderMap = new HashMap<>();
for (Pair<String, String> header : response.request().headers()) {
requestHeaderMap.put(header.first, header.second);
}
for (Pair<String, String> header : response.headers()) {
responseHeaderMap.put(header.first, header.second);
}
}
return response;
}).build();
Request.Builder builder = new Request.Builder().url(url).method(RequestMethod.GET.name(), null);
client.newCall(builder.build()).execute();
val url = "https://request.url"
val uuid ="uuid"
//Get trace header parameters
val headers = FTTraceManager.get().getTraceHeader(uuid, url)
val client: OkHttpClient = OkHttpClient.Builder().addInterceptor { chain ->
val original = chain.request()
val requestBuilder = original.newBuilder()
//Add trace header parameters in the request
for (key in headers.keys) {
requestBuilder.header(key!!, headers[key]!!)
}
val request = requestBuilder.build()
response = chain.proceed(request)
if (response != null) {
val requestHeaderMap = HashMap<String, String>()
val responseHeaderMap = HashMap<String, String>()
request.headers.forEach {
requestHeaderMap[it.first] = it.second
}
response!!.headers.forEach {
responseHeaderMap[it.first] = it.second
}
}
response!!
}.build()
val builder: Request.Builder = Request.Builder().url(url).method(RequestMethod.GET.name, null)
client.newCall(builder.build()).execute()
Custom Resource and TraceHeader via OKHttp Interceptor¶
When FTRUMConfig
's enableTraceUserResource
and FTTraceConfig
's enableAutoTrace
are both enabled, custom Interceptor
configurations will be loaded first.
ft-sdk < 1.4.1, need to disable
FTRUMConfig
'senableTraceUserResource
andFTTraceConfig
'senableAutoTrace
. ft-sdk > 1.6.7 supports custom Trace Header association with RUM data
new OkHttpClient.Builder()
.addInterceptor(new FTTraceInterceptor(new FTTraceInterceptor.HeaderHandler() {
@Override
public HashMap<String, String> getTraceHeader(Request request) {
HashMap<String, String> map = new HashMap<>();
map.put("custom_header","custom_value");
return map;
}
// Supported in versions 1.6.7 and above
@Override
public String getSpanID() {
return "span_id";
}
// Supported in versions 1.6.7 and above
@Override
public String getTraceID() {
return "trace_id";
}
}))
.addInterceptor(new FTResourceInterceptor(new FTResourceInterceptor.ContentHandlerHelper() {
@Override
public void onRequest(Request request, HashMap<String, Object> extraData) {
String contentType = request.header("Content-Type");
extraData.put("df_request_header", request.headers().toString());
if ("application/json".equals(contentType) ||
"application/x-www-form-urlencoded".equals(contentType) ||
"application/xml".equals(contentType)) {
extraData.put("df_request_body", request.body());
@Override
public void onResponse(Response response, HashMap<String, Object> extraData) throws IOException {
String contentType = response.header("Content-Type");
extraData.put("df_response_header", response.headers().toString());
if ("application/json".equals(contentType) ||
"application/xml".equals(contentType)) {
//copy part of the body to read, avoid consuming large data
ResponseBody body = response.peekBody(33554432);
extraData.put("df_response_body", body.string());
}
@Override
public void onException(Exception e, HashMap<String, Object> extraData)
}
}))
.eventListenerFactory(new FTResourceEventListener.FTFactory())
.build();
OkHttpClient.Builder()
.addInterceptor(FTTraceInterceptor(object : FTTraceInterceptor.HeaderHandler {
override fun getTraceHeader(request: Request): HashMap<String, String> {
val map = HashMap<String, String>()
map["custom_header"] = "custom_value"
return map
}
}))
.addInterceptor(FTResourceInterceptor(object : FTResourceInterceptor.ContentHandlerHelper {
override fun onRequest(request: Request, extraData: HashMap<String, Any>) {
val contentType = request.header("Content-Type")
extraData["df_request_header"] = request.headers().toString()
if ("application/json" == contentType ||
"application/x-www-form-urlencoded" == contentType ||
"application/xml" == contentType) {
extraData["df_request_body"] = request.body()
}
}
override fun onResponse(response: Response, extraData: HashMap<String, Any>) {
val contentType = response.header("Content-Type")
extraData["df_response_header"] = response.headers().toString()
if ("application/json" == contentType ||
"application/xml" == contentType) {
// Copy part of the response body to avoid consuming large data
val body = response.peekBody(33554432)
extraData["df_response_body"] = body.string()
}
}
override fun onException(e: Exception, extraData: HashMap<String, Any>) {
// Handle exception cases
}
}))
.eventListenerFactory(FTResourceEventListener.FTFactory())
.build()
ContentHandlerHelperEx Local Network Error Filtering¶
ContentHandlerHelperEx is an enhancement on ContentHandlerHelper, allowing filtering of local network IOException errors.
new FTResourceInterceptor.ContentHandlerHelperEx() {
//...
/**
* Returns exceptions during network connection
*
* @param e IOException data that occurred during the request
* @param extraData additional data
* @return Whether to filter local network network_error type errors. true, to override
*/
@Override
public boolean onExceptionWithFilter(Exception e, HashMap<String, Object> extraData) {
if (e instanceof SocketTimeoutException) { //Network timeout
return true;
}
return super.onExceptionWithFilter(e, extraData);
}
}
object : FTResourceInterceptor.ContentHandlerHelperEx() {
//...
/**
* Returns exceptions during network connection
*
* @param e IOException data that occurred during the request
* @param extraData additional data
* @return Whether to filter local network network_error type errors. true, to override
*/
override fun onExceptionWithFilter(e: Exception, extraData: HashMap<String, Any>): Boolean {
return if (e is SocketTimeoutException) {
true
} else {
super.onExceptionWithFilter(e, extraData)
}
}
}
OKhttp Add ResourceID¶
Add uuid to Okhttp Request, recommended to enable if there are high-frequency concurrent scenarios with the same request. ft-plugin 1.3.5 and above, ft-sdk 1.6.10 and above, enabling FTSDKConfig.setEnableOkhttpRequestTag(true)
can automatically add ResourceID
to Request
User Information Binding and Unbinding¶
Use FTSdk
for user information binding and unbinding
Usage¶
UserData¶
Method Name | Meaning | Required | Note |
---|---|---|---|
setId | Set user ID | No | |
setName | Set username | No | |
setEmail | Set email | No | |
setExts | Set user extensions | No | For adding rules see here |
Code Example¶
// Can be called after user login to bind user information
FTSdk.bindRumUserData("001");
UserData userData = new UserData();
userData.setName("test.user");
userData.setId("test.id");
userData.setEmail("[email protected]");
Map<String, String> extMap = new HashMap<>();
extMap.put("ft_key", "ft_value");
userData.setExts(extMap);
FTSdk.bindRumUserData(userData);
// Can be called after user logout to unbind user information
FTSdk.unbindRumUserData();
//Can be called after user login to bind user information
FTSdk.bindRumUserData("001")
//Bind more user data
val userData = UserData()
userData.name = "test.user"
userData.id = "test.id"
userData("[email protected]")
val extMap = HashMap<String, String>()
extMap["ft_key"] = "ft_value"
userData.setExts(extMap)
FTSdk.bindRumUserData(userData)
//Can be called after user logout to unbind user information
FTSdk.unbindRumUserData()
Shut Down SDK¶
Use FTSdk
to shut down the SDK, if dynamically changing SDK configuration, need to shut down first to avoid generating incorrect data
Clear SDK Cache Data¶
Use FTSdk
to clear unreported cache data
Active Data Sync¶
Use FTSdk
to actively sync data.
FTSdk.setAutoSync(false) when, need to manually sync data
Active Dynamic Configuration Sync¶
Use FTSdk
to actively sync dynamic configuration. When automatic updates do not meet requirements, adjust the update timing by actively calling.
/**
* Actively update remote remote configuration, call frequency affected by FTSDKConfig.setRemoteConfigMiniUpdateInterval
*/
FTSdk.updateRemoteConfig();
/**
* Actively update remote remote configuration, this method ignores FTSDKConfig.setRemoteConfigMiniUpdateInterva configuration
*
* @param remoteConfigMiniUpdateInterval remote configuration time interval, unit seconds [0,)
* @param result returns update result
*/
FTSdk.updateRemoteConfig(int remoteConfigMiniUpdateInterval, FTRemoteConfigManager.FetchResult result);
/**
* Actively update remote remote configuration, call frequency affected by FTSDKConfig.setRemoteConfigMiniUpdateInterval
*/
FTSdk.updateRemoteConfig()
/**
* Actively update remote remote configuration, this method ignores FTSDKConfig.setRemoteConfigMiniUpdateInterva configuration
*
* @param remoteConfigMiniUpdateInterval remote configuration time interval, unit seconds [0,)
* @param result returns update result
*/
FTSdk.updateRemoteConfig(remoteConfigMiniUpdateInterval:Int,result:FTRemoteConfigManager.FetchResult)
Dynamic Enable and Disable AndroidID Access¶
Use FTSdk
to set whether to obtain Android ID in SDK
Add Custom Tags¶
Use FTSdk
to dynamically add tags during SDK runtime
Usage¶
/**
* Dynamically set global tag
* @param globalContext
*/
public static void appendGlobalContext(HashMap<String,Object> globalContext)
/**
* Dynamically set RUM global tag
* @param globalContext
*/
public static void appendRUMGlobalContext(HashMap<String,Object> globalContext)
/**
* Dynamically set log global tag
* @param globalContext
*/
public static void appendLogGlobalContext(HashMap<String,Object> globalContext)
/**
* Dynamically set global tag
* @param globalContext
*/
fun appendGlobalContext(globalContext: HashMap<String, Any>)
/**
* Dynamically set RUM global tag
* @param globalContext
*/
fun appendRUMGlobalContext(globalContext: HashMap<String, Any>)
/**
* Dynamically set log global tag
* @param globalContext
*/
fun appendLogGlobalContext(globalContext: HashMap<String, Any>)
Code Example¶
HashMap<String, Object> globalContext = new HashMap<>();
globalContext.put("global_key", "global_value");
FTSdk.appendGlobalContext(globalContext);
HashMap<String, Object> rumGlobalContext = new HashMap<>();
rumGlobalContext.put("rum_key", "rum_value");
FTSdk.appendRUMGlobalContext(rumGlobalContext);
HashMap<String, Object> logGlobalContext = new HashMap<>();
logGlobalContext.put("log_key", "log_value");
FTSdk.appendLogGlobalContext(logGlobalContext);
val globalContext = hashMapOf<String, Any>(
"global_key" to "global_value"
)
FTSdk.appendGlobalContext(globalContext)
val rumGlobalContext = hashMapOf<String, Any>(
"rum_key" to "rum_value"
)
FTSdk.appendRUMGlobalContext(rumGlobalContext)
val logGlobalContext = hashMapOf<String, Any>(
"log_key" to "log_value"
)
FTSdk.appendLogGlobalContext(logGlobalContext)
Symbol File Upload¶
plugin Upload (Only supports datakit【Local Deployment】)¶
ft-plugin
version needs 1.3.0
and above to support the latest symbol file upload rules, supports productFlavor
multi-version management, plugin will execute symbol file upload after gradle task assembleRelease
, detailed configuration can refer to SDK Demo
FTExt {
//...
autoUploadMap = true // Upload mapping.txt file, default is false
autoUploadNativeDebugSymbol = true // Upload c/c++ symbol so file, default is false
datakitUrl = 'https://datakit.url' // datakit upload address, generateSourceMapOnly=true when, no need to configure
datawayToken = 'dataway_token' // Space token, generateSourceMapOnly=true when, no need to configure
appId = "appid_xxxxx" // appid, generateSourceMapOnly=true when, no need to configure
env = 'common' // Environment, generateSourceMapOnly=true when, no need to configure
// native so specified path, only need to specify to the upper directory of the abi file
// |-stripped_native_libs
// |-release
// |-out
// |-lib
// |-arm64-v8a
// |-armeabi-v7a
// |-...
//nativeLibPath='/build/intermediates/merged_native_libs/release/out/lib'
generateSourceMapOnly = false //Only generate sourcemap, default is false, path example: /app/build/tmp/ft{flavor}SourceMapMerge-release.zip, ft-plugin:1.3.4 and above support
prodFlavors { //prodFlavors configuration will override outer settings
prodTest {
autoUploadMap = false
autoUploadNativeDebugSymbol = false
datakitUrl = 'https://datakit.url'
datawayToken = 'dataway_token'
appId = "appid_prodTest"
env = "gray"
}
prodPublish {
autoUploadMap = true
autoUploadNativeDebugSymbol = true
datakitUrl = 'https://datakit.url'
datawayToken = 'dataway_token'
appId = "appid_prodPublish"
env = "prod"
}
}
}
Manual Upload¶
Use plugin
to enable generateSourceMapOnly = true
, execute gradle task assembleRelease
to generate, or manually package into zip
file, then manually upload to datakit
or upload from TrueWatch Studio, recommend using zip
command line for packaging, avoid packing system hidden files into zip
package, symbol upload please refer to sourcemap upload
Unity Native Symbol files please refer to official documentation
Permission Configuration Description¶
Name | Required | Usage Reason |
---|---|---|
READ_PHONE_STATE |
No | Used to obtain mobile cellular network device information |
For how to apply for dynamic permissions, please refer to Android Developer
Plugin AOP Ignore¶
Add @IngoreAOP
in methods covered by Plugin AOP to ignore ASM insertion. If batch ignore is needed, please use ft-plugin
FTExt
ignorePackages
for ignore.
WebView Data Monitoring¶
WebView data monitoring requires integrating Web Monitoring SDK in the WebView access page.
Data Masking¶
If you want to fully mask a field, it is recommended to use setDataModifier
, which performs better. If you need detailed rule replacement, it is recommended to use setLineDataModifier
Do not use complex or high-latency methods in the callback method, as this will greatly affect SDK data writing performance
FTSdk.install(
FTSDKConfig.builder("xxx")
.setDataModifier(new DataModifier() {
/**
* Modify a field
*
* @param key field name
* @param value field value (original value)
* @return new value, return null to indicate no change
*/
@Override
public Object modify(String key, Object value) {
if (key.equals("device_uuid")) {
return "xxx";
}
return null;
}
}).setLineDataModifier(new LineDataModifier() {
/***
* Modify a line of data
*
* @param measurement data metric type view, action, resource,
* longtask, error, df_rum_android_log
* @param data original data key-value pairs
* @return key-value pairs that need to be modified, (return null or empty map means no change)
*/
@Override
public Map<String, Object> modify(String measurement, HashMap<String, Object> data) {
if(measurement.equals("view")){
HashMap<String,Object> changeMap = new HashMap<String,Object>();
changeMap.put("view_url", "xxx");
}
return null;
}
})
FTSdk.install(
FTSDKConfig.builder("xxx")
.setDataModifier(object : DataModifier {
/**
* Modify a field
*
* @param key field name
* @param value field value (original value)
* @return new value, return null to indicate no change
*/
override fun modify(key: String, value: Any?): Any? {
return if (key == "device_uuid") {
"xxx" // Replace with custom device_uuid
} else {
null
}
}
})
// Batch modify certain fields in a single line of data
.setLineDataModifier(object : LineDataModifier {
/**
* Modify a line of data
*
* @param measurement data metric type view, action, resource,
* longtask, error, df_rum_android_log
* @param data original data key-value pairs
* @return key-value pairs that need to be modified, (return null or empty map means no change)
*/
override fun modify(
measurement: String,
data: HashMap<String, Any>
): Map<String, Any>? {
return if (measurement == "view") {
hashMapOf("view_url" to "xxx")
} else {
null
}
}
})
Custom Tag Usage Example¶
Compilation Configuration Method¶
- Create multiple
productFlavors
inbuild.gradle
to distinguish tags
android{
//…
productFlavors {
prodTest {
buildConfigField "String", "CUSTOM_VALUE", "\"Custom Test Value\""
//…
}
prodPublish {
buildConfigField "String", "CUSTOM_VALUE", "\"Custom Publish Value\""
//…
}
}
}
- Add corresponding
BuildConfig
constants inRUM
configuration
Runtime File Read-Write Method¶
- Store file type data, such as
SharedPreferences
, configure usingSDK
, add code to obtain tag data at the configuration.
SharedPreferences sp = context.getSharedPreferences(SP_STORE_DATA, MODE_PRIVATE);
String customDynamicValue = sp.getString(CUSTOM_DYNAMIC_TAG, "not set");
// Configure RUM
FTSdk.initRUMWithConfig(
new FTRUMConfig().addGlobalContext(CUSTOM_DYNAMIC_TAG, customDynamicValue)
//… add other configurations
);
- Add methods to change file data anywhere.
- Finally, restart the application. For detailed details, see SDK Demo
Add at SDK Runtime¶
After the SDK initialization is complete, use FTSdk.appendGlobalContext(globalContext)
, FTSdk.appendRUMGlobalContext(globalContext)
, FTSdk.appendLogGlobalContext(globalContext)
to dynamically add tags. After setting, it will take effect immediately. Subsequently, RUM or Log subsequent reported data will automatically add tag data. This usage is suitable for scenarios where data acquisition is delayed, such as when tag data needs to be obtained through network requests.
//SDK initialization pseudo code, get parameters from the network, then set tags
FTSdk.init()
getInfoFromNet(info){
HashMap<String, Object> globalContext = new HashMap<>();
globalContext.put("delay_key", info.value);
FTSdk.appendGlobalContext(globalContext)
}
FAQ¶
Avoid Conflict Fields with Global Variables¶
To avoid conflicts between custom fields and SDK data, it is recommended to add a project abbreviation prefix to the tag name, such as df_tag_name
. The key
value used in the project can be queried in the source code. When the same variable appears in the SDK global variable and RUM, Log, RUM, Log will overwrite the global variable in the SDK.
SDK Compatibility¶
Coping with Market Privacy Audits¶
Privacy Statement¶
Method 1: SDK AndroidID Configuration¶
The SDK uses Android ID to better associate data from the same user. If you need to publish the application on the market, you need to cope with market privacy audits in the following ways.
public class DemoApplication extends Application {
@Override
public void onCreate() {
// Set setEnableAccessAndroidID to false during initialization
FTSDKConfig config = new FTSDKConfig.Builder(DATAKIT_URL)
.setEnableAccessAndroidID(false)
.build();
FTSdk.install(config);
// ...
}
}
// Enable after user agrees to privacy policy
FTSdk.setEnableAccessAndroidID(true);
class DemoApplication : Application() {
override fun onCreate() {
//Set setEnableAccessAndroidID to false during initialization
val config = FTSDKConfig
.builder(DATAKIT_URL)
. setEnableAccessAndroidID(false)
FTSdk.install(config)
//...
}
}
//Enable after user agrees to privacy policy
FTSdk.setEnableAccessAndroidID(true);
Method 2: Delay SDK Initialization¶
If you need to delay loading the SDK in the application, it is recommended to initialize in the following way.
// Application
public class DemoApplication extends Application {
@Override
public void onCreate() {
//If the agreement has been agreed, initialize in Application
if(agreeProtocol){
FTSdk.init(); //SDK initialization pseudo code
}
}
}
// Privacy Statement Activity Page
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
//Privacy statement not read
if ( notReadProtocol ) {
//Privacy statement popup
showProtocolView();
//If the privacy statement is agreed
if( agreeProtocol ){
FTSdk.init(); //SDK initialization pseudo code
}
}
}
}
// Application
class DemoApplication : Application() {
override fun onCreate() {
// If the agreement has been agreed, initialize in Application
if (agreeProtocol) {
FTSdk.init() //SDK initialization pseudo code
}
}
}
// Privacy Statement Activity Page
class MainActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
// Privacy statement not read
if (notReadProtocol) {
// Privacy statement popup
showProtocolView()
// If the privacy statement is agreed
if (agreeProtocol) {
FTSdk.init() //SDK initialization pseudo code
}
}
}
}
Third-Party Frameworks¶
flutter
, react-native
, uni-app
, unity
can adopt similar delayed initialization methods as native Android to cope with market privacy audits.
Jetpack Compose Support¶
Currently, automatic collection of compose component-generated pages is not supported, but you can manually track click events and page navigation events through custom interfaces for Action
and View
, refer to here
How to Integrate SDK Without Using ft-plugin¶
TrueWatch uses Androig Grale Plugin Transformation to implement code injection, thereby achieving automatic data collection. However, due to some compatibility issues, there may be situations where ft-plugin
or ft-plugin-legacy
cannot be used. Affected include RUM Action
, Resource
, and android.util.Log
, Java and Kotlin println
console log automatic capture, and symbol file automatic upload.
Currently, for this situation, we have another integration solution, the response plan is as follows:
- Application startup event, source code example reference DemoForManualSet.kt
- Button and other events need to be added manually at the trigger, for example, Button onClick event, source code example reference ManualActivity.kt:
OKhttp
throughaddInterceptor
,eventListener
method to integrateResource
,Trace
, examples are as follows, source code example reference ManualActivity.kt:
OkHttpClient.Builder builder = new OkHttpClient.Builder()
.addInterceptor(new FTTraceInterceptor())
.addInterceptor(new FTResourceInterceptor())
.eventListenerFactory(new FTResourceEventListener.FTFactory());
//.eventListenerFactory(new FTResourceEventListener.FTFactory(true));
OkHttpClient client = builder.build();
-
Other network frameworks need to manually implement using
FTRUMGlobalManager
startResource
,stopResource
,addResource
,FTTraceManager.getTraceHeader
. For specific implementation methods, please refer to the source code example ManualActivity.kt -
WebView data collection configuration