Sentry - 向用户上下文添加任意 key/value 对
Sentry - adding arbitrary key/value pairs to the user context
在下面的documentation中,它表示您可以
...provide arbitrary key/value pairs beyond the reserved names and those will be stored with the user
在 C# 代码中,我有以下内容:
var _user = new {
Login = "fred",
EmailAddress = "fred@here.com",
Name = "Fred Flintstone"
}
SentrySdk.ConfigureScope( scope => {
scope.User = new Sentry.Protocol.User()
{
Id = _user.Login,
Email = _user.EmailAddress,
Username = _user.Login
};
});
有没有办法添加Name
(或任何其他字段)?或者文档只是指标签?
您可以通过 Other
属性 添加自定义用户数据。
Sentry.Protocol
的最新版本将 Other
作为 IReadOnlyDictionary
,这意味着您需要分配一个新实例,例如:
var sut = new User
{
Id = "user-id",
Email = "test@sentry.io",
IpAddress = "::1",
Username = "user-name",
Other = new Dictionary<string, string>
{
{"Name", "your name"},
{"anything else", "whatever"},
}
};
This PR is making Other
mutable 这样您就可以添加如下数据:
var user = new User();
user.Other.Add("key", "value");
在下面的documentation中,它表示您可以
...provide arbitrary key/value pairs beyond the reserved names and those will be stored with the user
在 C# 代码中,我有以下内容:
var _user = new {
Login = "fred",
EmailAddress = "fred@here.com",
Name = "Fred Flintstone"
}
SentrySdk.ConfigureScope( scope => {
scope.User = new Sentry.Protocol.User()
{
Id = _user.Login,
Email = _user.EmailAddress,
Username = _user.Login
};
});
有没有办法添加Name
(或任何其他字段)?或者文档只是指标签?
您可以通过 Other
属性 添加自定义用户数据。
Sentry.Protocol
的最新版本将 Other
作为 IReadOnlyDictionary
,这意味着您需要分配一个新实例,例如:
var sut = new User
{
Id = "user-id",
Email = "test@sentry.io",
IpAddress = "::1",
Username = "user-name",
Other = new Dictionary<string, string>
{
{"Name", "your name"},
{"anything else", "whatever"},
}
};
This PR is making Other
mutable 这样您就可以添加如下数据:
var user = new User();
user.Other.Add("key", "value");