Skip to content

Commit ab68b25

Browse files
authored
ref: DSN resolution during the plugin initialization (#985)
* Refactor DSN resolution during the SDK init (default vs editor) * Move EditorDSN setting to Misc section * Fix lint errors
1 parent 7fc8016 commit ab68b25

File tree

4 files changed

+20
-19
lines changed

4 files changed

+20
-19
lines changed

plugin-dev/Source/Sentry/Private/Apple/AppleSentrySubsystem.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,7 @@ void FAppleSentrySubsystem::InitWithSettings(const USentrySettings* settings, US
4848
dispatch_group_enter(sentryDispatchGroup);
4949
dispatch_async(dispatch_get_main_queue(), ^{
5050
[SentrySDK startWithConfigureOptions:^(SentryOptions* options) {
51-
options.dsn = settings->Dsn.GetNSString();
52-
#if WITH_EDITOR
53-
if (!settings->EditorDsn.IsEmpty())
54-
{
55-
options.dsn = settings->EditorDsn.GetNSString();
56-
}
57-
#endif
51+
options.dsn = settings->GetEffectiveDsn().GetNSString();
5852
options.environment = settings->Environment.GetNSString();
5953
options.dist = settings->Dist.GetNSString();
6054
options.enableAutoSessionTracking = settings->EnableAutoSessionTracking;

plugin-dev/Source/Sentry/Private/GenericPlatform/GenericPlatformSentrySubsystem.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,8 @@ void FGenericPlatformSentrySubsystem::InitWithSettings(const USentrySettings* se
276276

277277
sentry_options_set_release(options, TCHAR_TO_ANSI(settings->OverrideReleaseName ? *settings->Release : *settings->GetFormattedReleaseName()));
278278

279-
sentry_options_set_dsn(options, TCHAR_TO_ANSI(*settings->Dsn));
280-
#if WITH_EDITOR
281-
if (!settings->EditorDsn.IsEmpty())
282-
{
283-
sentry_options_set_dsn(options, TCHAR_TO_ANSI(*settings->EditorDsn));
284-
}
285-
#endif // WITH_EDITOR
279+
sentry_options_set_dsn(options, TCHAR_TO_ANSI(*settings->GetEffectiveDsn()));
280+
286281
sentry_options_set_environment(options, TCHAR_TO_ANSI(*settings->Environment));
287282
sentry_options_set_dist(options, TCHAR_TO_ANSI(*settings->Dist));
288283
sentry_options_set_logger(options, PrintVerboseLog, nullptr);

plugin-dev/Source/Sentry/Private/SentrySettings.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ USentrySettings::USentrySettings(const FObjectInitializer& ObjectInitializer)
1313
: Super(ObjectInitializer)
1414
, InitAutomatically(true)
1515
, Dsn()
16-
, EditorDsn()
1716
, Debug(true)
1817
, Environment(GetDefaultEnvironmentName())
1918
, SampleRate(1.0f)
@@ -39,6 +38,7 @@ USentrySettings::USentrySettings(const FObjectInitializer& ObjectInitializer)
3938
, SamplingType(ESentryTracesSamplingType::UniformSampleRate)
4039
, TracesSampleRate(0.0f)
4140
, TracesSampler(USentryTraceSampler::StaticClass())
41+
, EditorDsn()
4242
, EnableForPromotedBuildsOnly(false)
4343
, UploadSymbolsAutomatically(false)
4444
, IncludeSources(false)
@@ -84,6 +84,11 @@ void USentrySettings::PostEditChangeProperty(FPropertyChangedEvent& PropertyChan
8484

8585
#endif
8686

87+
FString USentrySettings::GetEffectiveDsn() const
88+
{
89+
return GIsEditor && !EditorDsn.IsEmpty() ? EditorDsn : Dsn;
90+
}
91+
8792
FString USentrySettings::GetFormattedReleaseName()
8893
{
8994
FString FormattedReleaseName = FApp::GetProjectName();

plugin-dev/Source/Sentry/Public/SentrySettings.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,10 +189,6 @@ class SENTRY_API USentrySettings : public UObject
189189
Meta = (DisplayName = "DSN", ToolTip = "The DSN (Data Source Name) tells the SDK where to send the events to. Get your DSN in the Sentry dashboard."))
190190
FString Dsn;
191191

192-
UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = "General",
193-
Meta = (DisplayName = "Editor DSN", ToolTip = "The Editor DSN (Data Source Name) if you want to isolate editor crashes from packaged game crashes, defaults to Dsn if not provided."))
194-
FString EditorDsn;
195-
196192
UPROPERTY(Config, EditAnywhere, Category = "General",
197193
Meta = (DisplayName = "Enable verbose logging", ToolTip = "Flag indicating whether to enable verbose logging."))
198194
bool Debug;
@@ -319,6 +315,10 @@ class SENTRY_API USentrySettings : public UObject
319315
EditCondition = "EnableTracing && SamplingType == ESentryTracesSamplingType::TracesSampler", EditConditionHides))
320316
TSubclassOf<USentryTraceSampler> TracesSampler;
321317

318+
UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = "General|Misc",
319+
Meta = (DisplayName = "Editor DSN", ToolTip = "The Editor DSN (Data Source Name) if you want to isolate editor crashes from packaged game crashes, defaults to Dsn if not provided."))
320+
FString EditorDsn;
321+
322322
UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = "General|Misc",
323323
Meta = (DisplayName = "Promote values to tags"))
324324
FTagsPromotion TagsPromotion;
@@ -372,6 +372,13 @@ class SENTRY_API USentrySettings : public UObject
372372
virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
373373
#endif
374374

375+
/**
376+
* Gets the effective DSN based on current execution context.
377+
*
378+
* @return Editor DSN when running in the editor and one is set; otherwise, falls back to the default DSN.
379+
*/
380+
FString GetEffectiveDsn() const;
381+
375382
static FString GetFormattedReleaseName();
376383

377384
bool IsDirty() const;

0 commit comments

Comments
 (0)