Skip to content

Commit 3df3cb3

Browse files
authored
Always send memory stats for transactions (#2936)
1 parent 081ee0b commit 3df3cb3

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
- Add `sendModules` option for disable sending modules ([#2926](https://github.com/getsentry/sentry-java/pull/2926))
88
- Send `db.system` and `db.name` in span data for androidx.sqlite spans ([#2928](https://github.com/getsentry/sentry-java/pull/2928))
99

10+
### Fixes
11+
12+
- Always send memory stats for transactions ([#2936](https://github.com/getsentry/sentry-java/pull/2936))
13+
- This makes it possible to query transactions by the `device.class` tag on Sentry
14+
1015
### Dependencies
1116

1217
- Bump Gradle from v8.2.1 to v8.3.0 ([#2900](https://github.com/getsentry/sentry-java/pull/2900))

sentry-android-core/src/main/java/io/sentry/android/core/DeviceInfoUtil.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public final class DeviceInfoUtil {
4747
private final @Nullable ContextUtils.SideLoadedInfo sideLoadedInfo;
4848
private final @NotNull OperatingSystem os;
4949

50+
private final @Nullable Long totalMem;
51+
5052
public DeviceInfoUtil(
5153
final @NotNull Context context, final @NotNull SentryAndroidOptions options) {
5254
this.context = context;
@@ -59,6 +61,13 @@ public DeviceInfoUtil(
5961
isEmulator = buildInfoProvider.isEmulator();
6062
sideLoadedInfo =
6163
ContextUtils.retrieveSideLoadedInfo(context, options.getLogger(), buildInfoProvider);
64+
final @Nullable ActivityManager.MemoryInfo memInfo =
65+
ContextUtils.getMemInfo(context, options.getLogger());
66+
if (memInfo != null) {
67+
totalMem = getMemorySize(memInfo);
68+
} else {
69+
totalMem = null;
70+
}
6271
}
6372

6473
@NotNull
@@ -132,6 +141,8 @@ public Device collectDeviceInformation(
132141
device.setProcessorCount(cpuFrequencies.size());
133142
}
134143

144+
device.setMemorySize(totalMem);
145+
135146
// setting such values require IO hence we don't run for transactions
136147
if (collectDeviceIO && options.isCollectAdditionalContext()) {
137148
setDeviceIO(device, collectDynamicData);
@@ -194,15 +205,10 @@ private void setDeviceIO(final @NotNull Device device, final boolean includeDyna
194205

195206
final @Nullable ActivityManager.MemoryInfo memInfo =
196207
ContextUtils.getMemInfo(context, options.getLogger());
197-
if (memInfo != null) {
208+
if (memInfo != null && includeDynamicData) {
198209
// in bytes
199-
device.setMemorySize(getMemorySize(memInfo));
200-
if (includeDynamicData) {
201-
device.setFreeMemory(memInfo.availMem);
202-
device.setLowMemory(memInfo.lowMemory);
203-
}
204-
// there are runtime.totalMemory() and runtime.freeMemory(), but I kept the same for
205-
// compatibility
210+
device.setFreeMemory(memInfo.availMem);
211+
device.setLowMemory(memInfo.lowMemory);
206212
}
207213

208214
// this way of getting the size of storage might be problematic for storages bigger than 2GB

sentry-android-core/src/test/java/io/sentry/android/core/DeviceInfoUtilTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class DeviceInfoUtilTest {
3434
}
3535

3636
@Test
37-
fun `provides os and sideloaded info`() {
37+
fun `provides os, memory and sideloaded info`() {
3838
val deviceInfoUtil = DeviceInfoUtil.getInstance(context, SentryAndroidOptions())
3939

4040
val os = deviceInfoUtil.operatingSystem
@@ -48,6 +48,7 @@ class DeviceInfoUtilTest {
4848
assertNotNull(sideLoadedInfo.isSideLoaded)
4949

5050
assertNotNull(deviceInfo.isSimulator)
51+
assertNotNull(deviceInfo.memorySize)
5152
}
5253

5354
@Test
@@ -106,7 +107,6 @@ class DeviceInfoUtilTest {
106107
val deviceInfoUtil = DeviceInfoUtil.getInstance(context, options)
107108
val deviceInfo = deviceInfoUtil.collectDeviceInformation(false, false)
108109

109-
assertNull(deviceInfo.memorySize)
110110
assertNull(deviceInfo.storageSize)
111111
assertNull(deviceInfo.freeStorage)
112112
}

0 commit comments

Comments
 (0)