Add device attributes to Logs in the MAUI SDK
Problem Statement
The Sentry MAUI SDK currently does not include device-specific attributes (such as device.model, device.platform, device.manufacturer, and device.brand) in structured logs, even though this information is collected and sent with error events and issues.
Solution Brainstorm
No response
As the customer that triggered support rasing this ticket I thought I'd had some background. As it currently stands the logs and more importantly the lack of supplementary data mean they really only work in the scope of a single developer with one maybe two devices.
As soon as QA or production gets involved we need to know what devices are triggering which logs and that is impossible at the moment.
As a workaround I haved changed SetBeforeSendLog to read the User details out of Scope and then apply them to Log with SetAttribute
options.Experimental.SetBeforeSendLog(log =>
{
#if DEBUG
SentryLogLevel minimumLevel = SentryLogLevel.Debug;
#else
SentryLogLevel minimumLevel = SentryLogLevel.Info;
#endif
log.SetAttribute("DeviceName", DeviceInfo.Name);
log.SetAttribute("Manufacturer", DeviceInfo.Manufacturer);
log.SetAttribute("OSVersion", DeviceInfo.VersionString);
log.SetAttribute("DeviceModel", DeviceInfo.Model);
SentryUser sentryUser = null; ;
SentrySdk.ConfigureScope(scope =>
{
if (scope.HasUser())
{
sentryUser = scope.User;
}
});
if (sentryUser != null) {
log.SetAttribute("UserId", sentryUser.Id);
log.SetAttribute("UserName", sentryUser.Username);
}
if (log.Level < minimumLevel)
{
return null;
}
return log;
});