Skip to content

SDK Initialization

This document covers the initialization, basic configuration, and runtime capabilities of the C++ SDK.

Include Header File

#include "datakit-sdk-cpp/FTSDKFactory.h"

Initialize the SDK

auto sdk = FTSDKFactory::get();
sdk->init();
Field Type Required Description
FTSDKFactory::get string No Specifies the configuration file, defaults to ft_sdk_config.json

Start JSON File Configuration

You can use FTSDKFactory to start SDK debug logging with a JSON file.

{
  "general_config": {
    "enable_sdk_log": true
  }
}

enable_sdk_log is used to enable debug logging, which is off by default.

Basic Configuration

FTSDKConfig gc;
gc.setServerUrl("http://10.0.0.1:9529")
  .setEnv(EnvType::PROD)
  .addGlobalContext("custom_key", "custom_value")
  .setEnableFileDBCache(true);
sdk->install(gc);
Field Type Required Description
setServerUrl string Yes DataKit access URL, e.g., http://10.0.0.1:9529, default port is 9529. The device where the SDK is installed must be able to access this address.
setEnv enum No Environment configuration, default is EnvType::PROD
setAppVersion string No Automatically retrieved on Windows, needs to be set manually on Linux
setEnableFileDBCache bool No Whether to enable local database caching, defaults to false
addGlobalContext dictionary No Add SDK global attributes. Please read Custom Tags and Conflict Field Description for rules.
setServiceName string No Affects the service field data in Log and RUM. Defaults to df_rum_windows on Windows and df_rum_linux on Linux.

User Information Binding and Unbinding

/**
 * Bind user data
 *
 * @param config User data
 */
FTSDK&& bindUserData(UserData& config);

/**
 * Unbind user data
 */
void unbindUserData();

Example:

UserData uc;
uc.init("username", "1001", "[email protected]");
uc.addCustomizeItem("ft_key", "ft_value");
sdk->bindUserData(uc);

sdk->unbindUserData();

It is recommended that field names for addCustomizeItem also follow the Conflict Field Description.

Runtime Capabilities

Shut Down the SDK

sdk->deinit();

Calling deinit() will perform resource cleanup operations. If the application process still needs to continue collection, please reinitialize and configure.