-
-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathSentrySettings.cpp
196 lines (167 loc) · 6.08 KB
/
SentrySettings.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// Copyright (c) 2022 Sentry. All Rights Reserved.
#include "SentrySettings.h"
#include "SentryDefines.h"
#include "SentryBeforeSendHandler.h"
#include "SentryTraceSampler.h"
#include "Misc/Paths.h"
#include "Misc/ConfigCacheIni.h"
#include "Misc/App.h"
USentrySettings::USentrySettings(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
, InitAutomatically(true)
, Dsn()
, EditorDsn()
, Debug(true)
, Environment(GetDefaultEnvironmentName())
, SampleRate(1.0f)
, EnableAutoLogAttachment(false)
, AttachStacktrace(true)
, SendDefaultPii(false)
, AttachScreenshot(false)
, AttachGpuDump(true)
, MaxAttachmentSize(20 * 1024 * 1024)
, MaxBreadcrumbs(100)
, EnableAutoSessionTracking(true)
, SessionTimeout(30000)
, OverrideReleaseName(false)
, UseProxy(false)
, ProxyUrl()
, BeforeSendHandler(USentryBeforeSendHandler::StaticClass())
, BeforeBreadcrumbHandler(nullptr)
, EnableAutoCrashCapturing(true)
, DatabaseLocation(ESentryDatabaseLocation::ProjectUserDirectory)
, EnableAppNotRespondingTracking(false)
, EnableTracing(false)
, SamplingType(ESentryTracesSamplingType::UniformSampleRate)
, TracesSampleRate(0.0f)
, TracesSampler(USentryTraceSampler::StaticClass())
, EnableForPromotedBuildsOnly(false)
, UploadSymbolsAutomatically(false)
, IncludeSources(false)
, DiagnosticLevel(ESentryCliLogLevel::Info)
, UseLegacyGradlePlugin(false)
, CrashReporterUrl()
, bIsDirty(false)
{
if (GIsEditor)
{
LoadDebugSymbolsProperties();
}
CheckLegacySettings();
}
#if WITH_EDITOR
void USentrySettings::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
{
Super::PostEditChangeProperty(PropertyChangedEvent);
if (!PropertyChangedEvent.Property)
{
return;
}
if (PropertyChangedEvent.Property->GetFName() == GET_MEMBER_NAME_CHECKED(USentrySettings, InitAutomatically) ||
PropertyChangedEvent.Property->GetFName() == GET_MEMBER_NAME_CHECKED(USentrySettings, UploadSymbolsAutomatically) ||
PropertyChangedEvent.Property->GetFName() == GET_MEMBER_NAME_CHECKED(USentrySettings, ProjectName) ||
PropertyChangedEvent.Property->GetFName() == GET_MEMBER_NAME_CHECKED(USentrySettings, OrgName) ||
PropertyChangedEvent.Property->GetFName() == GET_MEMBER_NAME_CHECKED(USentrySettings, AuthToken) ||
PropertyChangedEvent.Property->GetFName() == GET_MEMBER_NAME_CHECKED(USentrySettings, IncludeSources) ||
PropertyChangedEvent.Property->GetFName() == GET_MEMBER_NAME_CHECKED(USentrySettings, UseLegacyGradlePlugin) ||
PropertyChangedEvent.Property->GetFName() == GET_MEMBER_NAME_CHECKED(USentrySettings, DiagnosticLevel) ||
PropertyChangedEvent.Property->GetFName() == GET_MEMBER_NAME_CHECKED(USentrySettings, CrashReporterUrl))
{
return;
}
bIsDirty = true;
}
#endif
FString USentrySettings::GetFormattedReleaseName()
{
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;
}
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"));
if (FPaths::FileExists(PropertiesFilePath))
{
FConfigFile PropertiesFile;
PropertiesFile.Read(PropertiesFilePath);
PropertiesFile.GetString(TEXT("Sentry"), TEXT("defaults.project"), ProjectName);
PropertiesFile.GetString(TEXT("Sentry"), TEXT("defaults.org"), OrgName);
PropertiesFile.GetString(TEXT("Sentry"), TEXT("auth.token"), AuthToken);
}
else
{
bool UploadSymbols = false;
GConfig->GetBool(TEXT("/Script/Sentry.SentrySettings"), TEXT("UploadSymbolsAutomatically"), UploadSymbols, *GetDefaultConfigFilename());
if (UploadSymbols)
{
UE_LOG(LogSentrySdk, Warning, TEXT("Sentry plugin can't find sentry.properties file"));
}
}
}
void USentrySettings::CheckLegacySettings()
{
bool IsSettingsDirty = false;
const FString SentrySection = TEXT("/Script/Sentry.SentrySettings");
const FString ConfigFilename = GetDefaultConfigFilename();
// Settings renamed in 0.9.0
const FString DsnLegacyKey = TEXT("DsnUrl");
FString DsnLegacyValue = TEXT("");
if(GConfig->GetString(*SentrySection, *DsnLegacyKey, DsnLegacyValue, *ConfigFilename))
{
Dsn = DsnLegacyValue;
GConfig->SetString(*SentrySection, TEXT("Dsn"), *Dsn, *ConfigFilename);
GConfig->RemoveKey(*SentrySection, *DsnLegacyKey, *ConfigFilename);
IsSettingsDirty = true;
}
const FString DebugLegacyKey = TEXT("EnableVerboseLogging");
bool DebugLegacyValue;
if(GConfig->GetBool(*SentrySection, *DebugLegacyKey, DebugLegacyValue, *ConfigFilename))
{
Debug = DebugLegacyValue;
GConfig->SetBool(*SentrySection, TEXT("Debug"), Debug, *ConfigFilename);
GConfig->RemoveKey(*SentrySection, *DebugLegacyKey, *ConfigFilename);
IsSettingsDirty = true;
}
const FString AttachStacktraceLegacyKey = TEXT("EnableStackTrace");
bool AttachStacktraceLegacyValue;
if(GConfig->GetBool(*SentrySection, *AttachStacktraceLegacyKey, AttachStacktraceLegacyValue, *ConfigFilename))
{
AttachStacktrace = AttachStacktraceLegacyValue;
GConfig->SetBool(*SentrySection, TEXT("AttachStacktrace"), AttachStacktrace, *ConfigFilename);
GConfig->RemoveKey(*SentrySection, *AttachStacktraceLegacyKey, *ConfigFilename);
IsSettingsDirty = true;
}
// Place newly renamed settings here specifying the release for which changes take place
if (IsSettingsDirty)
{
UE_LOG(LogSentrySdk, Warning, TEXT("Sentry settings were marked as dirty (if not checked out in Perforce these need to be updated manually)"));
GConfig->Flush(false, *ConfigFilename);
}
}