Fix the TelemetryClient

Fix the TelemetryClient
This commit is contained in:
Namhyeon Go 2025-12-03 16:45:31 +09:00
parent 2db2e7b91a
commit 3188317bf6
2 changed files with 32 additions and 11 deletions

View File

@ -47,16 +47,34 @@ namespace WelsonJS.Launcher
); );
// telemetry // telemetry
string telemetryProvider = GetAppConfig("TelemetryProvider"); try
{
var telemetryProvider = GetAppConfig("TelemetryProvider");
var telemetryOptions = new TelemetryOptions var telemetryOptions = new TelemetryOptions
{ {
ApiKey = GetAppConfig("TelemetryApiKey"), ApiKey = GetAppConfig("TelemetryApiKey"),
BaseUrl = GetAppConfig("TelemetryBaseUrl"), BaseUrl = GetAppConfig("TelemetryBaseUrl"),
DistinctId = TelemetryIdentity.GetDistinctId(), DistinctId = TelemetryIdentity.GetDistinctId(),
Disabled = !string.Equals(GetAppConfig("TelemetryEnabled"), "true", StringComparison.OrdinalIgnoreCase) Disabled = !string.Equals(
GetAppConfig("TelemetryEnabled"),
"true",
StringComparison.OrdinalIgnoreCase)
}; };
if (!telemetryOptions.Disabled &&
!string.IsNullOrWhiteSpace(telemetryProvider) &&
!string.IsNullOrWhiteSpace(telemetryOptions.ApiKey) &&
!string.IsNullOrWhiteSpace(telemetryOptions.BaseUrl))
{
_telemetryClient = new TelemetryClient(telemetryProvider, telemetryOptions, _logger); _telemetryClient = new TelemetryClient(telemetryProvider, telemetryOptions, _logger);
} }
}
catch (Exception ex)
{
_logger.Error($"Telemetry initialization failed: {ex}");
_telemetryClient = null;
}
}
[STAThread] [STAThread]
static void Main(string[] args) static void Main(string[] args)
@ -84,7 +102,10 @@ namespace WelsonJS.Launcher
} }
// send event to the telemetry server // send event to the telemetry server
_telemetryClient.TrackAppStartedAsync("WelsonJS.Launcher", "0.2.7.57"); if (_telemetryClient != null)
{
_ = _telemetryClient.TrackAppStartedAsync("WelsonJS.Launcher", "0.2.7.57");
}
// draw the main form // draw the main form
Application.EnableVisualStyles(); Application.EnableVisualStyles();

View File

@ -66,11 +66,11 @@ namespace WelsonJS.Launcher.Telemetry
try try
{ {
await _httpClient.PostAsync( using (var response = await _httpClient.PostAsync(
url, url,
new StringContent(json, Encoding.UTF8, "application/json"), new StringContent(json, Encoding.UTF8, "application/json"),
cancellationToken cancellationToken
); )) { /* disposed automatically */ }
} }
catch catch
{ {