Only send telemetry if we're on runtimelevel run (#12600)

This commit is contained in:
Mole
2022-06-22 08:25:18 +02:00
committed by GitHub
parent 045a487190
commit 42e2254e30

View File

@@ -3,8 +3,10 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Newtonsoft.Json;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Configuration;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Telemetry;
using Umbraco.Cms.Core.Telemetry.Models;
using Umbraco.Cms.Web.Common.DependencyInjection;
@@ -16,17 +18,28 @@ public class ReportSiteTask : RecurringHostedServiceBase
private static HttpClient _httpClient = new();
private readonly ILogger<ReportSiteTask> _logger;
private readonly ITelemetryService _telemetryService;
private readonly IRuntimeState _runtimeState;
public ReportSiteTask(
ILogger<ReportSiteTask> logger,
ITelemetryService telemetryService)
: base(logger, TimeSpan.FromDays(1), TimeSpan.FromMinutes(1))
ITelemetryService telemetryService,
IRuntimeState runtimeState)
: base(logger, TimeSpan.FromDays(1), TimeSpan.FromMinutes(5))
{
_logger = logger;
_telemetryService = telemetryService;
_runtimeState = runtimeState;
_httpClient = new HttpClient();
}
[Obsolete("Use the constructor that takes IRuntimeState, scheduled for removal in V12")]
public ReportSiteTask(
ILogger<ReportSiteTask> logger,
ITelemetryService telemetryService)
: this(logger, telemetryService, StaticServiceProvider.Instance.GetRequiredService<IRuntimeState>())
{
}
[Obsolete("Use the constructor that takes ITelemetryService instead, scheduled for removal in V11")]
public ReportSiteTask(
ILogger<ReportSiteTask> logger,
@@ -42,6 +55,12 @@ public class ReportSiteTask : RecurringHostedServiceBase
/// </summary>
public override async Task PerformExecuteAsync(object? state)
{
if (_runtimeState.Level is not RuntimeLevel.Run)
{
// We probably haven't installed yet, so we can't get telemetry.
return;
}
if (_telemetryService.TryGetTelemetryReportData(out TelemetryReportData? telemetryReportData) is false)
{
_logger.LogWarning("No telemetry marker found");