Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always send memory stats for transactions #2936

Merged
merged 4 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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