sentry-dotnet icon indicating copy to clipboard operation
sentry-dotnet copied to clipboard

Add device attributes to Logs in the MAUI SDK

Open dalnoki opened this issue 2 months ago • 3 comments

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

dalnoki avatar Nov 13 '25 12:11 dalnoki

NET-525

linear[bot] avatar Nov 13 '25 12:11 linear[bot]

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.

munkii avatar Nov 20 '25 11:11 munkii

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;
});

munkii avatar Nov 21 '25 13:11 munkii