Skip to content

Commit

Permalink
Add extra event context params and and tags promotion (#183)
Browse files Browse the repository at this point in the history
* Add extra context params and and tags promotion

* Update changelog
  • Loading branch information
tustanivsky authored Dec 29, 2022
1 parent 28a4e18 commit 5bad05b
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Features

- Automatic crash capturing for UE 5.1 (Windows only) ([#175](https://github.com/getsentry/sentry-unreal/pull/175))
- Add extra event context params and and tags promotion ([#183](https://github.com/getsentry/sentry-unreal/pull/183))

### Dependencies

Expand Down
28 changes: 28 additions & 0 deletions plugin-dev/Source/Sentry/Private/SentrySubsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "Engine/World.h"
#include "Misc/EngineVersion.h"
#include "Misc/CoreDelegates.h"
#include "Misc/App.h"
#include "GenericPlatform/GenericPlatformMisc.h"

#include "Interface/SentrySubsystemInterface.h"

Expand Down Expand Up @@ -58,6 +60,7 @@ void USentrySubsystem::Initialize()
SubsystemNativeImpl->InitWithSettings(Settings);

AddDefaultContext();
PromoteTags();
ConfigureBreadcrumbs();
}

Expand Down Expand Up @@ -221,10 +224,35 @@ void USentrySubsystem::AddDefaultContext()
TMap<FString, FString> DefaultContext;
DefaultContext.Add(TEXT("Engine version"), FEngineVersion::Current().ToString(EVersionComponent::Changelist));
DefaultContext.Add(TEXT("Plugin version"), FSentryModule::Get().GetPluginVersion());
DefaultContext.Add(TEXT("Configuration"), LexToString(FApp::GetBuildConfiguration()));
DefaultContext.Add(TEXT("Target Type"), LexToString(FApp::GetBuildTargetType()));
DefaultContext.Add(TEXT("Engine mode"), FGenericPlatformMisc::GetEngineMode());
DefaultContext.Add(TEXT("Is game"), FApp::IsGame() ? TEXT("True") : TEXT("False"));
DefaultContext.Add(TEXT("Is standalone"), FApp::IsStandalone() ? TEXT("True") : TEXT("False"));
DefaultContext.Add(TEXT("Is unattended"), FApp::IsUnattended() ? TEXT("True") : TEXT("False"));
DefaultContext.Add(TEXT("Game name"), FApp::GetName());

SubsystemNativeImpl->SetContext(TEXT("Unreal Engine"), DefaultContext);
}

void USentrySubsystem::PromoteTags()
{
const USentrySettings* Settings = FSentryModule::Get().GetSettings();

if(Settings->TagsPromotion.bPromoteBuildConfiguration)
SubsystemNativeImpl->SetTag(TEXT("Configuration"), LexToString(FApp::GetBuildConfiguration()));
if(Settings->TagsPromotion.bPromoteTargetType)
SubsystemNativeImpl->SetTag(TEXT("Target Type"), LexToString(FApp::GetBuildTargetType()));
if(Settings->TagsPromotion.bPromoteEngineMode)
SubsystemNativeImpl->SetTag(TEXT("Engine Mode"), FGenericPlatformMisc::GetEngineMode());
if(Settings->TagsPromotion.bPromoteIsGame)
SubsystemNativeImpl->SetTag(TEXT("Is game"), FApp::IsGame() ? TEXT("True") : TEXT("False"));
if(Settings->TagsPromotion.bPromoteIsStandalone)
SubsystemNativeImpl->SetTag(TEXT("Is standalone"), FApp::IsStandalone() ? TEXT("True") : TEXT("False"));
if(Settings->TagsPromotion.bPromoteIsUnattended)
SubsystemNativeImpl->SetTag(TEXT("Is unattended"), FApp::IsUnattended() ? TEXT("True") : TEXT("False"));
}

void USentrySubsystem::ConfigureBreadcrumbs()
{
const USentrySettings* Settings = FSentryModule::Get().GetSettings();
Expand Down
34 changes: 34 additions & 0 deletions plugin-dev/Source/Sentry/Public/SentrySettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,36 @@ struct FAutomaticBreadcrumbs
bool bOnUserActivityStringChanged = false;
};

USTRUCT(BlueprintType)
struct FTagsPromotion
{
GENERATED_BODY()

UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = "Misc",
Meta = (DisplayName = "Build configuration", ToolTip = "Flag indicating whether the build configuration should be promoted to a captured event's tag."))
bool bPromoteBuildConfiguration = true;

UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = "Misc",
Meta = (DisplayName = "Target type", ToolTip = "Flag indicating whether the target type should be promoted to a captured event's tag."))
bool bPromoteTargetType = true;

UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = "Misc",
Meta = (DisplayName = "Engine mode", ToolTip = "Flag indicating whether the engine mode should be promoted to a captured event's tag."))
bool bPromoteEngineMode = true;

UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = "Misc",
Meta = (DisplayName = "Is game", ToolTip = "Flag indicating whether the `IsGame` parameter should be promoted to a captured event's tag."))
bool bPromoteIsGame = true;

UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = "Misc",
Meta = (DisplayName = "Is standalone", ToolTip = "Flag indicating whether the `IsStandalone` parameter should be promoted to a captured event's tag."))
bool bPromoteIsStandalone = true;

UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = "Misc",
Meta = (DisplayName = "Is unattended", ToolTip = "Flag indicating whether the `IsUnattended` parameter should be promoted to a captured event's tag."))
bool bPromoteIsUnattended = true;
};

/**
* Sentry settings used for plugin configuration.
*/
Expand Down Expand Up @@ -62,6 +92,10 @@ class SENTRY_API USentrySettings : public UObject
Meta = (DisplayName = "Automatically add breadcrumbs"))
FAutomaticBreadcrumbs AutomaticBreadcrumbs;

UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = "Misc",
Meta = (DisplayName = "Promote values to tags"))
FTagsPromotion TagsPromotion;

UPROPERTY(Config, EditAnywhere, Category = "Misc",
Meta = (DisplayName = "Enable automatic crash capturing (Windows editor, UE 5.1+)", ToolTip = "Flag indicating whether to capture crashes automatically on Windows as an alternative to Crash Reporter."))
bool EnableAutoCrashCapturing;
Expand Down
3 changes: 3 additions & 0 deletions plugin-dev/Source/Sentry/Public/SentrySubsystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,9 @@ class SENTRY_API USentrySubsystem : public UGameInstanceSubsystem
/** Adds default context data for all events captured by Sentry SDK. */
void AddDefaultContext();

/** Promote specified values to tags for all events captured by Sentry SDK. */
void PromoteTags();

/** Subscribe to specified game events in order to add corresponding breadcrumbs automatically. */
void ConfigureBreadcrumbs();

Expand Down

0 comments on commit 5bad05b

Please sign in to comment.