-
-
Notifications
You must be signed in to change notification settings - Fork 47
Fix automatic game log attachment (Android) #309
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
Changes from all commits
935cc7c
17030f8
748bcfa
397a063
b29d9ec
bd9d114
293de54
5fd5161
a7f0c0c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,8 +3,6 @@ | |
package io.sentry.unreal; | ||
|
||
import android.app.Activity; | ||
import android.content.pm.PackageInfo; | ||
import android.content.pm.PackageManager; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
|
@@ -13,6 +11,7 @@ | |
|
||
import io.sentry.Attachment; | ||
import io.sentry.Breadcrumb; | ||
import io.sentry.Hint; | ||
import io.sentry.IHub; | ||
import io.sentry.Scope; | ||
import io.sentry.ScopeCallback; | ||
|
@@ -33,6 +32,7 @@ public static void init( | |
final String releaseName, | ||
final String environment, | ||
final String gameLogPath, | ||
final String gameBackupLogPath, | ||
final boolean enableAutoSessionTracking, | ||
final long sessionTimeout, | ||
final boolean enableStackTrace) { | ||
|
@@ -45,15 +45,24 @@ public void configure(SentryAndroidOptions options) { | |
options.setEnableAutoSessionTracking(enableAutoSessionTracking); | ||
options.setSessionTrackingIntervalMillis(sessionTimeout); | ||
options.setAttachStacktrace(enableStackTrace); | ||
} | ||
}); | ||
|
||
Sentry.configureScope(new ScopeCallback() { | ||
@Override | ||
public void run(@NonNull Scope scope) { | ||
if(!gameLogPath.isEmpty()) { | ||
scope.addAttachment(new Attachment(gameLogPath)); | ||
} | ||
options.setBeforeSend(new SentryOptions.BeforeSendCallback() { | ||
@Override | ||
public SentryEvent execute(SentryEvent event, Hint hint) { | ||
if(event.isCrashed() && event.isErrored()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't that mean that if the app crashed in the run before the gamelogs from the current run won't be part of any current events? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, after sending the crash event on app startup all subsequent events should be treated as usual with a current session's game log attached. |
||
{ | ||
if(!gameBackupLogPath.isEmpty()) { | ||
hint.addAttachment(new Attachment(gameBackupLogPath)); | ||
} | ||
} | ||
else | ||
{ | ||
if(!gameLogPath.isEmpty()) { | ||
hint.addAttachment(new Attachment(gameLogPath)); | ||
} | ||
} | ||
return event; | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) 2023 Sentry. All Rights Reserved. | ||
|
||
#include "SentryFileUtils.h" | ||
#include "SentryDefines.h" | ||
|
||
#include "HAL/FileManager.h" | ||
#include "GenericPlatform/GenericPlatformOutputDevices.h" | ||
#include "Misc/Paths.h" | ||
|
||
struct FSentrySortFileByDatePredicate | ||
{ | ||
bool operator()(const FString& A, const FString& B) const | ||
{ | ||
const FDateTime TimestampA = IFileManager::Get().GetTimeStamp(*A); | ||
const FDateTime TimestampB = IFileManager::Get().GetTimeStamp(*B); | ||
return TimestampB < TimestampA; | ||
} | ||
}; | ||
|
||
FString SentryFileUtils::GetGameLogPath() | ||
{ | ||
return IFileManager::Get().ConvertToAbsolutePathForExternalAppForRead(*FGenericPlatformOutputDevices::GetAbsoluteLogFilename()); | ||
} | ||
|
||
FString SentryFileUtils::GetGameLogBackupPath() | ||
{ | ||
TArray<FString> GameLogBackupFiles; | ||
IFileManager::Get().FindFiles(GameLogBackupFiles, *FString::Printf(TEXT("%s*-backup-*.*"), *FPaths::ProjectLogDir()), true, false); | ||
|
||
if(GameLogBackupFiles.IsEmpty()) | ||
{ | ||
UE_LOG(LogSentrySdk, Log, TEXT("There are no game log backups available.")); | ||
return FString(""); | ||
} | ||
|
||
for (int i = 0; i < GameLogBackupFiles.Num(); ++i) | ||
{ | ||
FString GameLogFullPath = IFileManager::Get().ConvertToAbsolutePathForExternalAppForRead(*(FPaths::ProjectLogDir() / GameLogBackupFiles[i])); | ||
GameLogBackupFiles[i] = GameLogFullPath; | ||
} | ||
|
||
GameLogBackupFiles.Sort(FSentrySortFileByDatePredicate()); | ||
|
||
return GameLogBackupFiles[0]; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright (c) 2023 Sentry. All Rights Reserved. | ||
|
||
#pragma once | ||
|
||
#include "CoreMinimal.h" | ||
|
||
class SentryFileUtils | ||
{ | ||
public: | ||
static FString GetGameLogPath(); | ||
static FString GetGameLogBackupPath(); | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely sure how that works underneath but can that callback be overwritten by users?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't expose any APIs allowing users to do that, so it should be safe to set the
beforeSend
hook like this.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Considering that we want to expose that API in the future, we could add this as an event-processor/integration instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think it should be feasible.