Exemplo n.º 1
0
        private static void ProcessException(TelemetrySpan span, Exception exception)
        {
            if (exception is WebException wexc)
            {
                if (wexc.Response is HttpWebResponse response)
                {
                    span.PutHttpStatusCode((int)response.StatusCode, response.StatusDescription);
                    return;
                }

                switch (wexc.Status)
                {
                case WebExceptionStatus.Timeout:
                    span.Status = Status.DeadlineExceeded;
                    return;

                case WebExceptionStatus.NameResolutionFailure:
                    span.Status = Status.InvalidArgument.WithDescription(exception.Message);
                    return;

                case WebExceptionStatus.SendFailure:
                case WebExceptionStatus.ConnectFailure:
                case WebExceptionStatus.SecureChannelFailure:
                case WebExceptionStatus.TrustFailure:
                    span.Status = Status.FailedPrecondition.WithDescription(exception.Message);
                    return;

                case WebExceptionStatus.ServerProtocolViolation:
                    span.Status = Status.Unimplemented.WithDescription(exception.Message);
                    return;

                case WebExceptionStatus.RequestCanceled:
                    span.Status = Status.Cancelled;
                    return;

                case WebExceptionStatus.MessageLengthLimitExceeded:
                    span.Status = Status.ResourceExhausted.WithDescription(exception.Message);
                    return;
                }
            }

            span.Status = Status.Unknown.WithDescription(exception.Message);
        }