Skip to content

Commit 22b114a

Browse files
authored
Support for unknown universe based on the URL (#171)
1 parent 4702027 commit 22b114a

File tree

3 files changed

+19
-16
lines changed

3 files changed

+19
-16
lines changed

Runtime/BacktraceClient.cs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -578,45 +578,46 @@ public bool EnableBreadcrumbsSupport()
578578
return Database.EnableBreadcrumbsSupport();
579579
}
580580
#if !UNITY_WEBGL
581-
public void EnableMetrics()
581+
public bool EnableMetrics()
582582
{
583-
EnableMetrics(true);
583+
return EnableMetrics(true);
584584
}
585-
private void EnableMetrics(bool enableIfConfigurationIsDisabled = true)
585+
private bool EnableMetrics(bool enableIfConfigurationIsDisabled = true)
586586
{
587587
if (!Configuration.EnableMetricsSupport)
588588
{
589589
if (!enableIfConfigurationIsDisabled)
590590
{
591-
return;
591+
return false;
592592
}
593593
Debug.LogWarning("Event aggregation configuration was disabled. Enabling it manually via API");
594594
}
595-
var universeName = Configuration.GetUniverseName();
596-
var token = Configuration.GetToken();
597-
EnableMetrics(
598-
BacktraceMetrics.GetDefaultUniqueEventsUrl(universeName, token),
599-
BacktraceMetrics.GetDefaultSummedEventsUrl(universeName, token),
600-
Configuration.GetEventAggregationIntervalTimerInMs());
595+
return EnableMetrics(BacktraceMetrics.DefaultUniqueAttributeName);
601596
}
602597

603-
public void EnableMetrics(string uniqueAttributeName = BacktraceMetrics.DefaultUniqueAttributeName)
598+
public bool EnableMetrics(string uniqueAttributeName = BacktraceMetrics.DefaultUniqueAttributeName)
604599
{
605600
var universeName = Configuration.GetUniverseName();
601+
if(string.IsNullOrEmpty(universeName))
602+
{
603+
Debug.LogWarning("Cannot initialize event aggregation - Unknown Backtrace URL.");
604+
return false;
605+
}
606606
var token = Configuration.GetToken();
607607
EnableMetrics(
608608
BacktraceMetrics.GetDefaultUniqueEventsUrl(universeName, token),
609609
BacktraceMetrics.GetDefaultSummedEventsUrl(universeName, token),
610610
Configuration.GetEventAggregationIntervalTimerInMs(),
611611
uniqueAttributeName);
612+
return true;
612613
}
613614

614-
public void EnableMetrics(string uniqueEventsSubmissionUrl, string summedEventsSubmissionUrl, uint timeIntervalInSec = BacktraceMetrics.DefaultTimeIntervalInSec, string uniqueAttributeName = BacktraceMetrics.DefaultUniqueAttributeName)
615+
public bool EnableMetrics(string uniqueEventsSubmissionUrl, string summedEventsSubmissionUrl, uint timeIntervalInSec = BacktraceMetrics.DefaultTimeIntervalInSec, string uniqueAttributeName = BacktraceMetrics.DefaultUniqueAttributeName)
615616
{
616617
if (_metrics != null)
617618
{
618619
Debug.LogWarning("Backtrace metrics support is enabled. Please use BacktraceClient.Metrics.");
619-
return;
620+
return false;
620621
}
621622
_metrics = new BacktraceMetrics(
622623
attributeProvider: AttributeProvider,
@@ -629,6 +630,7 @@ public void EnableMetrics(string uniqueEventsSubmissionUrl, string summedEventsS
629630
IgnoreSslValidation = Configuration.IgnoreSslValidation
630631
};
631632
StartupMetrics();
633+
return true;
632634
}
633635

634636
private void StartupMetrics()

Runtime/Interfaces/IBacktraceClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ public interface IBacktraceClient
6464
/// <summary>
6565
/// Enable event aggregation support.
6666
/// </summary>
67-
void EnableMetrics();
67+
bool EnableMetrics();
6868

6969
/// <summary>
7070
/// Enable event aggregation support.
7171
/// </summary>
72-
void EnableMetrics(string uniqueEventsSubmissionUrl, string summedEventsSubmissionUrl, uint timeIntervalInSec, string uniqueEventName);
72+
bool EnableMetrics(string uniqueEventsSubmissionUrl, string summedEventsSubmissionUrl, uint timeIntervalInSec, string uniqueEventName);
7373
#endif
7474
}
7575
}

Runtime/Model/BacktraceConfiguration.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ public string GetUniverseName()
346346
var domainIndex = submissionUrl.IndexOf(backtraceDomain);
347347
if (domainIndex == -1)
348348
{
349-
throw new ArgumentException("Invalid Backtrace url");
349+
// capture situation when the URL doesn't point to known Backtrace URL
350+
return null;
350351
}
351352

352353
var uri = new UriBuilder(submissionUrl);

0 commit comments

Comments
 (0)