public static void ProcessException(Exception exception, ITelemetryLogger logger) { EnsureArg.IsNotNull(logger, nameof(logger)); var(customException, errorName) = CustomizeException(exception); logger.LogError(customException); string exceptionName = customException.Equals(exception) ? $"{ErrorType.FHIRServiceError}{errorName}" : customException.GetType().Name; _exceptionTelemetryProcessor.LogExceptionMetric(customException, logger, FhirClientMetrics.HandledException(exceptionName, ErrorSeverity.Critical)); }
protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { var requestContext = new TokenRequestContext(Scopes); var accessToken = await TokenCredential.GetTokenAsync(requestContext, cancellationToken); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken.Token); var response = await base.SendAsync(request, cancellationToken); if (!response.IsSuccessStatusCode) { var statusDescription = response.ReasonPhrase.Replace(" ", string.Empty); var severity = response.StatusCode == System.Net.HttpStatusCode.TooManyRequests ? ErrorSeverity.Informational : ErrorSeverity.Critical; Logger.LogMetric(FhirClientMetrics.HandledException($"{ErrorType.FHIRServiceError}{statusDescription}", severity), 1); } return(response); }
protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { var requestContext = new TokenRequestContext(Scopes); var accessToken = await TokenCredential.GetTokenAsync(requestContext, CancellationToken.None); request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken.Token); var response = await base.SendAsync(request, cancellationToken); if (Logger != null && !response.IsSuccessStatusCode) { var statusDescription = response.ReasonPhrase.Replace(" ", string.Empty); if (response.StatusCode == System.Net.HttpStatusCode.TooManyRequests) { Logger.LogMetric(FhirClientMetrics.HandledException($"FhirServerError{statusDescription}", ErrorSeverity.Informational, ConnectorOperation.FHIRConversion), 1); } else { Logger.LogMetric(FhirClientMetrics.HandledException($"FhirServerError{statusDescription}", ErrorSeverity.Critical, ConnectorOperation.FHIRConversion), 1); } } return(response); }