diff --git a/CHANGELOG.md b/CHANGELOG.md index a8457a3e15c..c23af9be8ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## Unreleased + +### Fixes + +- Set the correct OOM event timestamp (#2394) + ## 7.31.0 ### Features diff --git a/Sources/Sentry/SentryOutOfMemoryTracker.m b/Sources/Sentry/SentryOutOfMemoryTracker.m index 5aa953956d9..3d309d0f38a 100644 --- a/Sources/Sentry/SentryOutOfMemoryTracker.m +++ b/Sources/Sentry/SentryOutOfMemoryTracker.m @@ -1,3 +1,4 @@ +#import "NSDate+SentryExtras.h" #import "SentryEvent+Private.h" #import "SentryFileManager.h" #import @@ -68,6 +69,12 @@ - (void)start self.options.maxBreadcrumbs)]; } + NSDictionary *lastBreadcrumb = event.serializedBreadcrumbs.lastObject; + if (lastBreadcrumb && [lastBreadcrumb objectForKey:@"timestamp"]) { + NSString *timestampIso8601String = [lastBreadcrumb objectForKey:@"timestamp"]; + event.timestamp = [NSDate sentry_fromIso8601String:timestampIso8601String]; + } + SentryException *exception = [[SentryException alloc] initWithValue:SentryOutOfMemoryExceptionValue type:SentryOutOfMemoryExceptionType]; diff --git a/Tests/SentryTests/Integrations/OutOfMemory/SentryOutOfMemoryTrackerTests.swift b/Tests/SentryTests/Integrations/OutOfMemory/SentryOutOfMemoryTrackerTests.swift index 686ae66da3a..fd6ad00ebd2 100644 --- a/Tests/SentryTests/Integrations/OutOfMemory/SentryOutOfMemoryTrackerTests.swift +++ b/Tests/SentryTests/Integrations/OutOfMemory/SentryOutOfMemoryTrackerTests.swift @@ -225,6 +225,9 @@ class SentryOutOfMemoryTrackerTests: NotificationCenterTestCase { fixture.fileManager.moveBreadcrumbsToPreviousBreadcrumbs() sut.start() assertOOMEventSent(expectedBreadcrumbs: 2) + + let crashEvent = fixture.client.captureCrashEventInvocations.first?.event + XCTAssertEqual(crashEvent?.timestamp, breadcrumb.timestamp) } func testAppOOM_WithOnlyHybridSdkDidBecomeActive() {