private static void AddResponseTags(HttpWebResponse response, Activity activity)
        {
            activity.SetCustomProperty("HttpWebRequest.Response", response);

            if (activity.IsAllDataRequested)
            {
                activity.AddTag(SpanAttributeConstants.HttpStatusCodeKey, HttpTagHelper.GetStatusCodeTagValueFromHttpStatusCode(response.StatusCode));

                Status status = SpanHelper.ResolveSpanStatusForHttpStatusCode((int)response.StatusCode);

                activity.AddTag(SpanAttributeConstants.StatusCodeKey, SpanHelper.GetCachedCanonicalCodeString(status.CanonicalCode));
                activity.AddTag(SpanAttributeConstants.StatusDescriptionKey, response.StatusDescription);
            }
        }
        private static void AddResponseTags(HttpWebResponse response, Activity activity)
        {
            activity.SetCustomProperty("HttpWebRequest.Response", response);

            if (activity.IsAllDataRequested)
            {
                activity.AddTag(SemanticConventions.AttributeHttpStatusCode, HttpTagHelper.GetStatusCodeTagValueFromHttpStatusCode(response.StatusCode));

                activity.SetStatus(
                    SpanHelper
                    .ResolveSpanStatusForHttpStatusCode((int)response.StatusCode)
                    .WithDescription(response.StatusDescription));
            }
        }
        private static void AddExceptionTags(Exception exception, Activity activity)
        {
            activity.SetCustomProperty("HttpWebRequest.Exception", exception);

            if (!activity.IsAllDataRequested)
            {
                return;
            }

            Status status;

            if (exception is WebException wexc)
            {
                if (wexc.Response is HttpWebResponse response)
                {
                    activity.AddTag(SpanAttributeConstants.HttpStatusCodeKey, HttpTagHelper.GetStatusCodeTagValueFromHttpStatusCode(response.StatusCode));

                    status = SpanHelper.ResolveSpanStatusForHttpStatusCode((int)response.StatusCode).WithDescription(response.StatusDescription);
                }
                else
                {
                    switch (wexc.Status)
                    {
                    case WebExceptionStatus.Timeout:
                        status = Status.DeadlineExceeded;
                        break;

                    case WebExceptionStatus.NameResolutionFailure:
                        status = Status.InvalidArgument.WithDescription(exception.Message);
                        break;

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

                    case WebExceptionStatus.ServerProtocolViolation:
                        status = Status.Unimplemented.WithDescription(exception.Message);
                        break;

                    case WebExceptionStatus.RequestCanceled:
                        status = Status.Cancelled;
                        break;

                    case WebExceptionStatus.MessageLengthLimitExceeded:
                        status = Status.ResourceExhausted.WithDescription(exception.Message);
                        break;

                    default:
                        status = Status.Unknown.WithDescription(exception.Message);
                        break;
                    }
                }
            }
            else
            {
                status = Status.Unknown.WithDescription(exception.Message);
            }

            activity.AddTag(SpanAttributeConstants.StatusCodeKey, SpanHelper.GetCachedCanonicalCodeString(status.CanonicalCode));
            activity.AddTag(SpanAttributeConstants.StatusDescriptionKey, status.Description);
        }