From 96c0e9a7b481eb9be534c077e8ca13b5daa3d20a Mon Sep 17 00:00:00 2001 From: Ivan Tustanivskyi Date: Wed, 20 Aug 2025 17:27:13 +0200 Subject: [PATCH 1/6] Add reading DSN from env variable --- .../Source/Sentry/Private/SentrySettings.cpp | 20 ++++++++++++++++++- .../Source/Sentry/Private/SentrySubsystem.cpp | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/plugin-dev/Source/Sentry/Private/SentrySettings.cpp b/plugin-dev/Source/Sentry/Private/SentrySettings.cpp index ad983f838..2489decd2 100644 --- a/plugin-dev/Source/Sentry/Private/SentrySettings.cpp +++ b/plugin-dev/Source/Sentry/Private/SentrySettings.cpp @@ -84,7 +84,25 @@ void USentrySettings::PostEditChangeProperty(FPropertyChangedEvent& PropertyChan FString USentrySettings::GetEffectiveDsn() const { - return GIsEditor && !EditorDsn.IsEmpty() ? EditorDsn : Dsn; + if (GIsEditor && !EditorDsn.IsEmpty()) + { + return EditorDsn; + } + + if (!Dsn.IsEmpty()) + { + return Dsn; + } + + const FString& EnvironmentDsn = FPlatformMisc::GetEnvironmentVariable(TEXT("SENTRY_DSN")); + if (!EnvironmentDsn.IsEmpty()) + { + UE_LOG(LogSentrySdk, Log, TEXT("DSN is not set in plugin settings - using SENTRY_DSN environment variable instead.")); + return EnvironmentDsn; + } + + UE_LOG(LogSentrySdk, Log, TEXT("DSN is not configured.")); + return FString(); } FString USentrySettings::GetFormattedReleaseName() diff --git a/plugin-dev/Source/Sentry/Private/SentrySubsystem.cpp b/plugin-dev/Source/Sentry/Private/SentrySubsystem.cpp index 0abee39c1..d9f2eefc1 100644 --- a/plugin-dev/Source/Sentry/Private/SentrySubsystem.cpp +++ b/plugin-dev/Source/Sentry/Private/SentrySubsystem.cpp @@ -77,7 +77,7 @@ void USentrySubsystem::Initialize() const USentrySettings* Settings = FSentryModule::Get().GetSettings(); check(Settings); - if (Settings->Dsn.IsEmpty()) + if (Settings->GetEffectiveDsn().IsEmpty()) { UE_LOG(LogSentrySdk, Warning, TEXT("Sentry requires minimal configuration for its initialization - please provide the DSN in plugin settings.")); return; From b8fbfd9395b2513fc2cb8b531aa25d7bac2093fb Mon Sep 17 00:00:00 2001 From: Ivan Tustanivskyi Date: Mon, 25 Aug 2025 10:03:54 +0300 Subject: [PATCH 2/6] Update DSN option comment --- plugin-dev/Source/Sentry/Private/SentrySettings.cpp | 6 +++--- plugin-dev/Source/Sentry/Public/SentrySettings.h | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/plugin-dev/Source/Sentry/Private/SentrySettings.cpp b/plugin-dev/Source/Sentry/Private/SentrySettings.cpp index 2489decd2..530167681 100644 --- a/plugin-dev/Source/Sentry/Private/SentrySettings.cpp +++ b/plugin-dev/Source/Sentry/Private/SentrySettings.cpp @@ -94,11 +94,11 @@ FString USentrySettings::GetEffectiveDsn() const return Dsn; } - const FString& EnvironmentDsn = FPlatformMisc::GetEnvironmentVariable(TEXT("SENTRY_DSN")); - if (!EnvironmentDsn.IsEmpty()) + const FString& EnvVarDsn = FPlatformMisc::GetEnvironmentVariable(TEXT("SENTRY_DSN")); + if (!EnvVarDsn.IsEmpty()) { UE_LOG(LogSentrySdk, Log, TEXT("DSN is not set in plugin settings - using SENTRY_DSN environment variable instead.")); - return EnvironmentDsn; + return EnvVarDsn; } UE_LOG(LogSentrySdk, Log, TEXT("DSN is not configured.")); diff --git a/plugin-dev/Source/Sentry/Public/SentrySettings.h b/plugin-dev/Source/Sentry/Public/SentrySettings.h index 83d57f080..e4bb61f49 100644 --- a/plugin-dev/Source/Sentry/Public/SentrySettings.h +++ b/plugin-dev/Source/Sentry/Public/SentrySettings.h @@ -376,6 +376,7 @@ class SENTRY_API USentrySettings : public UObject * Gets the effective DSN based on current execution context. * * @return Editor DSN when running in the editor and one is set; otherwise, falls back to the default DSN. + * If neither is provided, the SDK will attempt to read it from the SENTRY_DSN environment variable. */ FString GetEffectiveDsn() const; From 24820b20f7f829d6d311ff21e1d9a0e7096b8bca Mon Sep 17 00:00:00 2001 From: Ivan Tustanivskyi Date: Mon, 25 Aug 2025 12:08:35 +0300 Subject: [PATCH 3/6] Add reading environment and release from env vars --- .../Android/AndroidSentrySubsystem.cpp | 4 +- .../Private/Apple/AppleSentrySubsystem.cpp | 4 +- .../GenericPlatformSentrySubsystem.cpp | 5 +- .../Private/Linux/LinuxSentrySubsystem.cpp | 2 +- .../Microsoft/MicrosoftSentrySubsystem.cpp | 4 +- .../Source/Sentry/Private/SentrySettings.cpp | 71 ++++++++++++++----- .../Source/Sentry/Public/SentrySettings.h | 24 ++++++- 7 files changed, 83 insertions(+), 31 deletions(-) diff --git a/plugin-dev/Source/Sentry/Private/Android/AndroidSentrySubsystem.cpp b/plugin-dev/Source/Sentry/Private/Android/AndroidSentrySubsystem.cpp index ba6715c2b..624bcc0d8 100644 --- a/plugin-dev/Source/Sentry/Private/Android/AndroidSentrySubsystem.cpp +++ b/plugin-dev/Source/Sentry/Private/Android/AndroidSentrySubsystem.cpp @@ -33,8 +33,8 @@ void FAndroidSentrySubsystem::InitWithSettings(const USentrySettings* settings, { TSharedPtr SettingsJson = MakeShareable(new FJsonObject); SettingsJson->SetStringField(TEXT("dsn"), settings->Dsn); - SettingsJson->SetStringField(TEXT("release"), settings->OverrideReleaseName ? settings->Release : settings->GetFormattedReleaseName()); - SettingsJson->SetStringField(TEXT("environment"), settings->Environment); + SettingsJson->SetStringField(TEXT("release"), settings->GetEffectiveRelease()); + SettingsJson->SetStringField(TEXT("environment"), settings->GetEffectiveEnvironment()); SettingsJson->SetStringField(TEXT("dist"), settings->Dist); SettingsJson->SetBoolField(TEXT("autoSessionTracking"), settings->EnableAutoSessionTracking); SettingsJson->SetNumberField(TEXT("sessionTimeout"), settings->SessionTimeout); diff --git a/plugin-dev/Source/Sentry/Private/Apple/AppleSentrySubsystem.cpp b/plugin-dev/Source/Sentry/Private/Apple/AppleSentrySubsystem.cpp index d6f13fbe3..5f49f7691 100644 --- a/plugin-dev/Source/Sentry/Private/Apple/AppleSentrySubsystem.cpp +++ b/plugin-dev/Source/Sentry/Private/Apple/AppleSentrySubsystem.cpp @@ -51,11 +51,11 @@ void FAppleSentrySubsystem::InitWithSettings(const USentrySettings* settings, US dispatch_async(dispatch_get_main_queue(), ^{ [SENTRY_APPLE_CLASS(SentrySDK) startWithConfigureOptions:^(SentryOptions* options) { options.dsn = settings->GetEffectiveDsn().GetNSString(); - options.environment = settings->Environment.GetNSString(); + options.releaseName = settings->GetEffectiveRelease().GetNSString(); + options.environment = settings->GetEffectiveEnvironment().GetNSString(); options.dist = settings->Dist.GetNSString(); options.enableAutoSessionTracking = settings->EnableAutoSessionTracking; options.sessionTrackingIntervalMillis = settings->SessionTimeout; - options.releaseName = settings->OverrideReleaseName ? settings->Release.GetNSString() : settings->GetFormattedReleaseName().GetNSString(); options.attachStacktrace = settings->AttachStacktrace; options.debug = settings->Debug; options.sampleRate = [NSNumber numberWithFloat:settings->SampleRate]; diff --git a/plugin-dev/Source/Sentry/Private/GenericPlatform/GenericPlatformSentrySubsystem.cpp b/plugin-dev/Source/Sentry/Private/GenericPlatform/GenericPlatformSentrySubsystem.cpp index 24d43ea9e..cfea2ceee 100644 --- a/plugin-dev/Source/Sentry/Private/GenericPlatform/GenericPlatformSentrySubsystem.cpp +++ b/plugin-dev/Source/Sentry/Private/GenericPlatform/GenericPlatformSentrySubsystem.cpp @@ -298,10 +298,9 @@ void FGenericPlatformSentrySubsystem::InitWithSettings(const USentrySettings* se ConfigureCertsPath(options); ConfigureNetworkConnectFunc(options); - sentry_options_set_release(options, TCHAR_TO_ANSI(settings->OverrideReleaseName ? *settings->Release : *settings->GetFormattedReleaseName())); - sentry_options_set_dsn(options, TCHAR_TO_ANSI(*settings->GetEffectiveDsn())); - sentry_options_set_environment(options, TCHAR_TO_ANSI(*settings->Environment)); + sentry_options_set_release(options, TCHAR_TO_ANSI(*settings->GetEffectiveRelease())); + sentry_options_set_environment(options, TCHAR_TO_ANSI(*settings->GetEffectiveEnvironment())); sentry_options_set_dist(options, TCHAR_TO_ANSI(*settings->Dist)); sentry_options_set_logger(options, PrintVerboseLog, nullptr); sentry_options_set_debug(options, settings->Debug); diff --git a/plugin-dev/Source/Sentry/Private/Linux/LinuxSentrySubsystem.cpp b/plugin-dev/Source/Sentry/Private/Linux/LinuxSentrySubsystem.cpp index 393f943d8..791f9b6c8 100644 --- a/plugin-dev/Source/Sentry/Private/Linux/LinuxSentrySubsystem.cpp +++ b/plugin-dev/Source/Sentry/Private/Linux/LinuxSentrySubsystem.cpp @@ -16,7 +16,7 @@ void FLinuxSentrySubsystem::InitWithSettings(const USentrySettings* Settings, US { FGenericPlatformSentrySubsystem::InitWithSettings(Settings, BeforeSendHandler, BeforeBreadcrumbHandler, TraceSampler); - InitCrashReporter(Settings->Release, Settings->Environment); + InitCrashReporter(Settings->GetEffectiveRelease(), Settings->GetEffectiveEnvironment()); } void FLinuxSentrySubsystem::ConfigureHandlerPath(sentry_options_t* Options) diff --git a/plugin-dev/Source/Sentry/Private/Microsoft/MicrosoftSentrySubsystem.cpp b/plugin-dev/Source/Sentry/Private/Microsoft/MicrosoftSentrySubsystem.cpp index 451f79c58..92f74c4ea 100644 --- a/plugin-dev/Source/Sentry/Private/Microsoft/MicrosoftSentrySubsystem.cpp +++ b/plugin-dev/Source/Sentry/Private/Microsoft/MicrosoftSentrySubsystem.cpp @@ -31,10 +31,10 @@ void FMicrosoftSentrySubsystem::InitWithSettings(const USentrySettings* Settings if (FPlatformMisc::GetCrashHandlingType() == ECrashHandlingType::Default) { - InitCrashReporter(Settings->Release, Settings->Environment); + InitCrashReporter(Settings->GetEffectiveRelease(), Settings->GetEffectiveEnvironment()); } #else - InitCrashReporter(Settings->Release, Settings->Environment); + InitCrashReporter(Settings->GetEffectiveRelease(), Settings->GetEffectiveEnvironment()); #endif } diff --git a/plugin-dev/Source/Sentry/Private/SentrySettings.cpp b/plugin-dev/Source/Sentry/Private/SentrySettings.cpp index 530167681..715dbd676 100644 --- a/plugin-dev/Source/Sentry/Private/SentrySettings.cpp +++ b/plugin-dev/Source/Sentry/Private/SentrySettings.cpp @@ -14,7 +14,6 @@ USentrySettings::USentrySettings(const FObjectInitializer& ObjectInitializer) , InitAutomatically(true) , Dsn() , Debug(true) - , Environment(GetDefaultEnvironmentName()) , SampleRate(1.0f) , EnableAutoLogAttachment(false) , AttachStacktrace(true) @@ -105,7 +104,59 @@ FString USentrySettings::GetEffectiveDsn() const return FString(); } -FString USentrySettings::GetFormattedReleaseName() +FString USentrySettings::GetEffectiveEnvironment() const +{ + if (!Environment.IsEmpty()) + { + return Environment; + } + + const FString& EnvVarEnvironment = FPlatformMisc::GetEnvironmentVariable(TEXT("SENTRY_ENVIRONMENT")); + if (!EnvVarEnvironment.IsEmpty()) + { + UE_LOG(LogSentrySdk, Log, TEXT("Using SENTRY_ENVIRONMENT variable as Sentry environment.")); + return EnvVarEnvironment; + } + + UE_LOG(LogSentrySdk, Log, TEXT("Using current build configuration as Sentry environment.")); + return GetEnvironmentFromBuildConfig(); +} + +FString USentrySettings::GetEnvironmentFromBuildConfig() const +{ + if (GIsEditor) + { + return TEXT("Editor"); + } + + // Check Shipping configuration separately for backward compatibility + if (FApp::GetBuildConfiguration() == EBuildConfiguration::Shipping) + { + return TEXT("Release"); + } + + return LexToString(FApp::GetBuildConfiguration()); +} + +FString USentrySettings::GetEffectiveRelease() const +{ + if (OverrideReleaseName) + { + return Release; + } + + const FString& EnvVarRelease = FPlatformMisc::GetEnvironmentVariable(TEXT("SENTRY_RELEASE")); + if (!EnvVarRelease.IsEmpty()) + { + UE_LOG(LogSentrySdk, Log, TEXT("Using SENTRY_RELEASE variable as Sentry release.")); + return EnvVarRelease; + } + + UE_LOG(LogSentrySdk, Log, TEXT("Using current project name and version as Sentry release.")); + return GetReleaseFromProjectSettings(); +} + +FString USentrySettings::GetReleaseFromProjectSettings() const { FString FormattedReleaseName = FApp::GetProjectName(); @@ -129,22 +180,6 @@ void USentrySettings::ClearDirtyFlag() bIsDirty = false; } -FString USentrySettings::GetDefaultEnvironmentName() -{ - if (GIsEditor) - { - return TEXT("Editor"); - } - - // Check Shipping configuration separately for backward compatibility - if (FApp::GetBuildConfiguration() == EBuildConfiguration::Shipping) - { - return TEXT("Release"); - } - - return LexToString(FApp::GetBuildConfiguration()); -} - void USentrySettings::LoadDebugSymbolsProperties() { const FString PropertiesFilePath = FPaths::Combine(FPaths::ProjectDir(), TEXT("sentry.properties")); diff --git a/plugin-dev/Source/Sentry/Public/SentrySettings.h b/plugin-dev/Source/Sentry/Public/SentrySettings.h index e4bb61f49..abbdad047 100644 --- a/plugin-dev/Source/Sentry/Public/SentrySettings.h +++ b/plugin-dev/Source/Sentry/Public/SentrySettings.h @@ -380,14 +380,32 @@ class SENTRY_API USentrySettings : public UObject */ FString GetEffectiveDsn() const; - static FString GetFormattedReleaseName(); + /** + * Gets the effective environment based on current execution context. + * + * @return By default, the SDK uses the `Environment` value from the plugin settings if set. + * If not, the SDK will attempt to read it from SENTRY_ENVIRONMENT environment variable. + * If that is also not set, the environment is automatically derived from the current build configuration. + */ + FString GetEffectiveEnvironment() const; + + FString GetEnvironmentFromBuildConfig() const; + + /** + * Gets the effective release name based on current execution context. + * + * @return By default, the SDK uses the `Release` value from the plugin settings if `OverrideReleaseName` flag is set. + * If not, the SDK will attempt to read it from SENTRY_RELEASE environment variable. + * If that is also not set, the release name is automatically derived from the current project name and version. + */ + FString GetEffectiveRelease() const; + + FString GetReleaseFromProjectSettings() const; bool IsDirty() const; void ClearDirtyFlag(); private: - FString GetDefaultEnvironmentName(); - void LoadDebugSymbolsProperties(); bool bIsDirty; From 66be39dc602f736388777573b24657e80ce6539c Mon Sep 17 00:00:00 2001 From: Ivan Tustanivskyi Date: Mon, 25 Aug 2025 12:19:38 +0300 Subject: [PATCH 4/6] Update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a892c5fd..8a8344639 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## Unreleased +### Features + +- Read `DSN`, `Environment` and `Release` options from environment variables ([#1054](https://github.com/getsentry/sentry-unreal/pull/1054)) + ### Dependencies - Bump CLI from v2.51.1 to v2.52.0 ([#1049](https://github.com/getsentry/sentry-unreal/pull/1049)) From 781143fb7574f6382af6f95284d68bb2437757bd Mon Sep 17 00:00:00 2001 From: Ivan Tustanivskyi Date: Wed, 27 Aug 2025 09:17:47 +0300 Subject: [PATCH 5/6] Add comments for new functions --- plugin-dev/Source/Sentry/Public/SentrySettings.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/plugin-dev/Source/Sentry/Public/SentrySettings.h b/plugin-dev/Source/Sentry/Public/SentrySettings.h index a9d4ca749..cbb98e835 100644 --- a/plugin-dev/Source/Sentry/Public/SentrySettings.h +++ b/plugin-dev/Source/Sentry/Public/SentrySettings.h @@ -397,6 +397,11 @@ class SENTRY_API USentrySettings : public UObject */ FString GetEffectiveEnvironment() const; + /** + * Gets the environment from the application's build configuration. + * + * @return Environment string based on build configuration (`Shipping` maps to `Release`, others map directly). + */ FString GetEnvironmentFromBuildConfig() const; /** @@ -408,6 +413,11 @@ class SENTRY_API USentrySettings : public UObject */ FString GetEffectiveRelease() const; + /** + * Gets the release name from the project settings. + * + * @return Release name derived from the current project name and version to match the format `@`. + */ FString GetReleaseFromProjectSettings() const; bool IsDirty() const; From 221784478749b2430d9f067a1306ffed6e7956ad Mon Sep 17 00:00:00 2001 From: Ivan Tustanivskyi Date: Wed, 27 Aug 2025 09:41:30 +0300 Subject: [PATCH 6/6] Add more logs --- plugin-dev/Source/Sentry/Private/SentrySettings.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin-dev/Source/Sentry/Private/SentrySettings.cpp b/plugin-dev/Source/Sentry/Private/SentrySettings.cpp index 467d11123..3ca138d83 100644 --- a/plugin-dev/Source/Sentry/Private/SentrySettings.cpp +++ b/plugin-dev/Source/Sentry/Private/SentrySettings.cpp @@ -110,6 +110,7 @@ FString USentrySettings::GetEffectiveEnvironment() const { if (!Environment.IsEmpty()) { + UE_LOG(LogSentrySdk, Verbose, TEXT("Using the value from plugin settings as Sentry environment.")); return Environment; } @@ -144,6 +145,7 @@ FString USentrySettings::GetEffectiveRelease() const { if (OverrideReleaseName) { + UE_LOG(LogSentrySdk, Verbose, TEXT("Using the value from plugin settings as Sentry release.")); return Release; }