public void TrackStrippedRepositorySignatures( string packageId, string normalizedVersion, Guid validationId, PrimarySignature inputSignature, PrimarySignature outputSignature) { var properties = new Dictionary <string, string> { { PackageId, packageId }, { NormalizedVersion, normalizedVersion }, { ValidationId, validationId.ToString() }, { InputSignatureType, inputSignature.Type.ToString() }, { InputCounterSignatureCount, inputSignature.SignerInfo.CounterSignerInfos.Count.ToString() }, }; if (outputSignature != null) { properties.Add(OutputSignatureType, outputSignature.Type.ToString()); properties.Add(OutputCounterSignatureCount, outputSignature.SignerInfo.CounterSignerInfos.Count.ToString()); } _telemetryClient.TrackMetric( StrippedRepositorySignatures, 1, properties); }
public void TrackPackageDownloaded(Uri packageUri, TimeSpan duration, long size) { // Remove the query string from the package URI, since this could contain a SAS token. var uriBuilder = new UriBuilder(packageUri); uriBuilder.Query = null; var absoluteUri = uriBuilder.Uri.AbsoluteUri; _telemetryClient.TrackMetric( PackageDownloadedSeconds, duration.TotalSeconds, new Dictionary <string, string> { { PackageUri, absoluteUri }, { PackageSize, size.ToString() }, }); _telemetryClient.TrackMetric( PackageDownloadSpeed, duration.TotalSeconds > 0 ? size / duration.TotalSeconds : DefaultDownloadSpeed, new Dictionary <string, string> { { PackageUri, absoluteUri }, { PackageSize, size.ToString() }, }); }
public void TrackInstanceReboot(string region, int index) { _telemetryClient.TrackMetric(InstanceReboot, 1, new Dictionary <string, string> { { Subscription, _subscription }, { Region, region }, { InstanceIndex, index.ToString() }, }); }
public void TrackRunDuration(TimeSpan duration, bool completed) { _telemetryClient.TrackMetric( RunDuration, duration.TotalSeconds, new Dictionary <string, string> { { Completed, completed.ToString() } }); }
public void TrackPackageNotFoundEvent(string packageId, string packageNormalizedVersion) { _telemetryClient.TrackMetric( PackageNotFound, 1, new Dictionary <string, string> { { PackageId, packageId }, { PackageNormalizedVersion, packageNormalizedVersion } }); }
public void TrackPackageCreationLag(DateTimeOffset eventTime, Instance instance, string packageId, string packageVersion, TimeSpan createdDelay) { _telemetryClient.TrackMetric(CreatedLagName, createdDelay.TotalSeconds, new Dictionary <string, string> { { PackageId, packageId }, { PackageVersion, packageVersion }, { Region, instance.Region }, { Subscription, _subscription }, { InstanceIndex, instance.Index.ToString() } }); }
public void TrackPackageRevalidationMarkedAsCompleted(string packageId, string normalizedVersion) { _client.TrackMetric( PackageRevalidationMarkedAsCompleted, 1, new Dictionary <string, string> { { PackageId, packageId }, { NormalizedVersion, normalizedVersion }, }); }
public async Task Synchronize(CancellationToken cancellationToken) { var bearerToken = await _authenticator.GetBearerTokenForApplicationAsync(); _bearerTokenSetter.SetBearerToken(bearerToken, false); _currentUserSetter.SetCurrentUserOid(_synchronizationUserOid); var currentUser = _claimsProvider.GetCurrentUser(); var claimsIdentity = new ClaimsIdentity(); claimsIdentity.AddClaim(new Claim(ClaimsExtensions.Oid, _synchronizationUserOid.ToString())); currentUser.AddIdentity(claimsIdentity); foreach (var plant in await _plantCache.GetPlantWithAccessForUserAsync(_synchronizationUserOid)) { _logger.LogInformation($"Synchronizing plant {plant}..."); _plantSetter.SetPlant(plant); await _claimsTransformation.TransformAsync(currentUser); var startTime = TimeService.UtcNow; // todo Synchronize here var endTime = TimeService.UtcNow; _logger.LogInformation($"Plant {plant} synchronized. Duration: {(endTime - startTime).TotalSeconds}s."); _telemetryClient.TrackMetric("Synchronization Time", (endTime - startTime).TotalSeconds, "Plant", plant); } }
protected virtual void TrackMetric(string metricName, double value, Action <Dictionary <string, string> > addProperties) { var telemetryProperties = new Dictionary <string, string>(); addProperties(telemetryProperties); _telemetryClient.TrackMetric(metricName, value, telemetryProperties); }
public void TrackExporterDuration(string exporter, string report, TimeSpan duration, bool success) { _telemetryClient.TrackMetric( Prefix + "ExporterDurationMs", duration.TotalMilliseconds, new Dictionary <string, string> { { "Exporter", exporter }, { "Report", report }, { "Success", success.ToString() }, }); }
public async Task SendMessageChunk() { try { _logger.LogInformation($"BusSenderService SendMessageChunk starting at: {DateTimeOffset.Now}"); var events = await _busEventRepository.GetEarliestUnProcessedEventChunk(); if (events.Any()) { _telemetryClient.TrackMetric("BusSender Chunk", events.Count); } _logger.LogInformation($"BusSenderService found {events.Count} messages to process"); foreach (var busEvent in events) { var message = JsonSerializer.Deserialize <BusEventMessage>(WashString(busEvent.Message)); if (message.ProjectName == null) { message.ProjectName = "_"; } TrackMetric(message); await _topicClients.SendAsync(busEvent.Event, WashString(busEvent.Message)); TrackEvent(busEvent.Event, message); busEvent.Sent = Status.Sent; await _unitOfWork.SaveChangesAsync(); } } catch (Exception exception) { _logger.LogError(exception, $"BusSenderService execute send failed at: {DateTimeOffset.Now}"); throw; } _logger.LogInformation($"BusSenderService SendMessageChunk finished at: {DateTimeOffset.Now}"); _telemetryClient.Flush(); }
public void TrackDurationToValidationSetCreation(TimeSpan duration) { _telemetryClient.TrackMetric( DurationToValidationSetCreationSeconds, duration.TotalSeconds); }
public void TrackFeatureFlagStaleness(TimeSpan staleness) { _telemetryClient.TrackMetric( FeatureFlagStalenessSeconds, staleness.TotalSeconds); }
private void TrackMetricCore(string metricName, double value) { _client.TrackMetric(metricName, value); }
public void TrackDurationToValidationSetCreation(string packageId, string normalizedVersion, Guid validationTrackingId, TimeSpan duration) { _telemetryClient.TrackMetric( DurationToValidationSetCreationSeconds, duration.TotalSeconds, new Dictionary <string, string> { { PackageId, packageId }, { NormalizedVersion, normalizedVersion }, { ValidationTrackingId, validationTrackingId.ToString() }, }); }
public async Task <IHttpJsonResponseMessage <T> > GetJsonAsync <T>( Uri requestUri, TimeSpan?requestTimeout = null, AuthenticationHeaderValue authenticationHeaderValue = null) { // SocialGist only accepts TLS 1.1 or higher. AzureFunctions (on Azure) default to SSL3 or TLS // AzureFunctions runing locally use defaults that work with SocialGist but remote Azure Functions do not. ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11; log.Verbose($"Retrieving URL using protocol: {ServicePointManager.SecurityProtocol}"); telemetryClient.TrackEvent(TelemetryNames.HTTP_Get, new Dictionary <string, string> { { "URL", requestUri.ToString() } }); var handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }; using (var client = new System.Net.Http.HttpClient(handler)) { if (requestTimeout.HasValue) { client.Timeout = requestTimeout.Value; } if (authenticationHeaderValue != null) { client.DefaultRequestHeaders.Authorization = authenticationHeaderValue; } string data = ""; HttpResponseMessage response = null; int retryCount = 0; while (retryCount < RETRY_COUNT) { try { telemetryClient.TrackEvent(TelemetryNames.HTTP_Try, new Dictionary <string, string> { { "URL", requestUri?.ToString() }, { "try number", retryCount.ToString() } }); log.Verbose($"Retrieving URL {requestUri} on attempt {retryCount}"); // Track telemetry for each host query using (var tracker = telemetryClient.StartTrackDependency(requestUri.Host, requestUri.AbsolutePath, "HTTP")) { tracker.Properties.Add("Request URL", requestUri?.ToString()); tracker.Properties.Add("Try attempt", retryCount.ToString()); try { response = await client.GetAsync(requestUri); } catch (TaskCanceledException) { tracker.IsSuccess = false; tracker.ResultCode = "Task Canceled (HTTP Timeout)"; throw; } catch (HttpRequestException e) { tracker.IsSuccess = false; tracker.ResultCode = $"HTTPException: {e.Message}"; throw; } tracker.IsSuccess = response.IsSuccessStatusCode; tracker.ResultCode = response.StatusCode.ToString(); // Get data after setting telemetry status codes incase this errors out. data = await response.Content.ReadAsStringAsync(); if (!response.IsSuccessStatusCode) { // Do not store this data unless the request failed. This data can get very large very fast. tracker.Properties.Add("Server Response", data); } } if (response.IsSuccessStatusCode) { this.objectLogger.Log(data, "HttpClient", requestUri.ToString()); // Successfully completed request break; } else { telemetryClient.TrackEvent(TelemetryNames.HTTP_Error, new Dictionary <string, string> { { "URL", requestUri?.ToString() }, { "StatusCode", response?.StatusCode.ToString() } }); retryCount = HandleFailure(retryCount, requestUri, response); } } catch (Exception e) { retryCount++; telemetryClient.TrackEvent(TelemetryNames.HTTP_Error, new Dictionary <string, string> { { "URL", requestUri?.ToString() }, { "StatusCode", response?.StatusCode.ToString() }, { "Exception", e.ToString() } }); if (retryCount < RETRY_COUNT) { log.Error($"Error executing web request for URL {requestUri} on attempt {retryCount}. Retrying.", e); } else { log.Error($"Error executing web request for URI {requestUri} on attempt {retryCount}. NOT retrying", e); // Rethrow the exception to fail the current job throw; } } // Do not wait after the final try. if (retryCount < RETRY_COUNT) { // Request failed. Wait a random time and try again. Random() uses a time-dependent seed. int wait = new Random().Next((int)minWaitBeforeRetry.TotalMilliseconds, (int)maxWaitBeforeRetry.TotalMilliseconds); log.Verbose($"Waiting {wait} milliseconds before retrying"); Thread.Sleep(wait); } } log.Verbose($"URL {requestUri} retrieved."); var metric = new MetricTelemetry(); metric.Name = TelemetryNames.HTTP_RetryCount; metric.Sum = retryCount; metric.Timestamp = DateTime.Now; metric.Properties.Add("Domain", requestUri.Host); telemetryClient.TrackMetric(metric); try { var obj = JsonConvert.DeserializeObject <T>(data); log.Verbose($"Result deserialized from URL {requestUri}"); return(new HttpJsonResponseMessage <T> { Object = obj, ResponseMessage = response }); } catch (Exception e) { telemetryClient.TrackEvent(TelemetryNames.HTTP_JSON_Error, new Dictionary <string, string> { { "URL", requestUri?.ToString() }, { "StatusCode", response?.StatusCode.ToString() }, { "Exception", e.ToString() }, { "Response", data } }); // Log and rethrow the exception log.Error($"Error deserializing result from URL {requestUri}", e); // Rethrow the exception to fail the current job throw; } } }
public void TrackDurationToHashPackage(TimeSpan duration, string packageId, string normalizedVersion, string hashAlgorithm, string streamType) { _telemetryClient.TrackMetric( DurationToHashPackageSeconds, duration.TotalSeconds, new Dictionary <string, string> { { PackageId, packageId }, { NormalizedVersion, normalizedVersion }, { PackageSize, PackageSize.ToString() }, { HashAlgorithm, hashAlgorithm }, { StreamType, streamType }, }); }
public void Dispose() => _telemetry.TrackMetric(_name, _timer.Elapsed.TotalSeconds, _properties);
public void TrackCatalogIndexReadDuration(TimeSpan duration, Uri uri) { if (uri == null) { throw new ArgumentNullException(nameof(uri)); } _telemetryClient.TrackMetric( TelemetryConstants.CatalogIndexReadDurationSeconds, duration.TotalSeconds, new Dictionary <string, string> { { TelemetryConstants.Uri, uri.AbsoluteUri }, }); }
public void TrackIndexPushSuccess(string indexName, int documentCount, TimeSpan elapsed) { _telemetryClient.TrackMetric( Prefix + "IndexPushSuccessSeconds", elapsed.TotalSeconds, new Dictionary <string, string> { { "IndexName", indexName }, { "DocumentCount", documentCount.ToString() }, }); }
public void TrackCertificateRevalidationTakingTooLong() => _client.TrackMetric(CertificateRevalidationTakingTooLong, 1);