Skip to content

Commit d15cdd9

Browse files
Align device types with Cocoa and Java SDKs (#3567)
1 parent e2967f0 commit d15cdd9

File tree

10 files changed

+159
-248
lines changed

10 files changed

+159
-248
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- You should no longer pass `AndroidContext` as an argument to `SentrySdk.Init` ([#3562](https://github.com/getsentry/sentry-dotnet/pull/3562))
88
- The `SentryUser.Segment` property has been deprecated. Consider sending this as a tag or additional data instead ([#3563](https://github.com/getsentry/sentry-dotnet/pull/3563))
99
- The ITraceContext now includes an [Origin](https://develop.sentry.dev/sdk/telemetry/traces/trace-origin/), which is set automatically and is primarily used internally by the Sentry server ([#3564](https://github.com/getsentry/sentry-dotnet/pull/3564))
10+
- `Device.BatteryLevel` and `Device.ProcessorFrequency` are now stored as floats rather than ints, to align with the Cocoa and Java SDKs ([#3567](https://github.com/getsentry/sentry-dotnet/pull/3567))
1011

1112
## 4.10.2
1213

src/Sentry.Maui/Internal/MauiDeviceData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static void ApplyMauiDeviceData(this Device device, IDiagnosticLogger? lo
4040
try
4141
{
4242
var battery = Battery.Default;
43-
device.BatteryLevel ??= battery.ChargeLevel < 0 ? null : (short)(battery.ChargeLevel * 100.0);
43+
device.BatteryLevel ??= battery.ChargeLevel < 0 ? null : (float)(battery.ChargeLevel * 100.0);
4444
device.BatteryStatus ??= battery.State.ToString();
4545
device.IsCharging ??= battery.State switch
4646
{

src/Sentry/Platforms/Android/Extensions/DeviceExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static void ApplyFromSentryAndroidSdk(this Device device, JavaSdk.Protoco
2323
device.Name ??= d.Name;
2424
device.Family ??= d.Family;
2525
device.ModelId ??= d.ModelId;
26-
device.BatteryLevel ??= d.BatteryLevel?.ShortValue();
26+
device.BatteryLevel ??= d.BatteryLevel?.FloatValue();
2727
device.IsCharging ??= d.IsCharging()?.BooleanValue();
2828
device.IsOnline ??= d.IsOnline()?.BooleanValue();
2929
device.Orientation ??= d.Orientation?.ToDeviceOrientation();

src/Sentry/Protocol/Device.cs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ public sealed class Device : ISentryJsonSerializable, ICloneable<Device>, IUpdat
7070
public string? Architecture { get; set; }
7171

7272
/// <summary>
73-
/// If the device has a battery an integer defining the battery level (in the range 0-100).
73+
/// If the device has a battery a number defining the battery level (in the range 0-100).
7474
/// </summary>
75-
public short? BatteryLevel { get; set; }
75+
public float? BatteryLevel { get; set; }
7676

7777
/// <summary>
7878
/// True if the device is charging.
@@ -184,7 +184,7 @@ public sealed class Device : ISentryJsonSerializable, ICloneable<Device>, IUpdat
184184
/// <example>
185185
/// 2500
186186
/// </example>
187-
public int? ProcessorFrequency { get; set; }
187+
public float? ProcessorFrequency { get; set; }
188188

189189
/// <summary>
190190
/// Kind of device the application is running on.
@@ -426,15 +426,9 @@ public static Device FromJson(JsonElement json)
426426
var model = json.GetPropertyOrNull("model")?.GetString();
427427
var modelId = json.GetPropertyOrNull("model_id")?.GetString();
428428
var architecture = json.GetPropertyOrNull("arch")?.GetString();
429-
430-
// TODO: For next major: Remove this and change BatteryLevel from short to float
431-
// The Java and Cocoa SDK report the battery as `float`
432-
// Cocoa https://github.com/getsentry/sentry-cocoa/blob/e773cad622b86735f1673368414009475e4119fd/Sources/Sentry/include/SentryUIDeviceWrapper.h#L18
433-
// Java https://github.com/getsentry/sentry-java/blob/25f1ca4e1636a801c17c1662f0145f888550bce8/sentry/src/main/java/io/sentry/protocol/Device.java#L231-L233
434429
var batteryLevel = json.GetPropertyOrNull("battery_level")?.TryGetDouble(out var level) is true
435-
? (short)level
436-
: (short?)null;
437-
430+
? (float)level
431+
: (float?)null;
438432
var isCharging = json.GetPropertyOrNull("charging")?.GetBoolean();
439433
var isOnline = json.GetPropertyOrNull("online")?.GetBoolean();
440434
var orientation = json.GetPropertyOrNull("orientation")?.GetString()?.ParseEnum<DeviceOrientation>();
@@ -453,14 +447,9 @@ public static Device FromJson(JsonElement json)
453447
var bootTime = json.GetPropertyOrNull("boot_time")?.GetDateTimeOffset();
454448
var processorCount = json.GetPropertyOrNull("processor_count")?.GetInt32();
455449
var cpuDescription = json.GetPropertyOrNull("cpu_description")?.GetString();
456-
457-
// TODO: For next major: Remove this and change ProcessorFrequency from int to float
458-
// The Java SDK reports the processorFrequency as `double`
459-
// Java https://github.com/getsentry/sentry-java/blob/9762f09afa51944b40a9b77e116a55e54636e6c5/sentry/src/main/java/io/sentry/protocol/Device.java#L130
460450
var processorFrequency = json.GetPropertyOrNull("processor_frequency")?.TryGetDouble(out var frequency) is true
461-
? (int)frequency
462-
: (int?)null;
463-
451+
? (float)frequency
452+
: (float?)null;
464453
var deviceType = json.GetPropertyOrNull("device_type")?.GetString();
465454
var batteryStatus = json.GetPropertyOrNull("battery_status")?.GetString();
466455
var deviceUniqueIdentifier = json.GetPropertyOrNull("device_unique_identifier")?.GetString();

test/Sentry.Tests/ApiApprovalTests.Run.DotNet6_0.verified.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,7 +1588,7 @@ namespace Sentry.Protocol
15881588
public const string Type = "device";
15891589
public Device() { }
15901590
public string? Architecture { get; set; }
1591-
public short? BatteryLevel { get; set; }
1591+
public float? BatteryLevel { get; set; }
15921592
public string? BatteryStatus { get; set; }
15931593
public System.DateTimeOffset? BootTime { get; set; }
15941594
public string? Brand { get; set; }
@@ -1610,7 +1610,7 @@ namespace Sentry.Protocol
16101610
public string? Name { get; set; }
16111611
public Sentry.Protocol.DeviceOrientation? Orientation { get; set; }
16121612
public int? ProcessorCount { get; set; }
1613-
public int? ProcessorFrequency { get; set; }
1613+
public float? ProcessorFrequency { get; set; }
16141614
public float? ScreenDensity { get; set; }
16151615
public int? ScreenDpi { get; set; }
16161616
public string? ScreenResolution { get; set; }

test/Sentry.Tests/ApiApprovalTests.Run.DotNet7_0.verified.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,7 +1588,7 @@ namespace Sentry.Protocol
15881588
public const string Type = "device";
15891589
public Device() { }
15901590
public string? Architecture { get; set; }
1591-
public short? BatteryLevel { get; set; }
1591+
public float? BatteryLevel { get; set; }
15921592
public string? BatteryStatus { get; set; }
15931593
public System.DateTimeOffset? BootTime { get; set; }
15941594
public string? Brand { get; set; }
@@ -1610,7 +1610,7 @@ namespace Sentry.Protocol
16101610
public string? Name { get; set; }
16111611
public Sentry.Protocol.DeviceOrientation? Orientation { get; set; }
16121612
public int? ProcessorCount { get; set; }
1613-
public int? ProcessorFrequency { get; set; }
1613+
public float? ProcessorFrequency { get; set; }
16141614
public float? ScreenDensity { get; set; }
16151615
public int? ScreenDpi { get; set; }
16161616
public string? ScreenResolution { get; set; }

test/Sentry.Tests/ApiApprovalTests.Run.DotNet8_0.verified.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,7 +1590,7 @@ namespace Sentry.Protocol
15901590
public const string Type = "device";
15911591
public Device() { }
15921592
public string? Architecture { get; set; }
1593-
public short? BatteryLevel { get; set; }
1593+
public float? BatteryLevel { get; set; }
15941594
public string? BatteryStatus { get; set; }
15951595
public System.DateTimeOffset? BootTime { get; set; }
15961596
public string? Brand { get; set; }
@@ -1612,7 +1612,7 @@ namespace Sentry.Protocol
16121612
public string? Name { get; set; }
16131613
public Sentry.Protocol.DeviceOrientation? Orientation { get; set; }
16141614
public int? ProcessorCount { get; set; }
1615-
public int? ProcessorFrequency { get; set; }
1615+
public float? ProcessorFrequency { get; set; }
16161616
public float? ScreenDensity { get; set; }
16171617
public int? ScreenDpi { get; set; }
16181618
public string? ScreenResolution { get; set; }

test/Sentry.Tests/ApiApprovalTests.Run.Net4_8.verified.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,7 +1586,7 @@ namespace Sentry.Protocol
15861586
public const string Type = "device";
15871587
public Device() { }
15881588
public string? Architecture { get; set; }
1589-
public short? BatteryLevel { get; set; }
1589+
public float? BatteryLevel { get; set; }
15901590
public string? BatteryStatus { get; set; }
15911591
public System.DateTimeOffset? BootTime { get; set; }
15921592
public string? Brand { get; set; }
@@ -1608,7 +1608,7 @@ namespace Sentry.Protocol
16081608
public string? Name { get; set; }
16091609
public Sentry.Protocol.DeviceOrientation? Orientation { get; set; }
16101610
public int? ProcessorCount { get; set; }
1611-
public int? ProcessorFrequency { get; set; }
1611+
public float? ProcessorFrequency { get; set; }
16121612
public float? ScreenDensity { get; set; }
16131613
public int? ScreenDpi { get; set; }
16141614
public string? ScreenResolution { get; set; }

0 commit comments

Comments
 (0)