-
-
Notifications
You must be signed in to change notification settings - Fork 51
Read DSN
, Environment
and Release
options from environment variables
#1054
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
96c0e9a
b8fbfd9
24820b2
66be39d
584a3ea
65f875c
781143f
2217844
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 |
---|---|---|
|
@@ -14,7 +14,6 @@ USentrySettings::USentrySettings(const FObjectInitializer& ObjectInitializer) | |
, InitAutomatically(true) | ||
, Dsn() | ||
, Debug(true) | ||
, Environment(GetDefaultEnvironmentName()) | ||
, SampleRate(1.0f) | ||
, EnableAutoLogAttachment(false) | ||
, AttachStacktrace(true) | ||
|
@@ -86,34 +85,47 @@ void USentrySettings::PostEditChangeProperty(FPropertyChangedEvent& PropertyChan | |
|
||
FString USentrySettings::GetEffectiveDsn() const | ||
{ | ||
return GIsEditor && !EditorDsn.IsEmpty() ? EditorDsn : Dsn; | ||
} | ||
if (GIsEditor && !EditorDsn.IsEmpty()) | ||
{ | ||
return EditorDsn; | ||
} | ||
|
||
FString USentrySettings::GetFormattedReleaseName() | ||
{ | ||
FString FormattedReleaseName = FApp::GetProjectName(); | ||
if (!Dsn.IsEmpty()) | ||
{ | ||
return Dsn; | ||
} | ||
|
||
FString Version = TEXT(""); | ||
GConfig->GetString(TEXT("/Script/EngineSettings.GeneralProjectSettings"), TEXT("ProjectVersion"), Version, GGameIni); | ||
if (!Version.IsEmpty()) | ||
const FString& EnvVarDsn = FPlatformMisc::GetEnvironmentVariable(TEXT("SENTRY_DSN")); | ||
if (!EnvVarDsn.IsEmpty()) | ||
{ | ||
FormattedReleaseName = FString::Printf(TEXT("%s@%s"), *FormattedReleaseName, *Version); | ||
UE_LOG(LogSentrySdk, Log, TEXT("DSN is not set in plugin settings - using SENTRY_DSN environment variable instead.")); | ||
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. Note: Since Engine config is still priority, we will need to adapt demo when we update the SDK version there. |
||
return EnvVarDsn; | ||
} | ||
|
||
return FormattedReleaseName; | ||
UE_LOG(LogSentrySdk, Log, TEXT("DSN is not configured.")); | ||
return FString(); | ||
} | ||
|
||
bool USentrySettings::IsDirty() const | ||
FString USentrySettings::GetEffectiveEnvironment() const | ||
{ | ||
return bIsDirty; | ||
} | ||
if (!Environment.IsEmpty()) | ||
{ | ||
UE_LOG(LogSentrySdk, Verbose, TEXT("Using the value from plugin settings as Sentry environment.")); | ||
return Environment; | ||
} | ||
|
||
void USentrySettings::ClearDirtyFlag() | ||
{ | ||
bIsDirty = false; | ||
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.")); | ||
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. Do we also want to add a log message when using the environment from engine config? At least verbose. Same for GetEffectiveRelease() 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. Added a verbose log message when the value from the plugin settings is used (for both release and environment). |
||
return GetEnvironmentFromBuildConfig(); | ||
} | ||
|
||
FString USentrySettings::GetDefaultEnvironmentName() | ||
FString USentrySettings::GetEnvironmentFromBuildConfig() const | ||
{ | ||
if (GIsEditor) | ||
{ | ||
|
@@ -129,6 +141,49 @@ FString USentrySettings::GetDefaultEnvironmentName() | |
return LexToString(FApp::GetBuildConfiguration()); | ||
} | ||
|
||
FString USentrySettings::GetEffectiveRelease() const | ||
{ | ||
if (OverrideReleaseName) | ||
{ | ||
UE_LOG(LogSentrySdk, Verbose, TEXT("Using the value from plugin settings as Sentry release.")); | ||
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(); | ||
|
||
FString Version = TEXT(""); | ||
GConfig->GetString(TEXT("/Script/EngineSettings.GeneralProjectSettings"), TEXT("ProjectVersion"), Version, GGameIni); | ||
if (!Version.IsEmpty()) | ||
{ | ||
FormattedReleaseName = FString::Printf(TEXT("%s@%s"), *FormattedReleaseName, *Version); | ||
} | ||
|
||
return FormattedReleaseName; | ||
} | ||
|
||
bool USentrySettings::IsDirty() const | ||
{ | ||
return bIsDirty; | ||
} | ||
|
||
void USentrySettings::ClearDirtyFlag() | ||
{ | ||
bIsDirty = false; | ||
} | ||
|
||
void USentrySettings::LoadDebugSymbolsProperties() | ||
{ | ||
const FString PropertiesFilePath = FPaths::Combine(FPaths::ProjectDir(), TEXT("sentry.properties")); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -384,17 +384,46 @@ 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; | ||
|
||
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; | ||
|
||
/** | ||
* 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; | ||
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. Let's also add documentation for the two other functions we added here |
||
|
||
/** | ||
* 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; | ||
|
||
/** | ||
* Gets the release name from the project settings. | ||
* | ||
* @return Release name derived from the current project name and version to match the format `<ProjectName>@<Version>`. | ||
*/ | ||
FString GetReleaseFromProjectSettings() const; | ||
|
||
bool IsDirty() const; | ||
void ClearDirtyFlag(); | ||
|
||
private: | ||
FString GetDefaultEnvironmentName(); | ||
|
||
void LoadDebugSymbolsProperties(); | ||
|
||
bool bIsDirty; | ||
|
Uh oh!
There was an error while loading. Please reload this page.