Skip to content

Fix invalid log file being attached to crash events on Mac/iOS #873

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

tustanivsky
Copy link
Collaborator

@tustanivsky tustanivsky commented Apr 17, 2025

This PR fixes an issue where the game log file from the current session was being attached to a captured crash event before sending it to Sentry instead of attaching the log file from the previous session in which the crash occurred.

It leverages the same approach used for screenshots (#849) by sending the log file in a separate envelope within the onCrashedLastRun handler.

Closes #302

Also, supersedes #732

@tustanivsky tustanivsky marked this pull request as ready for review April 23, 2025 06:11
Comment on lines +43 to +44
isScreenshotAttachmentEnabled = settings->AttachScreenshot;
isGameLogAttachmentEnabled = settings->EnableAutoLogAttachment;
Copy link
Contributor

@bitsandfoxes bitsandfoxes Apr 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these go on the actual options? We're starting to mix settings. with options. here. I'd really prefer the options to be the source of truth of:

  1. What options exist?
  2. What options does the SDK use.

This will also make it easier for users to browse and explore and for us to reason through the SDK's behaviour.

Copy link
Collaborator Author

@tustanivsky tustanivsky Apr 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two flags are cached separately here since they don't necessarily have a direct representation in Cocoa SDK options:

  • isGameLogAttachmentEnabled is Unreal-specific feature
  • isScreenshotAttachmentEnabled can't be just set via options.attachScreenshot as it's an iOS-only thing in sentry-cocoa

Accessing them using FSentryModule::Get().GetSettings() could cause unwanted ensures when called from a non-game thread.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

attachScreenshot

This option (with this name) also exists on Android, .NET, Godot, Unity.

Copy link
Collaborator Author

@tustanivsky tustanivsky Apr 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be missing the concern here. settings properties are passed to the Cocoa SDK’s options within the startWithConfigureOptions block right after we make copies of these flags here (mainly for convenience as we use them in a few other places beyond initialization). Or is this about the naming?

Copy link
Member

@bruno-garcia bruno-garcia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm concerned that we have no tests for this. Do we have iOS device tests we could verify this change and avoid regressions?

@@ -9,6 +9,7 @@
### Fixes

- Fix warnings caused by deprecated Cocoa SDK API usages ([#868](https://github.com/getsentry/sentry-unreal/pull/868))
- Fix invalid log file being attached to crash events on Mac/iOS ([#873](https://github.com/getsentry/sentry-unreal/pull/873))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The section on the changelog is already "Fixes" so we could (going forward, from the next release perhaps) avoid starting the message with Fix.

Personally I'd be more interested in which platform the fix relates to. So this is a iOS/Mac, could be:

  • iOS/macOS: Correct log file now attached to crashes. Since crashes are sent on restart, the SDK now looks at the previous run's log files to attach. Leaving the current run's log file untouched

Or something like that.

Comment on lines +43 to +44
isScreenshotAttachmentEnabled = settings->AttachScreenshot;
isGameLogAttachmentEnabled = settings->EnableAutoLogAttachment;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

attachScreenshot

This option (with this name) also exists on Android, .NET, Godot, Unity.

}

TSharedPtr<ISentryId> FAppleSentrySubsystem::CaptureEventWithScope(TSharedPtr<ISentryEvent> event, const FSentryScopeDelegate& onConfigureScope)
{
TSharedPtr<SentryEventApple> eventIOS = StaticCastSharedPtr<SentryEventApple>(event);

SentryId* id = [SENTRY_APPLE_CLASS(SentrySDK) captureEvent:eventIOS->GetNativeObject() withScopeBlock:^(SentryScope* scope) {
if(isGameLogAttachmentEnabled) {
const FString logFilePath = GetGameLogPath();
SentryAttachment* logAttachment = [[SENTRY_APPLE_CLASS(SentryAttachment) alloc] initWithPath:logFilePath.GetNSString()];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to diff the 3 versions of this snippet in this PR but they all seem the same?

If we're changing things would you want them all to be consistent?
I think it's better to throw this into a function, add some debug logging in there (central point) for example

@tustanivsky
Copy link
Collaborator Author

I'm concerned that we have no tests for this. Do we have iOS device tests we could verify this change and avoid regressions?

At the moment we don’t have a way to automate testing on mobile so manual testing is our only option for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crashes captured on Android/iOS have incorrect game log file attached
3 participants