Skip to content

Commit

Permalink
Fix: Set the correct OOM event timestamp (#2394)
Browse files Browse the repository at this point in the history
Use the last breadcrumb's timestamp as the OOM event timestamp
  • Loading branch information
kevinrenskers authored Nov 16, 2022
1 parent 3a1d58d commit 8442084
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Fixes

- Set the correct OOM event timestamp (#2394)

## 7.31.0

### Features
Expand Down
7 changes: 7 additions & 0 deletions Sources/Sentry/SentryOutOfMemoryTracker.m
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#import "NSDate+SentryExtras.h"
#import "SentryEvent+Private.h"
#import "SentryFileManager.h"
#import <Foundation/Foundation.h>
Expand Down Expand Up @@ -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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 8442084

Please sign in to comment.