Advanced Configuration

Basic attributes can be reconfigured by providing a special game data to the crash reporter by setting the __sentry game data key to a JSON value containing Sentry specific attributes:

Copied
#include "GenericPlatform/GenericPlatformCrashContext.h"
#include "Dom/Json.h"

void ConfigureCrashReporter()
{
    TSharedPtr<FJsonObject> config = MakeShareable(new FJsonObject);

    // sentry specific attributes go here
    config->SetStringField("release", "my-project-name@2.3.12");
    config->SetStringField("environment", "production");
    
    TSharedPtr<FJsonObject> tags = MakeShareable(new FJsonObject);
    tags->SetStringField("tag1", "value1");
    tags->SetStringField("tag2", "value2");
    config->SetObjectField("tags", tags);
    
    TSharedPtr<FJsonObject> user = MakeShareable(new FJsonObject);
    user->SetStringField("ip_address", "{{auto}}");
    user->SetStringField("email", "jane.doe@example.com");
    config->SetObjectField("user", user);

    FString jsonConfig;
    TSharedRef<TJsonWriter<>> jsonWriter = TJsonWriterFactory<>::Create(&jsonConfig);
    FJsonSerializer::Serialize(config.ToSharedRef(), jsonWriter);

    FGenericCrashContext::SetGameData(TEXT("__sentry"), jsonConfig);
}

You need to call the ConfigureCrashReporter some time after your game starts up. Any event attribute can be set.

Depending on the version of Unreal Engine you are using, you may have to add JSON support to the build script (MyProject.build.cs):

Copied
PublicDependencyModuleNames.AddRange(new string[] { ..., "Json" });