protected void RecordTelemetry(string method, int statusCode, string content, ResourceEnum resource, Util.SplitStopwatch clock) { if (statusCode >= (int)HttpStatusCode.OK && statusCode < (int)HttpStatusCode.Ambiguous) { _telemetryRuntimeProducer.RecordSyncLatency(resource, Util.Metrics.Bucket(clock.ElapsedMilliseconds)); _telemetryRuntimeProducer.RecordSuccessfulSync(resource, CurrentTimeHelper.CurrentTimeMillis()); } else { _log.Error($"Http status executing {method}: {statusCode.ToString()} - {content}"); _telemetryRuntimeProducer.RecordSyncError(resource, statusCode); } }
public async Task <AuthenticationResponse> AuthenticateAsync() { using (var clock = new Util.SplitStopwatch()) { clock.Start(); try { var response = await _splitioHttpClient.GetAsync(_url); if (response.statusCode == HttpStatusCode.OK) { _log.Debug($"Success connection to: {_url}"); _telemetryRuntimeProducer.RecordSyncLatency(ResourceEnum.TokenSync, Util.Metrics.Bucket(clock.ElapsedMilliseconds)); _telemetryRuntimeProducer.RecordSuccessfulSync(ResourceEnum.TokenSync, CurrentTimeHelper.CurrentTimeMillis()); return(GetSuccessResponse(response.content)); } else if (response.statusCode >= HttpStatusCode.BadRequest && response.statusCode < HttpStatusCode.InternalServerError) { _log.Debug($"Problem to connect to : {_url}. Response status: {response.statusCode}"); _telemetryRuntimeProducer.RecordAuthRejections(); return(new AuthenticationResponse { PushEnabled = false, Retry = false }); } _telemetryRuntimeProducer.RecordSyncError(ResourceEnum.TokenSync, (int)response.statusCode); return(new AuthenticationResponse { PushEnabled = false, Retry = true }); } catch (Exception ex) { _log.Error(ex.Message); return(new AuthenticationResponse { PushEnabled = false, Retry = false }); } } }