跳转至

自定义标签

C# 与 Native C/C++ 都支持用户信息、SDK 全局上下文和 RUM 全局上下文。Log 还可以配置独立的全局属性。

设置用户

RumSdk.SetUser(
    id: "user-123",
    name: "Alice",
    email: "alice@example.com",
    extra: new Dictionary<string, object?>
    {
        ["plan"] = "enterprise"
    });
guance_rum_set_user(
    rum,
    "user-123",
    "Alice",
    "alice@example.com");

清除用户:

RumSdk.ClearUser();
guance_rum_clear_user(rum);

用户切换只影响后续数据,不修改已经入队的数据。

SDK 全局上下文

适用于 RUM 以及开启关联的 Log:

RumSdk.AddGlobalContext("region", "cn-east-1");
RumSdk.AddGlobalContext("tenant", "tenant-a");
guance_rum_add_global_context(rum, "region", "cn-east-1");
guance_rum_add_global_context(rum, "tenant", "tenant-a");

RUM 全局上下文

只追加到 RUM 数据:

RumSdk.AddRumGlobalContext("ui.framework", "wpf");
guance_rum_add_rum_context(rum, "ui.framework", "win32");

Log 全局上下文

Log 专用标签在初始化 Log 时配置:

Logging = new RumLogConfig
{
    EnableCustomLog = true,
    GlobalContext = new Dictionary<string, object?>
    {
        ["logger_name"] = "desktop-client"
    }
}
guance_rum_log_property context[] = {
    {"logger_name", "native-client"}
};
logging.global_context = context;
logging.global_context_count = 1;

完整参数请参考 Log 配置

事件级属性

C# 的手动 RUM 和 Log API 接受事件级字典。Native Log 接受 guance_rum_log_property;Native RUM v1 的手动事件 API 不提供任意事件级属性结构。

RumSdk.AddAction(
    "Save",
    "click",
    TimeSpan.FromMilliseconds(25),
    new Dictionary<string, object?>
    {
        ["result"] = "success"
    });

命名与保留字段

  • 使用小写、稳定、可聚合的字段名,例如 feature.name
  • 不要写入 Token、Cookie、密码或直接身份信息。
  • app_idserviceenvversionsdk_namesession_idview_idaction_id 和平台字段由 SDK 管理。
  • 自定义上下文不能覆盖 SDK 保留字段。
  • Native 上下文 API 会同步复制字符串;不要传入空 Key。

文档评价

文档内容是否对您有帮助? ×