/// <summary>
        /// Update a monitor message from HttpContext
        /// </summary>
        /// <param name="message"></param>
        /// <param name="httpContext"></param>
        /// <param name="ex"></param>
        /// <returns></returns>
        public static async Task UpdateForHttpRequest(MonitorMessage message, HttpContext httpContext, Exception ex = null)
        {
            message.EndTime  = DateTimeOffset.UtcNow;
            message.Duration = message.EndTime - message.StartTime;

            var response = httpContext.Response;

            message.ResponseBody = await GetContent(response);

            message.ResponseHeaders = GetHeaders(response.Headers);
            message.ResponseArchitectureMetadata = GetCurrentArchitectureMetadata(httpContext);
            message.ResponseCode = response.StatusCode.ToString();

            if (ex == null)
            {
                message.IsError = response.StatusCode < 200 || response.StatusCode >= 300;
            }
            else
            {
                if (!ProcessShouldSkipException(ex, message))
                {
                    message.IsError      = true;
                    message.ErrorMessage = MonitorHelper.GetErrorString(ex);
                    if (response.StatusCode == 200)
                    {
                        message.ResponseCode = "500";
                    }
                }
            }
        }
        /// <summary>
        /// Update a monitor message from a service bus sender message
        /// </summary>
        /// <param name="message"></param>
        /// <param name="ex"></param>
        /// <returns></returns>
        public static async Task UpdateForServiceBusMessageSender(MonitorMessage message, Exception ex = null)
        {
            message.EndTime  = DateTimeOffset.UtcNow;
            message.Duration = message.EndTime - message.StartTime;

            if (ex != null)
            {
                if (!ProcessShouldSkipException(ex, message))
                {
                    message.IsError      = true;
                    message.ErrorMessage = MonitorHelper.GetErrorString(ex);
                    if (String.IsNullOrEmpty(message.ResponseCode))
                    {
                        message.ResponseCode = "ERROR";
                    }
                }
            }
            else
            {
                if (String.IsNullOrEmpty(message.ResponseCode))
                {
                    message.ResponseCode = "SUCCESS";
                }
            }
        }
        /// <summary>
        /// Update a monitor message from HttpClient
        /// </summary>
        /// <param name="message"></param>
        /// <param name="response"></param>
        /// <param name="ex"></param>
        /// <returns></returns>
        public static async Task UpdateForHttpClient(MonitorMessage message, HttpResponseMessage response, Exception ex = null)
        {
            message.EndTime  = DateTimeOffset.UtcNow;
            message.Duration = message.EndTime - message.StartTime;

            if (response != null)
            {
                message.ResponseBody = await GetContent(response);

                message.ResponseHeaders = GetHeaders(response.Headers);
                message.ResponseArchitectureMetadata = GetArchitectureMetadata(response.Headers);
                message.ResponseCode = ((int)response.StatusCode).ToString();
                message.IsError      = (int)response.StatusCode < 200 || (int)response.StatusCode >= 300;
            }
            if (ex != null)
            {
                if (!ProcessShouldSkipException(ex, message))
                {
                    message.IsError      = true;
                    message.ErrorMessage = MonitorHelper.GetErrorString(ex);
                    if (String.IsNullOrEmpty(message.ResponseCode))
                    {
                        message.ResponseCode = "ERROR";
                    }
                }
            }
        }
        /// <summary>
        /// Update a monitor message from a generic object
        /// </summary>
        /// <param name="message"></param>
        /// <param name="ex"></param>
        /// <returns></returns>
        public static async Task UpdateForGenericObject(MonitorMessage message, Exception ex)
        {
            message.EndTime  = DateTimeOffset.UtcNow;
            message.Duration = message.EndTime - message.StartTime;

            if (ex != null)
            {
                if (!ProcessShouldSkipException(ex, message))
                {
                    message.IsError      = true;
                    message.ErrorMessage = MonitorHelper.GetErrorString(ex);
                    message.ResponseCode = "ERROR";
                }
            }
            else
            {
                message.ResponseCode = "SUCCESS";
            }
        }
        /// <summary>
        /// Hide/mask sencitive header values
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        private static string FilterHeaderValue(string name, string value)
        {
            if (value != null && name != null)
            {
                name = name.ToLower();

                if (name == "authorization")
                {
                    var parts = value.Split(' ');
                    if (parts.Length > 1)
                    {
                        value = parts[0] + " " + MonitorHelper.MaskSecretString(parts[1], 10);
                    }
                }
                if (name.EndsWith("key"))
                {
                    value = MonitorHelper.MaskSecretString(value, 10);
                }
            }
            return(value);
        }