SDK配置項讓您能夠通過設定參數來滿足額外需求。本文介紹PC應用常用的SDK配置。
啟動配置
(必須)設定Config地址
每個應用都需要關聯對應的Config地址,該介面需要在調用alibabacloud_rum_init函數前設定。
void alibabacloud_rum_options_set_config_address(alibabacloud_rum_options_t *options, const char *config_address);參數 | 說明 | 參數限制 | 失敗結果 |
options | alibabacloud_rum_options_t | 非空,通過 | 介面調用失敗,SDK停止 |
config_address | const char* | 非空,由使用者體驗監控平台產生。 | 介面調用失敗,SDK停止 |
樣本:
alibabacloud_rum_options_set_config_address(options, RUM_CONFIG_ADDRESS);(必須)設定應用ID
每個應用都需要關聯對應的AppId,該介面需要在調用alibabacloud_rum_init函數前設定。
void alibabacloud_rum_options_set_app_id(alibabacloud_rum_options_t *options, const char *app_id)參數 | 說明 | 參數限制 | 失敗結果 |
app_id | 應用AppID | 由使用者體驗監控平台產生的應用唯一ID | 介面調用失敗,SDK停止 |
樣本:
alibabacloud_rum_options_set_app_id(options, RUM_CONFIG_APPID);(必須)設定應用程式名稱
設定應用程式名稱。該介面需要在調用alibabacloud_rum_init函數前設定。
void alibabacloud_rum_options_set_app_name(alibabacloud_rum_options_t *options, const char *app_name)參數 | 說明 | 參數限制 | 失敗結果 |
app_name | const char*, 應用程式名稱。 | 非空,字串長度大於0且小於128。 | 介面調用失敗,應用程式名稱設定不會生效。 |
樣本:
alibabacloud_rum_options_set_app_name(options, "WindowsDemo");(必須)設定應用版本號碼
SDK支援設定應用的版本號碼資訊。該介面需要在調用alibabacloud_rum_init函數前設定。
void alibabacloud_rum_options_set_app_version(alibabacloud_rum_options_t *options, const char *app_version)參數 | 說明 | 參數限制 | 失敗結果 |
app_version | const char* | 非空,字串長度大於0且小於64 | 介面調用失敗,應用版本號碼設定不會生效。 |
樣本:
alibabacloud_rum_options_set_app_version(options, "0.1.0-beta.2");(可選)設定應用環境
SDK支援設定應用的環境,包含:local、daily、pre、gray、prod。該介面需要在調用alibabacloud_rum_init函數前設定。
void alibabacloud_rum_options_set_env(alibabacloud_rum_options_t *options, alibabacloud_rum_env_t env)參數 | 說明 | 參數限制 | 失敗結果 |
env | 應用環境枚舉 | 以下枚舉值中指定:
| 介面調用失敗,應用環境設定不會生效。 |
樣本:
alibabacloud_rum_options_set_env(options, ALIBABACLOUD_RUM_ENV_LOCAL);(可選)設定裝置ID
應用可以按需設定裝置ID。SDK會預設產生裝置ID,並緩衝在本地檔案中。該介面需要在調用alibabacloud_rum_init函數前設定。
void alibabacloud_rum_options_set_utdid(alibabacloud_rum_options_t *options, const char *utdid)參數 | 說明 | 參數限制 | 失敗結果 |
utdid | const char*,裝置ID。 | 非空,字串長度大於0且小於37。 | 介面調用失敗,裝置ID設定不會生效。 |
樣本:
alibabacloud_rum_options_set_utdid(options, "b7028408-ddac-4a58-72a9-653f6637f0e6");(可選)設定日誌等級
SDK在運行時會輸出一定的日誌。在使用SDK中遇到問題時,通過調整SDK日誌等級可以輸出更豐富的資訊,用於排查定位。該介面需要在調用alibabacloud_rum_init函數前設定。
void alibabacloud_rum_options_set_debug_level(alibabacloud_rum_options_t *options, alibabacloud_rum_level_t level);參數 | 說明 | 參數限制 | 失敗結果 |
level | 日誌等級枚舉。 | 以下枚舉值中指定:
其中,ALIBABACLOUD_RUM_LEVEL_ALL 的日誌等級最高,此時日誌會寫入到快取檔案中。 | 介面調用失敗,日誌等級設定不會生效。 |
樣本:
alibabacloud_rum_options_set_debug_level(options, ALIBABACLOUD_RUM_LEVEL_DEBUG);(可選)設定緩衝目錄
SDK運行時會產生快取檔案,可以根據需要指定緩衝目錄。SDK預設會在可執行檔所在目錄建立名為 .alibabacloud-rum 的檔案夾。該介面需要在調用alibabacloud_rum_init函數前設定。
void alibabacloud_rum_options_set_cache_path(alibabacloud_rum_options_t *options, const char *path)參數 | 說明 | 參數限制 | 失敗結果 |
path | const char * | 非空。檔案目錄的長度可能會受系統限制。 | 介面調用失敗,緩衝目錄設定不會生效。 |
樣本:
alibabacloud_rum_options_set_cache_path(options, "/path/to/your/cache/");(可選)設定網路請求採集過濾器
SDK支援採集libcurl、CEF架構的網路請求資料。您可以通過配置網路請求採集過濾器來決定指定URL的採集行為。該介面需要在調用alibabacloud_rum_init函數前設定。
void alibabacloud_rum_options_set_network_options(alibabacloud_rum_options_t *options, alibabacloud_rum_network_options_t *network_options)參數 | 說明 | 參數限制 | 失敗結果 |
network_options | 網路請求過濾器結構體。 | 非空,且需要滿足以下結構體的定義: | 介面調用失敗,網路請求採集過濾器設定不會生效。 |
樣本:
// 過濾指定URL是否允許採集。
// 該函數返回 0 時,表示不採集;返回非 0 時,表示採集。
int ALIBABACLOUD_RUM_CALLBACK example_should_record_request(const char *url)
{
LOG("example", "example_should_record_request, url: %s", url);
return 1;
}
// 過濾指定URL是否允許端到端打通。
// 該函數返回 0 時,表示允許;返回非 0 時,表示不允許。
int ALIBABACLOUD_RUM_CALLBACK example_should_tracing(const char *url)
{
LOG("example", "example_should_tracing, url: %s", url);
return NULL != strstr(url, "/api/data");
}
// 注意:SDK會預設配置network_options。預設情況下,會採集所有URL請求資料,且所有URL不允許端到端打通。
alibabacloud_rum_network_options_t *network_options = alibabacloud_rum_network_options_new();
network_options->should_tracing = example_should_tracing;
network_options->should_record_request = example_should_record_request;
alibabacloud_rum_options_set_network_options(options, network_options);(可選)開啟/關閉libcurl網路請求採集模組
SDK支援配置是否開啟libcurl網路請求模組。預設開啟libcurl網路請求模組。該介面需要在調用alibabacloud_rum_init函數前設定。
void alibabacloud_rum_options_set_auto_curl_tracking(alibabacloud_rum_options_t *options, int enabled)參數 | 說明 | 參數限制 | 失敗結果 |
enabled | int | 0, 關閉;1,開啟。 | 介面調用失敗,libcurl網路請求模組設定不會生效。 |
樣本:
// 開啟libcurl網路請求採集模組
alibabacloud_rum_options_set_auto_curl_tracking(options, 1);注意:開啟libcurl網路請求採集模組之前,您需要先整合libcurl庫。當前僅支援libcurl動態庫資料的採集。
(可選)開啟/關閉崩潰採集模組
SDK支援配置是否開啟崩潰資料擷取模組。預設開啟崩潰資料擷取模組。該介面需要在調用alibabacloud_rum_init函數前設定。
void alibabacloud_rum_options_set_auto_crash_tracking(alibabacloud_rum_options_t *options, int enabled)參數 | 說明 | 參數限制 | 失敗結果 |
enabled | int | 0, 關閉;1,開啟。 | 介面調用失敗,崩潰資料擷取模組設定不會生效。 |
樣本:
// 開啟崩潰資料擷取模組
alibabacloud_rum_options_set_auto_crash_tracking(options, 1);(可選)開啟/關閉CEF架構資料擷取模組
SDK支援配置是否開啟CEF架構資料擷取模組。預設關閉CEF架構資料擷取模組。該介面需要在調用alibabacloud_rum_init函數前設定。
void alibabacloud_rum_options_set_auto_cef_tracking(alibabacloud_rum_options_t *options, int enabled)參數 | 說明 | 參數限制 | 失敗結果 |
enabled | int | 0, 關閉;1,開啟。 | 介面調用失敗,CEF架構資料擷取模組設定不會生效。 |
樣本:
// 開啟CEF架構資料擷取模組
alibabacloud_rum_options_set_auto_cef_tracking(options, 1);注意:開啟CEF架構資料擷取模組之前,您需要先整合CEF庫。當前僅支援CEF動態庫資料的採集。
(必須)啟動SDK
通過 alibabacloud_rum_init 函數可以完成SDK的初始化。
int alibabacloud_rum_init(alibabacloud_rum_options_t *options)參數 | 說明 | 參數限制 | 失敗結果 |
options | SDK配置項 | 非空,且必要參數都已設定 | 介面調用失敗,SDK停止 |
(必須)關閉SDK
通過 alibabacloud_rum_close 函數可以完成SDK的關閉。
int alibabacloud_rum_close()樣本:
alibabacloud_rum_close()自訂資訊
設定使用者名稱稱
SDK支援設定與使用者相關的資訊,從而完成資料分析與實際使用者相關聯的需求情境。該介面需要在調用alibabacloud_rum_init函數之後設定。
void alibabacloud_rum_set_username(const char *username)參數 | 說明 | 參數限制 | 失敗結果 |
username | const char * | 字串非空,需要小於等於256。 | 介面調用失敗,當次設定無效 |
樣本:
alibabacloud_rum_set_username("my nick name is xxxx");設定使用者ID
SDK支援設定與使用者相關的資訊,從而完成資料分析與實際使用者相關聯的需求情境。該介面需要在調用alibabacloud_rum_init函數之後設定。
void alibabacloud_rum_set_userid(const char *userid)參數 | 說明 | 參數限制 | 失敗結果 |
userid | const char * | 字串非空,需要小於等於256。 | 介面調用失敗,當次設定無效 |
樣本:
alibabacloud_rum_set_userid("1234567890");設定使用者擴充資訊
SDK支援設定與使用者相關的資訊,從而完成資料分析與實際使用者相關聯的需求情境。
void alibabacloud_rum_set_user_tags(const char *user_tags)參數 | 說明 | 參數限制 | 失敗結果 |
user_tags | const char* | 字串非空,需要小於等於512。 | 介面調用失敗,當次設定無效 |
設定全域屬性
SDK支援設定自訂全域業務屬性。自訂全域屬性設定後,新產生的資料會自動攜帶該業務屬性資訊,可以完成資料分析與業務屬性相關聯的需求情境。alibabacloud_rum_set_properties函數調用後,會覆蓋上一次的值。
#define alibabacloud_rum_set_properties(...)參數 | 說明 | 參數限制 | 失敗結果 |
(...) | 屬性索引值對 | 索引值對的最大數量為50,key的長度最大為52,所有索引值對對應的字串最大長度為2000。 | 介面調用失敗,當次設定無效 |
樣本:
alibabacloud_rum_set_properties("shop_id", "gz_xihu_001", "shop_name", "西湖總店");上報自訂異常
調用自訂異常介面,並傳入相應的參數,可完成自訂異常資料的統計功能。C/C++ SDK提供了一組函數用來完成自訂異常的上報。
alibabacloud_rum_custom_exception_t* alibabacloud_rum_custom_exception_new(const char *name, const char *message);
void alibabacloud_rum_custom_exception_set_file(alibabacloud_rum_custom_exception_t *event, const char *file);
void alibabacloud_rum_custom_exception_set_source(alibabacloud_rum_custom_exception_t *event, const char *source);
void alibabacloud_rum_custom_exception_set_caused_by(alibabacloud_rum_custom_exception_t *event, const char *caused_by);
void alibabacloud_rum_custom_exception_set_stack(alibabacloud_rum_custom_exception_t *event, const char *stack);
void alibabacloud_rum_custom_exception_free(alibabacloud_rum_custom_exception_t *event);
void alibabacloud_rum_custom_exception_report(alibabacloud_rum_custom_exception_t *event);函數名稱 | 說明 |
alibabacloud_rum_custom_exception_new | 建立 alibabacloud_rum_custom_exception_t 執行個體。 |
alibabacloud_rum_custom_exception_set_file | 設定異常關聯源檔案。 |
alibabacloud_rum_custom_exception_set_source | 設定異常來源,保留欄位。 |
alibabacloud_rum_custom_exception_set_caused_by | 設定異常原因。 |
alibabacloud_rum_custom_exception_set_stack | 設定異常堆棧。 |
alibabacloud_rum_custom_exception_free | 釋放 alibabacloud_rum_custom_exception_t 執行個體,一般無需調用。 |
alibabacloud_rum_custom_exception_report | 上報自訂異常 |
樣本:
alibabacloud_rum_custom_exception_t *custom_exception = alibabacloud_rum_custom_exception_new("exception", "NullPointerException");
alibabacloud_rum_custom_exception_set_file(custom_exception, "/example/main.c");
alibabacloud_rum_custom_exception_set_caused_by(custom_exception, "NullPointerException");
alibabacloud_rum_custom_exception_set_stack(custom_exception, "Exception in thread 'main' java.util.NullPointerException");
alibabacloud_rum_custom_exception_report(custom_exception);上報自訂事件
SDK支援上報自訂事件。調用相應的介面,並傳入相應的參數,可完成自訂事件數目據的統計功能。C/C++ SDK提供了一組函數用來完成自訂事件的上報。
alibabacloud_rum_custom_event_t* alibabacloud_rum_custom_event_new(const char *type, const char *name);
void alibabacloud_rum_custom_event_set_value(alibabacloud_rum_custom_event_t *event, double value);
void alibabacloud_rum_custom_event_set_group(alibabacloud_rum_custom_event_t *event, const char *group);
void alibabacloud_rum_custom_event_set_snapshots(alibabacloud_rum_custom_event_t *event, const char *snapshots);
void alibabacloud_rum_custom_event_add_extra(alibabacloud_rum_custom_event_t *event, const char *k, const char *v);
void alibabacloud_rum_custom_event_free(alibabacloud_rum_custom_event_t *event);
void alibabacloud_rum_custom_event_report(alibabacloud_rum_custom_event_t *event);函數名稱 | 說明 |
alibabacloud_rum_custom_event_new | 建立 alibabacloud_rum_custom_event_t 執行個體。 |
alibabacloud_rum_custom_event_set_value | 設定事件關聯值。 |
alibabacloud_rum_custom_event_set_group | 設定事件分組。 |
alibabacloud_rum_custom_event_set_snapshots | 設定事件快照。 |
alibabacloud_rum_custom_event_add_extra | 設定事件擴充參數。 |
alibabacloud_rum_custom_event_free | 釋放 alibabacloud_rum_custom_event_t 執行個體,一般無需調用。 |
alibabacloud_rum_custom_event_report | 上報自訂事件。 |
樣本:
alibabacloud_rum_custom_event_t *event = alibabacloud_rum_custom_event_new("custom_event_type", "custom_event_name");
alibabacloud_rum_custom_event_set_group(event, "custom_event_group");
alibabacloud_rum_custom_event_set_value(event, 123.3456);
alibabacloud_rum_custom_event_set_snapshots(event, "custom event snapshots");
alibabacloud_rum_custom_event_add_extra(event, "event_key1", "event_value1");
alibabacloud_rum_custom_event_add_extra(event, "event_key2", "event_value2");
alibabacloud_rum_custom_event_report(event);上報自訂日誌
SDK支援上報自訂日誌資訊。調用相應的介面,並傳入相應的參數,可完成自訂日誌資料的統計功能。C/C++ SDK提供了一組函數用來完成自訂日誌的上報。
alibabacloud_rum_custom_log_t *alibabacloud_rum_custom_log_new(const char *type, const char *name);
void alibabacloud_rum_custom_log_set_log(alibabacloud_rum_custom_log_t *log, alibabacloud_rum_custom_log_level_t level, const char *content);
void alibabacloud_rum_custom_log_set_value(alibabacloud_rum_custom_log_t *log, double value);
void alibabacloud_rum_custom_log_set_group(alibabacloud_rum_custom_log_t *log, const char *group);
void alibabacloud_rum_custom_log_set_snapshots(alibabacloud_rum_custom_log_t *log, const char *snapshots);
void alibabacloud_rum_custom_log_add_extra(alibabacloud_rum_custom_log_t *log, const char *k, const char *v);
void alibabacloud_rum_custom_log_free(alibabacloud_rum_custom_log_t *log);
void alibabacloud_rum_custom_log_report(alibabacloud_rum_custom_log_t *log);函數名稱 | 說明 |
alibabacloud_rum_custom_log_t | 建立 alibabacloud_rum_custom_log_t 執行個體。 |
alibabacloud_rum_custom_log_set_log | 設定日誌內容。 |
alibabacloud_rum_custom_log_set_value | 設定日誌關聯值。 |
alibabacloud_rum_custom_log_set_group | 設定日誌分組。 |
alibabacloud_rum_custom_log_set_snapshots | 設定日誌快照。 |
alibabacloud_rum_custom_log_add_extra | 設定日誌擴充參數。 |
alibabacloud_rum_custom_log_free | 釋放 alibabacloud_rum_custom_log_t 執行個體,一般無需調用。 |
alibabacloud_rum_custom_log_report | 上報自訂日誌。 |
樣本:
alibabacloud_rum_custom_log_t *log = alibabacloud_rum_custom_log_new("custom_log_type", "custom_log_name");
alibabacloud_rum_custom_log_set_group(log, "custom_log_group");
alibabacloud_rum_custom_log_set_value(log, 343.4222);
alibabacloud_rum_custom_log_set_snapshots(log, "custom log snapshots");
alibabacloud_rum_custom_log_set_log(log, LOG_DEBUG, "我是自訂日誌內容");
alibabacloud_rum_custom_log_add_extra(log, "log_key1", "log_value1");
alibabacloud_rum_custom_log_add_extra(log, "log_key2", "log_value2");
alibabacloud_rum_custom_log_report(log);上報自訂資源
SDK支援上報自訂資源資訊。調用相應的介面,並傳入相應的參數,可完成自訂資源資料的統計功能。C/C++ SDK提供了一組函數用來完成自訂資源的上報。
alibabacloud_rum_custom_resource_t* alibabacloud_rum_custom_resource_new(const char *url, const char *method);
void alibabacloud_rum_custom_resource_set_type(alibabacloud_rum_custom_resource_t *resource, alibabacloud_rum_resource_type_t type);
void alibabacloud_rum_custom_resource_set_status_code(alibabacloud_rum_custom_resource_t *resource, int32_t status_code);
void alibabacloud_rum_custom_resource_set_success(alibabacloud_rum_custom_resource_t *resource, int32_t success);
void alibabacloud_rum_custom_resource_set_measuring(
alibabacloud_rum_custom_resource_t *resource,
int64_t duration,
int64_t size,
int32_t connect_duration,
int32_t ssl_duration,
int32_t dns_duration,
int32_t redirect_duration,
int32_t first_byte_duration,
int32_t download_duration);
void alibabacloud_rum_custom_resource_set_trace_id(alibabacloud_rum_custom_resource_t *resource, const char *trace_id);
void alibabacloud_rum_custom_resource_set_span_id(alibabacloud_rum_custom_resource_t *resource, const char *span_id);
void alibabacloud_rum_custom_resource_set_provider(alibabacloud_rum_custom_resource_t *resource, const char *provider);
void alibabacloud_rum_custom_resource_add_attribute(alibabacloud_rum_custom_resource_t *resource, const char *key, const char *value);
void alibabacloud_rum_custom_resource_free(alibabacloud_rum_custom_resource_t *resource);
void alibabacloud_rum_custom_resource_report(alibabacloud_rum_custom_resource_t *resource);函數名稱 | 說明 |
alibabacloud_rum_custom_resource_new | 建立 alibabacloud_rum_custom_resource_t 執行個體。 |
alibabacloud_rum_custom_resource_set_type | 設定資源類型 |
alibabacloud_rum_custom_resource_set_status_code | 設定狀態代碼 |
alibabacloud_rum_custom_resource_set_success | 設定資源載入狀態
|
alibabacloud_rum_custom_resource_set_measuring | 設定resource效能資訊 |
alibabacloud_rum_custom_resource_set_trace_id | 設定traceId |
alibabacloud_rum_custom_resource_set_span_id | 設定spanId |
alibabacloud_rum_custom_resource_set_provider | 設定resource提供者類型 (eg: first-party, cdn, ad, analytics)。 |
alibabacloud_rum_custom_resource_add_attribute | 設定日誌擴充參數。 |
alibabacloud_rum_custom_resource_free | 釋放alibabacloud_rum_custom_resource_t 執行個體,一般無需調用。 |
alibabacloud_rum_custom_resource_report | 上報日定義資源資料。 |
其中measuring指標資料,參數及定義:
參數 | 說明 |
duration | 資源載入的全部耗時,單位ms |
size | 資源大小,單位Byte |
connectDuration | 與伺服器建連耗時,單位ms |
sslDuration | TLS握手耗時,單位ms |
dnsDuration | DNS解析耗時,單位ms |
redirectDuration | 重新導向耗時,單位ms |
firstByteDuration | 首包耗時,單位ms |
downloadDuration | 下載響應耗時,單位ms |
樣本:
alibabacloud_rum_custom_resource_t *resource =
alibabacloud_rum_custom_resource_new("https://api.example.com/users", "GET");
if (!resource) {
printf("Failed to create resource event\n");
return;
}
// Set resource type
alibabacloud_rum_custom_resource_set_type(resource, ALIBABACLOUD_RUM_RESOURCE_TYPE_XHR);
// Set HTTP response info
alibabacloud_rum_custom_resource_set_status_code(resource, 200);
alibabacloud_rum_custom_resource_set_success(resource, 1);
alibabacloud_rum_custom_resource_set_provider(resource, "first-party")
// Set all performance metrics at once
alibabacloud_rum_custom_resource_set_measuring(
resource,
285, // duration
2048, // size
25, // connect_duration
45, // ssl_duration
15, // dns_duration
0, // redirect_duration
120, // first_byte_duration
80 // download_duration
);
// Add custom attributes
alibabacloud_rum_custom_resource_add_attribute(resource, "endpoint", "/users");
alibabacloud_rum_custom_resource_add_attribute(resource, "api_version", "v1");
// Report the event
alibabacloud_rum_custom_resource_report(resource);
// Clean up
alibabacloud_rum_custom_resource_free(resource);