You can use SDK configuration items to set parameters for specific requirements. This topic describes common SDK configurations for PC applications.
Startup configurations
(Required) Set the Config address
You must associate each application with its Config address. Call this function before you call the alibabacloud_rum_init function.
void alibabacloud_rum_options_set_config_address(alibabacloud_rum_options_t *options, const char *config_address);Parameter | Description | Constraints | Result if failed |
options | alibabacloud_rum_options_t | Cannot be empty. Created using the | If the function call fails, the SDK stops. |
config_address | const char* | Cannot be empty. Generated by the Real User Monitoring (RUM) platform. | The API call failed, and the SDK stopped. |
Example:
alibabacloud_rum_options_set_config_address(options, RUM_CONFIG_ADDRESS);(Required) Set the application ID
You must associate each application with its AppId. Call this function before you call the alibabacloud_rum_init function.
void alibabacloud_rum_options_set_app_id(alibabacloud_rum_options_t *options, const char *app_id)Parameter | Description | Constraints | Result if failed |
app_id | The AppID of the application. | The unique application ID generated by the RUM platform. | The API call failed, causing the SDK to stop. |
Example:
alibabacloud_rum_options_set_app_id(options, RUM_CONFIG_APPID);(Required) Set the application name
You must set the application name. Call this function before you call the alibabacloud_rum_init function.
void alibabacloud_rum_options_set_app_name(alibabacloud_rum_options_t *options, const char *app_name)Parameter | Description | Constraints | Result if failed |
app_name | const char*. The name of the application. | Cannot be empty. The string length must be greater than 0 and less than 128. | If the function call fails, the application name setting does not take effect. |
Example:
alibabacloud_rum_options_set_app_name(options, "WindowsDemo");(Required) Set the application version number
The SDK lets you set the version number of the application. You must call this function before you call the alibabacloud_rum_init function.
void alibabacloud_rum_options_set_app_version(alibabacloud_rum_options_t *options, const char *app_version)Parameter | Description | Constraints | Result if failed |
app_version | const char* | Cannot be empty. The string length must be greater than 0 and less than 64. | If the function call fails, the application version number setting does not take effect. |
Example:
alibabacloud_rum_options_set_app_version(options, "0.1.0-beta.2");(Optional) Set the application environment
The SDK lets you set the application environment. Environments include local, daily, pre, gray, and prod. Call this function before you call the alibabacloud_rum_init function.
void alibabacloud_rum_options_set_env(alibabacloud_rum_options_t *options, alibabacloud_rum_env_t env)Parameter | Description | Constraints | Failure |
env | Application environment enumeration. | Specify one of the following enumeration values:
| If the function call fails, the application environment setting does not take effect. |
Example:
alibabacloud_rum_options_set_env(options, ALIBABACLOUD_RUM_ENV_LOCAL);(Optional) Set the device ID
You can set the device ID for the application as needed. By default, the SDK generates a device ID and caches it in a local file. Call this function before you call the alibabacloud_rum_init function.
void alibabacloud_rum_options_set_utdid(alibabacloud_rum_options_t *options, const char *utdid)Parameter | Description | Constraints | Result if failed |
utdid | const char*. The device ID. | Cannot be empty. The string length must be greater than 0 and less than 37. | If the function call fails, the device ID setting does not take effect. |
Example:
alibabacloud_rum_options_set_utdid(options, "b7028408-ddac-4a58-72a9-653f6637f0e6");(Optional) Set the log level
The SDK outputs logs during runtime. If you encounter issues when you use the SDK, you can adjust the SDK log level to output more information for troubleshooting. Call this function before you call the alibabacloud_rum_init function.
void alibabacloud_rum_options_set_debug_level(alibabacloud_rum_options_t *options, alibabacloud_rum_level_t level);Parameter | Description | Constraints | Failure |
level | Log level enumeration. | Specify one of the following enumeration values:
ALIBABACLOUD_RUM_LEVEL_ALL is the highest log level. At this level, logs are written to the cache file. | If the function call fails, the log level setting does not take effect. |
Example:
alibabacloud_rum_options_set_debug_level(options, ALIBABACLOUD_RUM_LEVEL_DEBUG);(Optional) Set the cache folder
The SDK generates cache files during runtime. You can specify a cache folder as needed. By default, the SDK creates a folder named .alibabacloud-rum in the same directory as the executable file. Call this function before you call the alibabacloud_rum_init function.
void alibabacloud_rum_options_set_cache_path(alibabacloud_rum_options_t *options, const char *path)Parameter | Description | Constraints | Result if failed |
path | const char * | Cannot be empty. The length of the file path may be limited by the system. | If the function call fails, the cache folder setting does not take effect. |
Example:
alibabacloud_rum_options_set_cache_path(options, "/path/to/your/cache/");(Optional) Set a filter for network request collection
The SDK supports collecting network request data from the libcurl and Chromium Embedded Framework (CEF) frameworks. You can configure a network request collection filter to control the collection behavior for specific URLs. Call this function before you call the alibabacloud_rum_init function.
void alibabacloud_rum_options_set_network_options(alibabacloud_rum_options_t *options, alibabacloud_rum_network_options_t *network_options)Parameter | Description | Constraints | Result if failed |
network_options | The struct for the network request filter. | Cannot be empty. Must meet the definition of the following struct: | If the function call fails, the network request collection filter setting does not take effect. |
Example:
// Filters whether collection is allowed for a specific URL.
// If this function returns 0, the data is not collected. If it returns a non-zero value, the data is collected.
int ALIBABACLOUD_RUM_CALLBACK example_should_record_request(const char *url)
{
LOG("example", "example_should_record_request, url: %s", url);
return 1;
}
// Filters whether end-to-end tracing is allowed for a specific URL.
// If this function returns 0, tracing is allowed. If it returns a non-zero value, tracing is not allowed.
int ALIBABACLOUD_RUM_CALLBACK example_should_tracing(const char *url)
{
LOG("example", "example_should_tracing, url: %s", url);
return NULL != strstr(url, "/api/data");
}
// Note: The SDK configures network_options by default. By default, data from all URL requests is collected, and end-to-end tracing is not allowed for any 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);(Optional) Enable or disable the libcurl network request collection module
The SDK lets you configure whether to enable the libcurl network request module. This module is enabled by default. Call this function before you call the alibabacloud_rum_init function.
void alibabacloud_rum_options_set_auto_curl_tracking(alibabacloud_rum_options_t *options, int enabled)Parameter | Description | Constraints | Failure |
enabled | int | 0: Disable. 1: Enable. | If the function call fails, the libcurl network request module setting does not take effect. |
Example:
// Enable the libcurl network request collection module.
alibabacloud_rum_options_set_auto_curl_tracking(options, 1);Note: Before you enable the libcurl network request collection module, you must integrate the libcurl library. Currently, only data collection from the libcurl dynamic library is supported.
(Optional) Enable or disable the crash collection module
The SDK lets you configure whether to enable the crash data collection module. This module is enabled by default. Call this function before you call the alibabacloud_rum_init function.
void alibabacloud_rum_options_set_auto_crash_tracking(alibabacloud_rum_options_t *options, int enabled)Parameter | Description | Constraints | Failures |
enabled | int | 0: Disable. 1: Enable. | If the function call fails, the crash data collection module setting does not take effect. |
Example:
// Enable the crash data collection module.
alibabacloud_rum_options_set_auto_crash_tracking(options, 1);(Optional) Enable or disable the CEF framework data collection module
The SDK lets you configure whether to enable the CEF data collection module. This module is disabled by default. Call this function before you call the alibabacloud_rum_init function.
void alibabacloud_rum_options_set_auto_cef_tracking(alibabacloud_rum_options_t *options, int enabled)Parameter | Description | Constraints | Result if failed |
enabled | int | 0: Disable. 1: Enable. | If the function call fails, the CEF framework data collection module setting does not take effect. |
Example:
// Enable the CEF framework data collection module.
alibabacloud_rum_options_set_auto_cef_tracking(options, 1);Note: Before you enable the CEF data collection module, you must integrate the CEF library. Currently, only data collection from the CEF dynamic library is supported.
(Required) Start the SDK
Use the alibabacloud_rum_init function to initialize the SDK.
int alibabacloud_rum_init(alibabacloud_rum_options_t *options)Parameter | Description | Constraints | Failure |
options | SDK configuration items. | Cannot be empty. All required parameters must be set. | If the function call fails, the SDK stops. |
(Required) Shut down the SDK
Use the alibabacloud_rum_close function to shut down the SDK.
int alibabacloud_rum_close()Example:
alibabacloud_rum_close()Custom information
Set the username
The SDK lets you set user-related information. This helps you associate data analytics with actual users. Call this function after you call the alibabacloud_rum_init function.
void alibabacloud_rum_set_username(const char *username)Parameter | Description | Constraints | Result if failed |
username | const char * | The string cannot be empty. The length must be 256 or less. | The interface call failed. The setting was not applied. |
Example:
alibabacloud_rum_set_username("my nick name is xxxx");Set the user ID
The SDK lets you set user-related information. This helps you associate data analytics with actual users. Call this function after you call the alibabacloud_rum_init function.
void alibabacloud_rum_set_userid(const char *userid)Parameter | Description | Constraints | Result if failed |
userid | const char * | The string cannot be empty. The length must be 256 or less. | If the function call fails, the current setting is invalid. |
Example:
alibabacloud_rum_set_userid("1234567890");Set extended user information
The SDK lets you set user-related information. This helps you associate data analytics with actual users.
void alibabacloud_rum_set_user_tags(const char *user_tags)Parameter | Description | Constraints | Result if failed |
user_tags | const char* | The string cannot be empty. The length must be 512 or less. | If the function call fails, the current setting is invalid. |
Set global properties
The SDK lets you set custom global business properties. After you set custom global properties, newly generated data automatically includes these properties. This helps you associate data analytics with business properties. A call to the alibabacloud_rum_set_properties function overwrites the previous value.
#define alibabacloud_rum_set_properties(...)Parameter | Description | Constraints | Failure |
(...) | Key-value pairs for the properties. | The maximum number of key-value pairs is 50. The maximum length of a key is 52. The maximum total length of all key-value pair strings is 2000. | If the function call fails, the current setting is invalid. |
Example:
alibabacloud_rum_set_properties("shop_id", "gz_xihu_001", "shop_name", "Xihu Main Store");Report a custom exception
You can call the custom exception function and pass the corresponding parameters to collect custom exception data. The C/C++ SDK provides a set of functions to report custom exceptions.
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);Function name | Description |
alibabacloud_rum_custom_exception_new | Creates an alibabacloud_rum_custom_exception_t instance. |
alibabacloud_rum_custom_exception_set_file | Sets the source file associated with the exception. |
alibabacloud_rum_custom_exception_set_source | Sets the source of the exception. This is a reserved field. |
alibabacloud_rum_custom_exception_set_caused_by | Sets the cause of the exception. |
alibabacloud_rum_custom_exception_set_stack | Sets the exception stack. |
alibabacloud_rum_custom_exception_free | Releases the alibabacloud_rum_custom_exception_t instance. You do not typically need to call this function. |
alibabacloud_rum_custom_exception_report | Reports the custom exception. |
Example:
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);Report a custom event
The SDK supports reporting custom events. You can call the corresponding function and pass the required parameters to collect custom event data. The C/C++ SDK provides a set of functions to report custom events.
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);Function name | Description |
alibabacloud_rum_custom_event_new | Creates an alibabacloud_rum_custom_event_t instance. |
alibabacloud_rum_custom_event_set_value | Sets the value associated with the event. |
alibabacloud_rum_custom_event_set_group | Sets the event group. |
alibabacloud_rum_custom_event_set_snapshots | Sets the event snapshot. |
alibabacloud_rum_custom_event_add_extra | Sets extended parameters for the event. |
alibabacloud_rum_custom_event_free | Releases the alibabacloud_rum_custom_event_t instance. You do not typically need to call this function. |
alibabacloud_rum_custom_event_report | Reports the custom event. |
Example:
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);Report a custom log
The SDK supports reporting custom log information. You can call the corresponding function and pass the required parameters to collect custom log data. The C/C++ SDK provides a set of functions to report custom logs.
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);Function name | Description |
alibabacloud_rum_custom_log_t | Creates an alibabacloud_rum_custom_log_t instance. |
alibabacloud_rum_custom_log_set_log | Sets the log content. |
alibabacloud_rum_custom_log_set_value | Sets the value associated with the log. |
alibabacloud_rum_custom_log_set_group | Sets the log group. |
alibabacloud_rum_custom_log_set_snapshots | Sets the log snapshot. |
alibabacloud_rum_custom_log_add_extra | Sets extended parameters for the log. |
alibabacloud_rum_custom_log_free | Releases the alibabacloud_rum_custom_log_t instance. You do not typically need to call this function. |
alibabacloud_rum_custom_log_report | Reports the custom log. |
Example:
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, "This is the custom log content");
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);Report a custom resource
The SDK supports reporting custom resource information. You can call the corresponding function and pass the required parameters to collect custom resource data. The C/C++ SDK provides a set of functions to report custom resources.
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);Function name | Description |
alibabacloud_rum_custom_resource_new | Creates an alibabacloud_rum_custom_resource_t instance. |
alibabacloud_rum_custom_resource_set_type | Sets the resource type. |
alibabacloud_rum_custom_resource_set_status_code | Sets the status code. |
alibabacloud_rum_custom_resource_set_success | Sets the resource loading status.
|
alibabacloud_rum_custom_resource_set_measuring | Sets the performance information for the resource. |
alibabacloud_rum_custom_resource_set_trace_id | Sets the traceId. |
alibabacloud_rum_custom_resource_set_span_id | Sets the spanId. |
alibabacloud_rum_custom_resource_set_provider | Sets the resource provider type, such as first-party, cdn, ad, or analytics. |
alibabacloud_rum_custom_resource_add_attribute | You can set the log extension parameters. |
alibabacloud_rum_custom_resource_free | Releases the alibabacloud_rum_custom_resource_t instance. You do not typically need to call this function. |
alibabacloud_rum_custom_resource_report | Reports the custom resource data. |
The following table describes the parameters and definitions for the measurement metrics.
Parameter | Description |
duration | The total time it takes to load the resource. Unit: ms. |
size | The size of the resource. Unit: bytes. |
connectDuration | The time it takes to establish a connection with the server. Unit: ms. |
sslDuration | The time it takes for the TLS handshake. Unit: ms. |
dnsDuration | The time it takes for DNS parsing. Unit: ms. |
redirectDuration | The time it takes for redirection. Unit: ms. |
firstByteDuration | The time to first byte. Unit: ms. |
downloadDuration | The time it takes to download the response. Unit: ms. |
Example:
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);