本文介紹如何接入iOS使用者體驗監控資料到全棧可觀測應用。
前提條件
已建立全棧可觀測執行個體(推薦)或Trace執行個體。具體操作,請參見建立全棧可觀測執行個體、建立Trace執行個體。
全棧可觀測執行個體需為2.1.0及以上版本。您可以在執行個體列表中查看版本資訊。
本文以全棧可觀測應用為例,即下文中的執行個體均為全棧可觀測執行個體。
步驟一:SDK整合
在專案檔夾中,建立Podfile檔案,並在Podfile中配置以下內容。
#指定source。
source 'https://gitee.com/aliyun-sls/Specs.git'
# 引入以下Pods。
pod 'AliyunLogProducer', '4.0.0'
pod 'AliyunLogOTelCommon', '4.0.0'
pod 'AliyunLogOtlpExporter', '4.0.0'
pod 'AliyunLogCrashReporter', '4.0.0'
步驟二:初始化SDK
參考如下代碼,初始化SDK。
[ConfigurationManager.shared setProviderWithAccessKeyProvider:^AccessKey * _Nullable(NSString * _Nonnull scope) {
return [AccessKey initWithAccessKeyId:@"${access-key-id}"
accessKeySecret:@"${access-key-secret}"
accessKeySecuritToken:@"${access-key-token}"
];
} workspaceProvider:^Workspace * _Nullable(NSString * _Nonnull scope) {
return [Workspace initWithEndpoint:@"https://${endpoint}"
project:@"${project}"
instanceId:@"${instanceId}"
];
} environmentProvider:^Environment * _Nullable(NSString * _Nonnull scope) {
// 設定環境資訊。
return [Environment initWithEnv:@"default" // 預設為default。一般情況下,建議debug版本設定為dev,release版本設定為pub。
uid:@"123456780" // 設定使用者ID,可選。
utdid:@"" // 設定裝置ID,可選。傳入無效值時,SDK會自動產生utdid。
channel:@"" // 設定渠道資訊,可選。
];
}];
// 一般情況下,建議debug版本設定為YES,release版本設定為NO。
BOOL debuggable = NO;
[[CrashReporter shared] initWithDebuggable:debuggable];
變數說明
變數 | 說明 | 樣本 |
${endpoint} | Log ServiceProject的接入地址,格式為 | cn-hangzhou.log.aliyuncs.com |
${project} | Log ServiceProject名稱。 | test-project |
${instance} | 全棧可觀測服務執行個體ID。更多資訊,請參見建立執行個體。 | test-traces |
${access-key-id} | 阿里雲帳號AccessKey ID。 建議您使用只具備Log ServiceProject寫入許可權的RAM使用者的AccessKey(包括AccessKey ID和AccessKey Secret)。授予RAM使用者向指定Project寫入資料許可權的具體操作,請參見授權。如何擷取AccessKey的具體操作,請參見存取金鑰。 | 無 |
${access-key-secret} | 阿里雲帳號AccessKey Secret。 建議您使用只具備Log ServiceProject寫入許可權的RAM使用者的AccessKey。 | 無 |
${access-key-token} | 阿里雲帳號AccessKey Token。 僅當AccessKey是通過STS方式擷取時才需要。 |