Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Fixes

- On mobile devices, the SDK no longer throws a `FormatException` for `ProcessorFrequency` when trying to report native events ([#3541](https://github.com/getsentry/sentry-dotnet/pull/3541))
- Unfinished spans are now correctly stored and retrieved by the CachingTransport ([#3533](https://github.com/getsentry/sentry-dotnet/pull/3533))

### Dependencies
Expand Down
20 changes: 12 additions & 8 deletions src/Sentry/Protocol/Device.cs
Original file line number Diff line number Diff line change
Expand Up @@ -427,16 +427,13 @@ public static Device FromJson(JsonElement json)
var modelId = json.GetPropertyOrNull("model_id")?.GetString();
var architecture = json.GetPropertyOrNull("arch")?.GetString();

// TODO: For next major: Remove this and change batteryLevel from short to float
// TODO: For next major: Remove this and change BatteryLevel from short to float
// The Java and Cocoa SDK report the battery as `float`
// Cocoa https://github.com/getsentry/sentry-cocoa/blob/e773cad622b86735f1673368414009475e4119fd/Sources/Sentry/include/SentryUIDeviceWrapper.h#L18
// Java https://github.com/getsentry/sentry-java/blob/25f1ca4e1636a801c17c1662f0145f888550bce8/sentry/src/main/java/io/sentry/protocol/Device.java#L231-L233
short? batteryLevel = null;
var batteryProperty = json.GetPropertyOrNull("battery_level");
if (batteryProperty.HasValue)
{
batteryLevel = (short)batteryProperty.Value.GetDouble();
}
var batteryLevel = json.GetPropertyOrNull("battery_level")?.TryGetDouble(out var level) == true
? (short)level
: (short?)null;

var isCharging = json.GetPropertyOrNull("charging")?.GetBoolean();
var isOnline = json.GetPropertyOrNull("online")?.GetBoolean();
Expand All @@ -456,7 +453,14 @@ public static Device FromJson(JsonElement json)
var bootTime = json.GetPropertyOrNull("boot_time")?.GetDateTimeOffset();
var processorCount = json.GetPropertyOrNull("processor_count")?.GetInt32();
var cpuDescription = json.GetPropertyOrNull("cpu_description")?.GetString();
var processorFrequency = json.GetPropertyOrNull("processor_frequency")?.GetInt32();

// TODO: For next major: Remove this and change ProcessorFrequency from int to float
// The Java SDK reports the processorFrequency as `double`
// Java https://github.com/getsentry/sentry-java/blob/9762f09afa51944b40a9b77e116a55e54636e6c5/sentry/src/main/java/io/sentry/protocol/Device.java#L130
var processorFrequency = json.GetPropertyOrNull("processor_frequency")?.TryGetDouble(out var frequency) == true
? (int)frequency
: (int?)null;

var deviceType = json.GetPropertyOrNull("device_type")?.GetString();
var batteryStatus = json.GetPropertyOrNull("battery_status")?.GetString();
var deviceUniqueIdentifier = json.GetPropertyOrNull("device_unique_identifier")?.GetString();
Expand Down