Skip to content

Commit

Permalink
Merge 6240f81 into 081ee0b
Browse files Browse the repository at this point in the history
  • Loading branch information
romtsn committed Sep 13, 2023
2 parents 081ee0b + 6240f81 commit 8d25c9c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 28 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 @@ -132,9 +132,20 @@ public Device collectDeviceInformation(
device.setProcessorCount(cpuFrequencies.size());
}

final @Nullable ActivityManager.MemoryInfo memInfo =
ContextUtils.getMemInfo(context, options.getLogger());
if (memInfo != null) {
// in bytes
device.setMemorySize(getMemorySize(memInfo));
if (collectDynamicData) {
device.setFreeMemory(memInfo.availMem);
device.setLowMemory(memInfo.lowMemory);
}
}

// setting such values require IO hence we don't run for transactions
if (collectDeviceIO && options.isCollectAdditionalContext()) {
setDeviceIO(device, collectDynamicData);
setDeviceIO(device);
}

return device;
Expand Down Expand Up @@ -171,7 +182,7 @@ public ContextUtils.SideLoadedInfo getSideLoadedInfo() {
return sideLoadedInfo;
}

private void setDeviceIO(final @NotNull Device device, final boolean includeDynamicData) {
private void setDeviceIO(final @NotNull Device device) {
final Intent batteryIntent = getBatteryIntent();
if (batteryIntent != null) {
device.setBatteryLevel(getBatteryLevel(batteryIntent));
Expand All @@ -192,19 +203,6 @@ private void setDeviceIO(final @NotNull Device device, final boolean includeDyna
}
device.setOnline(connected);

final @Nullable ActivityManager.MemoryInfo memInfo =
ContextUtils.getMemInfo(context, options.getLogger());
if (memInfo != null) {
// 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
}

// this way of getting the size of storage might be problematic for storages bigger than 2GB
// check the use of
// https://developer.android.com/reference/java/io/File.html#getFreeSpace%28%29
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,6 @@ class DeviceInfoUtilTest {
assertNotNull(deviceInfo.freeStorage)
}

@Test
fun `does not include device io data when disabled`() {
val options = SentryAndroidOptions().apply {
isCollectAdditionalContext = true
}
val deviceInfoUtil = DeviceInfoUtil.getInstance(context, options)
val deviceInfo = deviceInfoUtil.collectDeviceInformation(false, false)

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

@Test
fun `does include dynamic data when enabled`() {
val options = SentryAndroidOptions().apply {
Expand Down

0 comments on commit 8d25c9c

Please sign in to comment.