src/Umbraco.Web/Telemetry/ReportSiteTask.cs
/// <summary>
/// Runs the background task to send the anynomous ID
/// to telemetry service
/// </summary>
/// <returns>A value indicating whether to repeat the task.</returns>
Runs the background task to send the anynomous ID
to telemetry service
Runs the background task to send the anynomous ID to telemetry service
public override async Task<bool> PerformRunAsync(CancellationToken token)
        {
            var telemetricsFilePath = IOHelper.MapPath(SystemFiles.TelemetricsIdentifier);
            if (File.Exists(telemetricsFilePath) == false)
            {
                _logger.Warn<ReportSiteTask>("No telemetry marker file found at '{filePath}' and will not report site to telemetry service", telemetricsFilePath);
                return false;
            }
            var telemetricsFileContents = string.Empty;
            try
            {
                telemetricsFileContents = File.ReadAllText(telemetricsFilePath);
            }
            catch (Exception ex)
            {
                _logger.Error<ReportSiteTask>(ex, "Error in reading file contents of telemetry marker file found at '{filePath}'", telemetricsFilePath);
                return true;
            }
            if (Guid.TryParse(telemetricsFileContents, out var telemetrySiteIdentifier) == false)
            {
                _logger.Warn<ReportSiteTask>("The telemetry marker file found at '{filePath}' with '{telemetrySiteId}' is not a valid identifier for the telemetry service", telemetricsFilePath, telemetrySiteIdentifier);
                return false;
            }
            try
            {
                _httpClient.BaseAddress = new Uri("https://telemetry.umbraco.com/");
#if DEBUG
                _httpClient.BaseAddress = new Uri("https://telemetry.rainbowsrock.net/");
#endif
                _httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json");
                using (var request = new HttpRequestMessage(HttpMethod.Post, "installs/"))
                {
                    var postData = new TelemetryReportData { Id = telemetrySiteIdentifier, Version = UmbracoVersion.SemanticVersion.ToSemanticString() };
                    request.Content = new StringContent(JsonConvert.SerializeObject(postData), Encoding.UTF8, "application/json"); 
                    _httpClient.Timeout = new TimeSpan(0, 0, 1);
                    var result = await _httpClient.SendAsync(request);
                }
            }
            catch
            {
                _logger.Debug<ReportSiteTask>("There was a problem sending a request to the Umbraco telemetry service");
            }
            return true;
        }
public override async Task < bool > PerformRunAsync ( CancellationToken token ) { var telemetricsFilePath = IOHelper . MapPath ( SystemFiles . TelemetricsIdentifier ) ; if ( File . Exists ( telemetricsFilePath ) == false ) { _logger . Warn < ReportSiteTask > ( " " , telemetricsFilePath ) ; return false ; } var telemetricsFileContents = string . Empty ; try { telemetricsFileContents = File . ReadAllText ( telemetricsFilePath ) ; } catch ( Exception ex ) { _logger . Error < ReportSiteTask > ( ex , " " , telemetricsFilePath ) ; return true ; } if ( Guid . TryParse ( telemetricsFileContents , out var telemetrySiteIdentifier ) == false ) { _logger . Warn < ReportSiteTask > ( " " , telemetricsFilePath , telemetrySiteIdentifier ) ; return false ; } try { _httpClient . BaseAddress = new Uri ( " " ) ; if DEBUG _httpClient . BaseAddress = new Uri ( " " ) ; endif _httpClient . DefaultRequestHeaders . TryAddWithoutValidation ( " " , " " ) ; using ( var request = new HttpRequestMessage ( HttpMethod . Post , " " ) ) { var postData = new TelemetryReportData { Id = telemetrySiteIdentifier , Version = UmbracoVersion . SemanticVersion . ToSemanticString ( ) } ; request . Content = new StringContent ( JsonConvert . SerializeObject ( postData ) , Encoding . UTF8 , " " ) ; _httpClient . Timeout = new TimeSpan ( 0 , 0 , 1 ) ; var result = await _httpClient . SendAsync ( request ) ; } } catch { _logger . Debug < ReportSiteTask > ( " " ) ; } return true ; }
Runs the background task to send the anynomous ID
to telemetry service
Runs the background task to send the anynomous ID to telemetry service
// Try & find file at '/umbraco/telemetrics-id.umb' // Some users may have decided to not be tracked by deleting/removing the marker file // Stop repeating this task (no need to keep checking) // The only time it will recheck when the site is recycled // Open file & read its contents // It may throw due to file permissions or file locking // Silently swallow ex - but lets log it (ReadAllText throws a ton of different types of ex) // Hence the use of general exception type // Exit out early, but mark this task to be repeated in case its a file lock so it can be rechecked the next time round // Parse as a GUID & verify its a GUID and not some random string // In case of users may have messed or decided to empty the file contents or put in something random // Some users may have decided to mess with file contents // Stop repeating this task (no need to keep checking) // The only time it will recheck when the site is recycled // Send data to LIVE telemetry // Send data to DEBUG telemetry service //CONTENT-TYPE header // Set a low timeout - no need to use a larger default timeout for this POST request // Make a HTTP Post to telemetry service // https://telemetry.umbraco.com/installs/ // Fire & Forget, do not need to know if its a 200, 500 etc // Silently swallow // The user does not need the logs being polluted if our service has fallen over or is down etc // Hence only loggigng this at a more verbose level (Which users should not be using in prod) // Keep recurring this task & pinging the telemetry service
A value indicating whether to repeat the task.
A value indicating whether to repeat the task .
token
CancellationToken