Exemple #1
0
 public Configuration()
 {
     App           = new App();
     Format        = new Format();
     Peloton       = new Peloton();
     Garmin        = new Garmin();
     Observability = new Observability();
     Developer     = new Developer();
 }
Exemple #2
0
        public static void Configure(Observability config, int defaultTimeoutSeconds = 10)
        {
            Func <FlurlCall, Task> beforeCallAsync = (FlurlCall call) =>
            {
                try
                {
                    Log.Verbose("HTTP Request: {@HttpMethod} - {@Uri} - {@Headers} - {@Content}", call.HttpRequestMessage.Method, call.HttpRequestMessage.RequestUri, call.HttpRequestMessage.Headers.ToString(), call.HttpRequestMessage.Content);
                }
                catch { Console.WriteLine("Error in Flurl.beforeCallAsync"); }

                return(Task.CompletedTask);
            };

            Func <FlurlCall, Task> afterCallAsync = async(FlurlCall call) =>
            {
                try
                {
                    Log.Verbose("HTTP Response: {@HttpStatusCode} - {@HttpMethod} - {@Uri} - {@Headers} - {@Content}", call.HttpResponseMessage?.StatusCode, call.HttpRequestMessage?.Method, call.HttpRequestMessage?.RequestUri, call.HttpResponseMessage.Headers.ToString(), await call.HttpResponseMessage?.Content?.ReadAsStringAsync());

                    if (config.Prometheus.Enabled)
                    {
                        HttpRequestHistogram
                        .WithLabels(
                            call.HttpRequestMessage.Method.ToString(),
                            call.HttpRequestMessage.RequestUri.Host,
                            call.HttpRequestMessage.RequestUri.AbsolutePath,
                            call.HttpRequestMessage.RequestUri.Query,
                            ((int)call.HttpResponseMessage.StatusCode).ToString(),
                            call.HttpResponseMessage.ReasonPhrase
                            ).Observe(call.Duration.GetValueOrDefault().TotalSeconds);
                    }
                } catch { Console.WriteLine("Error in Flurl.afterCallAsync"); }
            };

            Func <FlurlCall, Task> onErrorAsync = async(FlurlCall call) =>
            {
                try
                {
                    var response = string.Empty;
                    if (call.HttpResponseMessage is object)
                    {
                        response = await call.HttpResponseMessage?.Content?.ReadAsStringAsync();
                    }
                    Log.Error("Http Call Failed. {@HttpStatusCode} {@Content}", call.HttpResponseMessage?.StatusCode, response);
                }
                catch { Console.WriteLine("Error in Flurl.onErrorAsync"); }
            };

            FlurlHttp.Configure(settings =>
            {
                settings.Timeout                  = new TimeSpan(0, 0, defaultTimeoutSeconds);
                settings.BeforeCallAsync          = beforeCallAsync;
                settings.AfterCallAsync           = afterCallAsync;
                settings.OnErrorAsync             = onErrorAsync;
                settings.Redirects.ForwardHeaders = true;
            });
        }
Exemple #3
0
        public static void ValidateConfig(Observability config)
        {
            if (!config.Prometheus.Enabled)
            {
                return;
            }

            if (config.Prometheus.Port.HasValue && config.Prometheus.Port <= 0)
            {
                Log.Error("Prometheus Port must be a valid port: {@ConfigSection}.{@ConfigProperty}.", nameof(config), nameof(config.Prometheus.Port));
                throw new ArgumentException("Prometheus port must be greater than 0.", nameof(config.Prometheus.Port));
            }
        }
Exemple #4
0
        public static void ValidateConfig(Observability config)
        {
            if (!config.Jaeger.Enabled)
            {
                return;
            }

            if (string.IsNullOrEmpty(config.Jaeger.AgentHost))
            {
                Log.Error("Agent Host must be set: {@ConfigSection}.{@ConfigProperty}.", nameof(config), nameof(config.Jaeger.AgentHost));
                throw new ArgumentException("Agent Host must be set.", nameof(config.Jaeger.AgentHost));
            }

            if (config.Jaeger.AgentPort is null || config.Jaeger.AgentPort <= 0)
            {
                Log.Error("Agent Port must be set: {@ConfigSection}.{@ConfigProperty}.", nameof(config), nameof(config.Jaeger.AgentPort));
                throw new ArgumentException("Agent Port must be a valid port.", nameof(config.Jaeger.AgentPort));
            }
        }
Exemple #5
0
 public AppConfiguration()
 {
     Api           = new ApiSettings();
     Observability = new Observability();
     Developer     = new Developer();
 }