Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Features

- The SDK now also reports the currently allocated memory when reporting an event or transaction. ([#2398](https://github.com/getsentry/sentry-unity/pull/2398))

### Fixes

- Resolved possible startup crashes on Android VR platforms like the Oculus Quest. The SDK no longer natively subscribes to interaction hooks for automatic tracing and breadcrumb creation. ([#2393](https://github.com/getsentry/sentry-unity/pull/2393))
Expand Down
11 changes: 11 additions & 0 deletions src/Sentry.Unity/UnityEventProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ private void SetEventContext(IEventLike sentryEvent)
{
try
{
PopulateApp(sentryEvent.Contexts.App);
PopulateDevice(sentryEvent.Contexts.Device);
// Populating the SDK Integrations here (for now) instead of UnityScopeIntegration because it cannot be guaranteed
// that it got added last or that there was not an integration added at a later point
Expand All @@ -49,6 +50,16 @@ private void SetEventContext(IEventLike sentryEvent)
}
}

private void PopulateApp(App app)
{
var totalAllocatedMemory = UnityEngine.Profiling.Profiler.GetTotalAllocatedMemoryLong();
// The Profiler returns '0' if not available. See https://docs.unity3d.com/ScriptReference/Profiling.Profiler.GetTotalAllocatedMemoryLong.html
if (totalAllocatedMemory > 0)
{
app.Memory = totalAllocatedMemory;
}
}

private void PopulateDevice(Device device)
{
if (!MainThreadData.IsMainThread())
Expand Down
30 changes: 30 additions & 0 deletions test/Sentry.Unity.Tests/UnityEventScopeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ public void SentrySdkCaptureEvent(bool captureOnUiThread)
Assert.AreEqual(systemInfo.DeviceModel!.Value, @event.Contexts.Device.Model);
Assert.AreEqual(systemInfo.DeviceUniqueIdentifier!.Value, @event.Contexts.Device.DeviceUniqueIdentifier);
Assert.AreEqual(systemInfo.IsDebugBuild!.Value ? "debug" : "release", @event.Contexts.App.BuildType);
Assert.IsNotNull(@event.Contexts.App.Memory);
Assert.Greater(@event.Contexts.App.Memory, 0);

@event.Contexts.TryGetValue(Unity.Protocol.Unity.Type, out var unityProtocolObject);
var unityContext = unityProtocolObject as Unity.Protocol.Unity;
Expand Down Expand Up @@ -276,6 +278,34 @@ public void AppProtocol_Assigned()
Assert.IsNotNull(scope.Contexts.App.BuildType);
}

[Test]
public void AppMemory_SetByEventProcessor()
{
// arrange
var unityEventProcessor = new UnityEventProcessor(_sentryOptions);
var sentryEvent = new SentryEvent();

// act
unityEventProcessor.Process(sentryEvent);

// assert
Assert.IsNotNull(sentryEvent.Contexts.App.Memory);
}

[Test]
public void AppMemory_SetByEventProcessorForTransactions()
{
// arrange
var unityEventProcessor = new UnityEventProcessor(_sentryOptions);
var transaction = new SentryTransaction("test-transaction", "test-operation");

// act
unityEventProcessor.Process(transaction);

// assert
Assert.IsNotNull(transaction.Contexts.App.Memory);
}

[Test]
public void AppProtocol_AppNameIsApplicationName()
{
Expand Down
Loading