Skip to content

Commit

Permalink
Always send memory stats for transactions (#2936)
Browse files Browse the repository at this point in the history
  • Loading branch information
romtsn authored Sep 13, 2023
1 parent 081ee0b commit 3df3cb3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
- Add `sendModules` option for disable sending modules ([#2926](https://github.com/getsentry/sentry-java/pull/2926))
- Send `db.system` and `db.name` in span data for androidx.sqlite spans ([#2928](https://github.com/getsentry/sentry-java/pull/2928))

### Fixes

- Always send memory stats for transactions ([#2936](https://github.com/getsentry/sentry-java/pull/2936))
- This makes it possible to query transactions by the `device.class` tag on Sentry

### Dependencies

- Bump Gradle from v8.2.1 to v8.3.0 ([#2900](https://github.com/getsentry/sentry-java/pull/2900))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public final class DeviceInfoUtil {
private final @Nullable ContextUtils.SideLoadedInfo sideLoadedInfo;
private final @NotNull OperatingSystem os;

private final @Nullable Long totalMem;

public DeviceInfoUtil(
final @NotNull Context context, final @NotNull SentryAndroidOptions options) {
this.context = context;
Expand All @@ -59,6 +61,13 @@ public DeviceInfoUtil(
isEmulator = buildInfoProvider.isEmulator();
sideLoadedInfo =
ContextUtils.retrieveSideLoadedInfo(context, options.getLogger(), buildInfoProvider);
final @Nullable ActivityManager.MemoryInfo memInfo =
ContextUtils.getMemInfo(context, options.getLogger());
if (memInfo != null) {
totalMem = getMemorySize(memInfo);
} else {
totalMem = null;
}
}

@NotNull
Expand Down Expand Up @@ -132,6 +141,8 @@ public Device collectDeviceInformation(
device.setProcessorCount(cpuFrequencies.size());
}

device.setMemorySize(totalMem);

// setting such values require IO hence we don't run for transactions
if (collectDeviceIO && options.isCollectAdditionalContext()) {
setDeviceIO(device, collectDynamicData);
Expand Down Expand Up @@ -194,15 +205,10 @@ private void setDeviceIO(final @NotNull Device device, final boolean includeDyna

final @Nullable ActivityManager.MemoryInfo memInfo =
ContextUtils.getMemInfo(context, options.getLogger());
if (memInfo != null) {
if (memInfo != null && includeDynamicData) {
// in bytes
device.setMemorySize(getMemorySize(memInfo));
if (includeDynamicData) {
device.setFreeMemory(memInfo.availMem);
device.setLowMemory(memInfo.lowMemory);
}
// there are runtime.totalMemory() and runtime.freeMemory(), but I kept the same for
// compatibility
device.setFreeMemory(memInfo.availMem);
device.setLowMemory(memInfo.lowMemory);
}

// this way of getting the size of storage might be problematic for storages bigger than 2GB
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class DeviceInfoUtilTest {
}

@Test
fun `provides os and sideloaded info`() {
fun `provides os, memory and sideloaded info`() {
val deviceInfoUtil = DeviceInfoUtil.getInstance(context, SentryAndroidOptions())

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

assertNotNull(deviceInfo.isSimulator)
assertNotNull(deviceInfo.memorySize)
}

@Test
Expand Down Expand Up @@ -106,7 +107,6 @@ class DeviceInfoUtilTest {
val deviceInfoUtil = DeviceInfoUtil.getInstance(context, options)
val deviceInfo = deviceInfoUtil.collectDeviceInformation(false, false)

assertNull(deviceInfo.memorySize)
assertNull(deviceInfo.storageSize)
assertNull(deviceInfo.freeStorage)
}
Expand Down

0 comments on commit 3df3cb3

Please sign in to comment.