Skip to content

Commit 52348cb

Browse files
authored
feat: Added app_memory to Context.App (#4707)
1 parent 3bfb2ca commit 52348cb

File tree

7 files changed

+119
-87
lines changed

7 files changed

+119
-87
lines changed

CHANGELOG.md

Lines changed: 101 additions & 87 deletions
Large diffs are not rendered by default.

src/Sentry/Protocol/App.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ public sealed class App : ISentryJsonSerializable, ICloneable<App>, IUpdatable<A
5454
/// </summary>
5555
public string? Build { get; set; }
5656

57+
/// <summary>
58+
/// Amount of memory used by the application in bytes.
59+
/// </summary>
60+
public long? Memory { get; set; }
61+
5762
/// <summary>
5863
/// A flag indicating whether the app is in foreground or not. An app is in foreground when it's visible to the user.
5964
/// </summary>
@@ -74,6 +79,7 @@ App ICloneable<App>.Clone()
7479
Name = Name,
7580
Version = Version,
7681
Build = Build,
82+
Memory = Memory,
7783
InForeground = InForeground
7884
};
7985

@@ -100,6 +106,7 @@ void IUpdatable<App>.UpdateFrom(App source)
100106
Name ??= source.Name;
101107
Version ??= source.Version;
102108
Build ??= source.Build;
109+
Memory ??= source.Memory;
103110
InForeground ??= source.InForeground;
104111
}
105112

@@ -116,6 +123,7 @@ public void WriteTo(Utf8JsonWriter writer, IDiagnosticLogger? _)
116123
writer.WriteStringIfNotWhiteSpace("app_name", Name);
117124
writer.WriteStringIfNotWhiteSpace("app_version", Version);
118125
writer.WriteStringIfNotWhiteSpace("app_build", Build);
126+
writer.WriteNumberIfNotNull("app_memory", Memory);
119127
writer.WriteBooleanIfNotNull("in_foreground", InForeground);
120128

121129
writer.WriteEndObject();
@@ -133,6 +141,7 @@ public static App FromJson(JsonElement json)
133141
var name = json.GetPropertyOrNull("app_name")?.GetString();
134142
var version = json.GetPropertyOrNull("app_version")?.GetString();
135143
var build = json.GetPropertyOrNull("app_build")?.GetString();
144+
var memory = json.GetPropertyOrNull("app_memory")?.GetInt64();
136145
var inForeground = json.GetPropertyOrNull("in_foreground")?.GetBoolean();
137146

138147
return new App
@@ -144,6 +153,7 @@ public static App FromJson(JsonElement json)
144153
Name = name,
145154
Version = version,
146155
Build = build,
156+
Memory = memory,
147157
InForeground = inForeground
148158
};
149159
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,6 +1676,7 @@ namespace Sentry.Protocol
16761676
public string? Hash { get; set; }
16771677
public string? Identifier { get; set; }
16781678
public bool? InForeground { get; set; }
1679+
public long? Memory { get; set; }
16791680
public string? Name { get; set; }
16801681
public System.DateTimeOffset? StartTime { get; set; }
16811682
public string? Version { get; set; }

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,6 +1676,7 @@ namespace Sentry.Protocol
16761676
public string? Hash { get; set; }
16771677
public string? Identifier { get; set; }
16781678
public bool? InForeground { get; set; }
1679+
public long? Memory { get; set; }
16791680
public string? Name { get; set; }
16801681
public System.DateTimeOffset? StartTime { get; set; }
16811682
public string? Version { get; set; }

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,6 +1676,7 @@ namespace Sentry.Protocol
16761676
public string? Hash { get; set; }
16771677
public string? Identifier { get; set; }
16781678
public bool? InForeground { get; set; }
1679+
public long? Memory { get; set; }
16791680
public string? Name { get; set; }
16801681
public System.DateTimeOffset? StartTime { get; set; }
16811682
public string? Version { get; set; }

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,6 +1647,7 @@ namespace Sentry.Protocol
16471647
public string? Hash { get; set; }
16481648
public string? Identifier { get; set; }
16491649
public bool? InForeground { get; set; }
1650+
public long? Memory { get; set; }
16501651
public string? Name { get; set; }
16511652
public System.DateTimeOffset? StartTime { get; set; }
16521653
public string? Version { get; set; }

test/Sentry.Tests/Protocol/Context/AppTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public void SerializeObject_AllPropertiesSetToNonDefault_SerializesValidObject()
2020
Hash = "93fd0e9a",
2121
Name = "Sentry.Test.App",
2222
StartTime = DateTimeOffset.MaxValue,
23+
Memory = 123456789,
2324
InForeground = true
2425
};
2526

@@ -41,6 +42,7 @@ public void Clone_CopyValues()
4142
Name = "name",
4243
StartTime = DateTimeOffset.UtcNow,
4344
Version = "version",
45+
Memory = 987654321,
4446
InForeground = false
4547
};
4648

@@ -53,6 +55,7 @@ public void Clone_CopyValues()
5355
Assert.Equal(sut.Name, clone.Name);
5456
Assert.Equal(sut.StartTime, clone.StartTime);
5557
Assert.Equal(sut.Version, clone.Version);
58+
Assert.Equal(sut.Memory, clone.Memory);
5659
Assert.Equal(sut.InForeground, clone.InForeground);
5760
}
5861

@@ -75,6 +78,7 @@ public static IEnumerable<object[]> TestCases()
7578
yield return new object[] { (new App { StartTime = DateTimeOffset.MaxValue }, """{"type":"app","app_start_time":"9999-12-31T23:59:59.9999999+00:00"}""") };
7679
yield return new object[] { (new App { Version = "some version" }, """{"type":"app","app_version":"some version"}""") };
7780
yield return new object[] { (new App { Identifier = "some identifier" }, """{"type":"app","app_identifier":"some identifier"}""") };
81+
yield return new object[] { (new App { Memory = 12345 }, """{"type":"app","app_memory":12345}""") };
7882
yield return new object[] { (new App { InForeground = true }, """{"type":"app","in_foreground":true}""") };
7983
}
8084
}

0 commit comments

Comments
 (0)