Skip to content

Switch the existing Sentry classes to use USTRUCTs #854

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
73 changes: 61 additions & 12 deletions plugin-dev/Source/Sentry/Private/SentryBreadcrumb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,87 +4,136 @@

#include "HAL/PlatformSentryBreadcrumb.h"

void USentryBreadcrumb::Initialize()
FSentryBreadcrumb::FSentryBreadcrumb() : NativeImpl(CreateSharedSentryBreadcrumb())
{
NativeImpl = CreateSharedSentryBreadcrumb();
}

void USentryBreadcrumb::SetMessage(const FString &Message)
void FSentryBreadcrumb::SetMessage(const FString &Message)
{
if (!NativeImpl)
return;

NativeImpl->SetMessage(Message);
}

FString USentryBreadcrumb::GetMessage() const
FString FSentryBreadcrumb::GetMessage() const
{
if(!NativeImpl)
return FString();

return NativeImpl->GetMessage();
}

void USentryBreadcrumb::SetType(const FString& Type)
void FSentryBreadcrumb::SetType(const FString& Type)
{
if (!NativeImpl)
return;

NativeImpl->SetType(Type);
}

FString USentryBreadcrumb::GetType() const
FString FSentryBreadcrumb::GetType() const
{
if(!NativeImpl)
return FString();

return NativeImpl->GetType();
}

void USentryBreadcrumb::SetCategory(const FString& Category)
void FSentryBreadcrumb::SetCategory(const FString& Category)
{
if (!NativeImpl)
return;

NativeImpl->SetCategory(Category);
}

FString USentryBreadcrumb::GetCategory() const
FString FSentryBreadcrumb::GetCategory() const
{
if(!NativeImpl)
return FString();

return NativeImpl->GetCategory();
}

void USentryBreadcrumb::SetData(const TMap<FString, FString>& Data)
void FSentryBreadcrumb::SetData(const TMap<FString, FString>& Data)
{
if (!NativeImpl)
return;

NativeImpl->SetData(Data);
}

TMap<FString, FString> USentryBreadcrumb::GetData() const
TMap<FString, FString> FSentryBreadcrumb::GetData() const
{
if(!NativeImpl)
return TMap<FString, FString>();

return NativeImpl->GetData();
}

void USentryBreadcrumb::SetLevel(ESentryLevel Level)
void FSentryBreadcrumb::SetLevel(ESentryLevel Level)
{
if (!NativeImpl)
return;

NativeImpl->SetLevel(Level);
}

ESentryLevel USentryBreadcrumb::GetLevel() const
ESentryLevel FSentryBreadcrumb::GetLevel() const
{
if(!NativeImpl)
return ESentryLevel::Debug;

return NativeImpl->GetLevel();
}

void USentryBreadcrumbLibrary::SetMessage(FSentryBreadcrumb& Breadcrumb, const FString& Message)
{
Breadcrumb.SetMessage(Message);
}

FString USentryBreadcrumbLibrary::GetMessage(const FSentryBreadcrumb& Breadcrumb)
{
return Breadcrumb.GetMessage();
}

void USentryBreadcrumbLibrary::SetType(FSentryBreadcrumb& Breadcrumb, const FString& Type)
{
Breadcrumb.SetType(Type);
}

FString USentryBreadcrumbLibrary::GetType(const FSentryBreadcrumb& Breadcrumb)
{
return Breadcrumb.GetType();
}

void USentryBreadcrumbLibrary::SetCategory(FSentryBreadcrumb& Breadcrumb, const FString& Category)
{
Breadcrumb.SetCategory(Category);
}

FString USentryBreadcrumbLibrary::GetCategory(const FSentryBreadcrumb& Breadcrumb)
{
return Breadcrumb.GetCategory();
}

void USentryBreadcrumbLibrary::SetData(FSentryBreadcrumb& Breadcrumb, const TMap<FString, FString>& Data)
{
Breadcrumb.SetData(Data);
}

TMap<FString, FString> USentryBreadcrumbLibrary::GetData(const FSentryBreadcrumb& Breadcrumb)
{
return Breadcrumb.GetData();
}

void USentryBreadcrumbLibrary::SetLevel(FSentryBreadcrumb& Breadcrumb, ESentryLevel Level)
{
Breadcrumb.SetLevel(Level);
}

ESentryLevel USentryBreadcrumbLibrary::GetLevel(const FSentryBreadcrumb& Breadcrumb)
{
return Breadcrumb.GetLevel();
}
14 changes: 7 additions & 7 deletions plugin-dev/Source/Sentry/Private/SentryLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ USentryUserFeedback* USentryLibrary::CreateSentryUserFeedback(const FString& Eve
return UserFeedback;
}

USentryBreadcrumb* USentryLibrary::CreateSentryBreadcrumb(const FString& Message, const FString& Type, const FString& Category,
FSentryBreadcrumb USentryLibrary::CreateSentryBreadcrumb(const FString& Message, const FString& Type, const FString& Category,
const TMap<FString, FString>& Data, ESentryLevel Level)
{
USentryBreadcrumb* Breadcrumb = USentryBreadcrumb::Create(CreateSharedSentryBreadcrumb());
FSentryBreadcrumb Breadcrumb;

Breadcrumb->SetMessage(Message);
Breadcrumb->SetCategory(Category);
Breadcrumb->SetType(Type);
Breadcrumb->SetData(Data);
Breadcrumb->SetLevel(Level);
Breadcrumb.SetMessage(Message);
Breadcrumb.SetCategory(Category);
Breadcrumb.SetType(Type);
Breadcrumb.SetData(Data);
Breadcrumb.SetLevel(Level);

return Breadcrumb;
}
Expand Down
4 changes: 2 additions & 2 deletions plugin-dev/Source/Sentry/Private/SentryScope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ void USentryScope::Initialize()
NativeImpl = CreateSharedSentryScope();
}

void USentryScope::AddBreadcrumb(USentryBreadcrumb* Breadcrumb)
void USentryScope::AddBreadcrumb(const FSentryBreadcrumb& Breadcrumb)
{
if (!NativeImpl)
return;

NativeImpl->AddBreadcrumb(Breadcrumb->GetNativeObject());
NativeImpl->AddBreadcrumb(Breadcrumb.GetNativeObject());
}

void USentryScope::ClearBreadcrumbs()
Expand Down
5 changes: 2 additions & 3 deletions plugin-dev/Source/Sentry/Private/SentrySubsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,17 +196,16 @@ ESentryCrashedLastRun USentrySubsystem::IsCrashedLastRun() const
return SubsystemNativeImpl->IsCrashedLastRun();
}

void USentrySubsystem::AddBreadcrumb(USentryBreadcrumb* Breadcrumb)
void USentrySubsystem::AddBreadcrumb(const FSentryBreadcrumb& Breadcrumb)
{
check(SubsystemNativeImpl);
check(Breadcrumb);

if (!SubsystemNativeImpl || !SubsystemNativeImpl->IsEnabled())
{
return;
}

SubsystemNativeImpl->AddBreadcrumb(Breadcrumb->GetNativeObject());
SubsystemNativeImpl->AddBreadcrumb(Breadcrumb.GetNativeObject());
}

void USentrySubsystem::AddBreadcrumbWithParams(const FString& Message, const FString& Category, const FString& Type, const TMap<FString, FString>& Data, ESentryLevel Level)
Expand Down
24 changes: 12 additions & 12 deletions plugin-dev/Source/Sentry/Private/Tests/SentryBreadcrumb.spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
#if WITH_AUTOMATION_TESTS

BEGIN_DEFINE_SPEC(SentryBreadcrumbSpec, "Sentry.SentryBreadcrumb", EAutomationTestFlags::ProductFilter | SentryApplicationContextMask)
USentryBreadcrumb* SentryBreadcrumb;
FSentryBreadcrumb SentryBreadcrumb;
END_DEFINE_SPEC(SentryBreadcrumbSpec)

void SentryBreadcrumbSpec::Define()
{
BeforeEach([this]()
{
SentryBreadcrumb = USentryBreadcrumb::Create(CreateSharedSentryBreadcrumb());
SentryBreadcrumb = FSentryBreadcrumb();
});

Describe("Breadcrumb params", [this]()
Expand All @@ -32,18 +32,18 @@ void SentryBreadcrumbSpec::Define()
TestData.Add(TEXT("Key1"), TEXT("Val1"));
TestData.Add(TEXT("Key2"), TEXT("Val2"));

SentryBreadcrumb->SetLevel(ESentryLevel::Fatal);
SentryBreadcrumb->SetMessage(TestMessage);
SentryBreadcrumb->SetType(TestType);
SentryBreadcrumb->SetCategory(TestCategory);
SentryBreadcrumb->SetData(TestData);
SentryBreadcrumb.SetLevel(ESentryLevel::Fatal);
SentryBreadcrumb.SetMessage(TestMessage);
SentryBreadcrumb.SetType(TestType);
SentryBreadcrumb.SetCategory(TestCategory);
SentryBreadcrumb.SetData(TestData);

TestEqual("Breadcrumb level", SentryBreadcrumb->GetLevel(), ESentryLevel::Fatal);
TestEqual("Breadcrumb message", SentryBreadcrumb->GetMessage(), TestMessage);
TestEqual("Breadcrumb type", SentryBreadcrumb->GetType(), TestType);
TestEqual("Breadcrumb category", SentryBreadcrumb->GetCategory(), TestCategory);
TestEqual("Breadcrumb level", SentryBreadcrumb.GetLevel(), ESentryLevel::Fatal);
TestEqual("Breadcrumb message", SentryBreadcrumb.GetMessage(), TestMessage);
TestEqual("Breadcrumb type", SentryBreadcrumb.GetType(), TestType);
TestEqual("Breadcrumb category", SentryBreadcrumb.GetCategory(), TestCategory);

TMap<FString, FString> ReceivedData = SentryBreadcrumb->GetData();
TMap<FString, FString> ReceivedData = SentryBreadcrumb.GetData();
TestEqual("Data 1", ReceivedData[TEXT("Key1")], TestData[TEXT("Key1")]);
TestEqual("Data 2", ReceivedData[TEXT("Key2")], TestData[TEXT("Key2")]);
});
Expand Down
62 changes: 46 additions & 16 deletions plugin-dev/Source/Sentry/Public/SentryBreadcrumb.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,60 +5,90 @@
#include "SentryDataTypes.h"
#include "SentryImplWrapper.h"

#include "Kismet/BlueprintFunctionLibrary.h"

#include "SentryBreadcrumb.generated.h"

class ISentryBreadcrumb;

/**
* Information to create a trail of events that happened prior to an issue.
*/
UCLASS(BlueprintType, NotBlueprintable, HideDropdown)
class SENTRY_API USentryBreadcrumb : public UObject, public TSentryImplWrapper<ISentryBreadcrumb, USentryBreadcrumb>
USTRUCT(BlueprintType)
struct SENTRY_API FSentryBreadcrumb
{
GENERATED_BODY()

public:
/** Initializes the breadcrumb. */
UFUNCTION(BlueprintCallable, Category = "Sentry")
void Initialize();
FSentryBreadcrumb();

void SetMessage(const FString& Message);
FString GetMessage() const;

void SetType(const FString& Type);
FString GetType() const;

void SetCategory(const FString& Category);
FString GetCategory() const;

void SetData(const TMap<FString, FString>& Data);
TMap<FString, FString> GetData() const;

void SetLevel(ESentryLevel Level);
ESentryLevel GetLevel() const;

/** Retrieves the underlying native implementation. */
TSharedPtr<ISentryBreadcrumb> GetNativeObject() const { return NativeImpl; }
Copy link
Collaborator

Choose a reason for hiding this comment

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

In general, it seems odd that we ever expose this. Perhaps we can remove the need for this and any public callers can use a different method? For example, we use GetNativeObject() to call sentry_value_set_stacktrace - perhaps instead we have a method on the the Sentry event called AddStacktrace and that calls the method underneath?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's a good point. There are definitely a few use cases where we can remove GetNativeObject() and route calls to underlying SDKs through our Unreal wrappers directly. I'll look into this and see if it's something we can achieve.


private:
TSharedPtr<ISentryBreadcrumb> NativeImpl;
};

/**
* Utility blueprint functions for Sentry breadcrumb.
*/
UCLASS()
class SENTRY_API USentryBreadcrumbLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()

public:
/** Sets message of the breadcrumb. */
UFUNCTION(BlueprintCallable, Category = "Sentry")
void SetMessage(const FString& Message);
static void SetMessage(UPARAM(ref) FSentryBreadcrumb& Breadcrumb, const FString& Message);

/** Gets message of the breadcrumb. */
UFUNCTION(BlueprintPure, Category = "Sentry")
FString GetMessage() const;
static FString GetMessage(const FSentryBreadcrumb& Breadcrumb);

/** Sets type of the breadcrumb. */
UFUNCTION(BlueprintCallable, Category = "Sentry")
void SetType(const FString& Type);
static void SetType(UPARAM(ref) FSentryBreadcrumb& Breadcrumb, const FString& Type);

/** Gets type of the breadcrumb. */
UFUNCTION(BlueprintPure, Category = "Sentry")
FString GetType() const;
static FString GetType(const FSentryBreadcrumb& Breadcrumb);

/** Sets category of the breadcrumb. */
UFUNCTION(BlueprintCallable, Category = "Sentry")
void SetCategory(const FString& Category);
static void SetCategory(UPARAM(ref) FSentryBreadcrumb& Breadcrumb, const FString& Category);

/** Gets category of the breadcrumb. */
UFUNCTION(BlueprintPure, Category = "Sentry")
FString GetCategory() const;
static FString GetCategory(const FSentryBreadcrumb& Breadcrumb);

/** Sets data associated with the breadcrumb. */
UFUNCTION(BlueprintCallable, Category = "Sentry")
void SetData(const TMap<FString, FString>& Data);
static void SetData(UPARAM(ref) FSentryBreadcrumb& Breadcrumb, const TMap<FString, FString>& Data);

/** Gets data associated with the breadcrumb. */
UFUNCTION(BlueprintPure, Category = "Sentry")
TMap<FString, FString> GetData() const;
static TMap<FString, FString> GetData(const FSentryBreadcrumb& Breadcrumb);

/** Sets the level of the breadcrumb. */
UFUNCTION(BlueprintCallable, Category = "Sentry")
void SetLevel(ESentryLevel Level);
static void SetLevel(UPARAM(ref) FSentryBreadcrumb& Breadcrumb, ESentryLevel Level);

/** Gets the level of the breadcrumb. */
UFUNCTION(BlueprintPure, Category = "Sentry")
ESentryLevel GetLevel() const;
static ESentryLevel GetLevel(const FSentryBreadcrumb& Breadcrumb);
};
2 changes: 1 addition & 1 deletion plugin-dev/Source/Sentry/Public/SentryLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class SENTRY_API USentryLibrary : public UBlueprintFunctionLibrary
* @param Level Level of the breadcrumb.
*/
UFUNCTION(BlueprintCallable, Category = "Sentry", Meta = (AutoCreateRefTerm = "Data"))
static USentryBreadcrumb* CreateSentryBreadcrumb(const FString& Message, const FString& Type, const FString& Category,
static FSentryBreadcrumb CreateSentryBreadcrumb(const FString& Message, const FString& Type, const FString& Category,
const TMap<FString, FString>& Data, ESentryLevel Level = ESentryLevel::Info);

/**
Expand Down
2 changes: 1 addition & 1 deletion plugin-dev/Source/Sentry/Public/SentryScope.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SENTRY_API USentryScope : public UObject, public TSentryImplWrapper<ISentr

/** Adds a breadcrumb to the current Scope. */
UFUNCTION(BlueprintCallable, Category = "Sentry")
void AddBreadcrumb(USentryBreadcrumb* Breadcrumb);
void AddBreadcrumb(const FSentryBreadcrumb& Breadcrumb);

/** Clear all breadcrumbs of the current Scope. */
UFUNCTION(BlueprintCallable, Category = "Sentry")
Expand Down
2 changes: 1 addition & 1 deletion plugin-dev/Source/Sentry/Public/SentrySubsystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class SENTRY_API USentrySubsystem : public UEngineSubsystem
* @param Breadcrumb The breadcrumb to send to Sentry.
*/
UFUNCTION(BlueprintCallable, Category = "Sentry")
void AddBreadcrumb(USentryBreadcrumb* Breadcrumb);
void AddBreadcrumb(const FSentryBreadcrumb& Breadcrumb);

/**
* Adds a breadcrumb to the current Scope.
Expand Down
Loading