tencent cloud

Tencent Cloud Observability Platform

SDK Initialization

Download
Focus Mode
Font Size
Last updated: 2026-05-25 18:01:58
This article describes how to initialize the Terminal Performance Monitoring Pro (RUM Pro) log SDK.

Configuring and Starting the SDK

Since the log printing, KV storage, and file compression modules in the SDK are replaceable, you need to configure the corresponding dependencies before initializing the SDK.
1. The SDK manages module dependencies through TDIAGDepends. A TDIAGDepends instance requires instances that implement the following protocols: id<TDLoggingIMPProtocol>, id<RAFTKVStorageFactoryProtocol>, and id<TDLogFilePackerProtocol>. For example:
#import <TDOS_Diagnose/TDOS_Diagnose.h> // Log SDK module

#import <TDOS_Diagnose/TDMMKVFactoryImpl.h> // MMKV module
#import <TDOS_Diagnose/TDOSLoggerProxy.h> // Log printing module
#import <TDOS_Diagnose/TDLogFilePackerImp.h> // File compression module


// Uses the SDK's default modules.
TDOSLoggerProxy *loggerProxy = [TDOSLoggerProxy defaultProxy];
TDMMKVFactory *kvFactory = [TDMMKVFactoryImpl sharedInstance];
TDLogFilePackerImp *filePacker = [[TDLogFilePackerImp alloc] init];

// Creates a TDIAGDepends instance.
TDIAGDepends *depends = [TDIAGDepends dependsWithLogImp:loggerProxy
kvFactoryImp:kvFactory
andFilePackerImp:filePacker];
In the above example, TDOSLoggerProxy, TDMMKVFactoryImpl, and TDLogFilePackerImp are default instances provided by the SDK that implement the corresponding protocols. After creating TDIAGDepends, you can proceed with SDK initialization.
2. Provide the AppID and AppKey. Here, use the AppID and AppKey provided during platform product registration.
// appid & appKey, generated by the platform
NSString *appID = BUGLY_APPID;
NSString *appKey = BUGLY_APPKEY;
3. You need to provide a dataSource object that conforms to the TDLogSDKDataSource protocol. This object supplies necessary data to the SDK. For details, refer to the definition in TDLogSDKDataSource. The - (NSString *)guidForTDLog; method must be implemented. This method returns a unique user ID, which is used when the platform issues commands.
// Creates a log retrieval module configuration instance and initializes it.
TDLogSDKConfig *config = [TDLogSDKConfig configWithAppId:appID
appKey:appKey
dataSource:self
depends:depends];
Note:
By default, the log module uses an internal domain. For RumPro users, you need to specify the corresponding domain type in TDLogSDKConfig:
/// Sets the service domain type.
@property (nonatomic,assign)TDLogServerHostType serverHostType;

/// Sets the reporting domain.
https://cloud.bugly.qq.com

/// Customizes the server domain.
@property(nonatomic,strong)NSString *customServerHost;
4. Based on your business requirements, you can configure frequency and traffic control policies to prevent excessive network resource consumption from frequent log reporting.
// Enables frequency control (default unlimited). Pass empty to use the SDK's default policy: 2 times/5min, or pass a custom policy. When restricted, the automatic reporting API callback will indicate failure.
// Example: Allow at most 3 reports within 10 minutes (using token bucket algorithm).
// TDLogFrequencyControlStrategy *strategy = [TDLogFrequencyControlStrategy new];
// strategy.times = 3;
// strategy.timeInterval = 10 * 60;
// Note: This API requires TDLogSDKDataSource to implement the whitelistForAutoUploadTags protocol, which provides an allowlist of tags for automatic reporting. This ensures that essential reports are not blocked.
[config setFrequencyLimitStatusForAutoUpload:YES
withCustomControlStrategy:nil]; // Recommended setting to prevent frequent automatic reporting
// Enables traffic control (default: unlimited). Pass 0 to disable reporting. Pass a negative value for no limit. When limited, the automatic reporting API callback will indicate failure.
// Note: This API requires TDLogSDKDataSource to implement the whitelistForAutoUploadTags protocol, which provides an allowlist of tags for automatic reporting. This ensures that essential reports are not blocked.
[config setTrafficQuota24hLimitForAutoUpload:(200 * 1024 * 1024)
xgQuota:(50 * 1024 * 1024)]; // Optional. Sets the traffic limit for automatic reporting.
5. Finally, call the corresponding method to start the SDK and complete the initialization process.
[[TDLogSDK sharedInstance] startWithConfig:config];

Configuring the Local Log Printing Module

TDOSLoggerProxy is a wrapper that implements the TDLoggingIMPProtocol interface provided by the TDOSLogger module in TDOS_Diagnose. To use the TDOSLogger module, you need to initialize it. The steps are as follows:
1. Initialize the log printing module.
// Initializes the log printing module.
TDOSLoggerConfig *loggerConfig = [TDOSLoggerConfig defaultConfig];
TDOSLogger *logger = [[TDOSLogger alloc] initWithConfig:loggerConfig];
2. Set the instantiated logger object to the TDOSLoggerProxy instance created earlier, so that the TDOSLogger module can function properly.
TDOSLoggerProxy *loggerProxy = [TDOSLoggerProxy defaultProxy];
[loggerProxy setLogger:logger];
Note:
For Extension project integration: This SDK supports iOS Extensions. If you are using the default MMKV dependency module, add the following script to your project's Podfile:
post_install do |installer|
installer.pods_project.targets.each do |target|
if target.name == "MMKV"
target.build_configurations.each do |config|
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'MMKV_IOS_EXTENSION']
end
end
end
end
For more features provided by TDOSLogger, see the API Description.

Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback