Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
10 changes: 10 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,15 @@ private void SetEventContext(IEventLike sentryEvent)
}
}

private void PopulateApp(App app)
{
var totalAllocatedMemory = UnityEngine.Profiling.Profiler.GetTotalAllocatedMemoryLong();
if (totalAllocatedMemory > 0)
{
app.Memory = totalAllocatedMemory;
}
}

private void PopulateDevice(Device device)
{
if (!MainThreadData.IsMainThread())
Expand Down
32 changes: 32 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,36 @@ 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);
Assert.Greater(sentryEvent.Contexts.App.Memory, 0);
}

[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);
Assert.Greater(transaction.Contexts.App.Memory, 0);
}

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