From ce3ef13e6a42c675ff4b6a2e0371af6602549f42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=BD=E5=9B=BD=E9=B9=8F?= <1033404553@qq.com> Date: Thu, 29 Feb 2024 20:22:42 +0800 Subject: [PATCH] fix: otel tracing content contains invalid UTF-8 (#3340) --- net/ghttp/ghttp_middleware_tracing.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/net/ghttp/ghttp_middleware_tracing.go b/net/ghttp/ghttp_middleware_tracing.go index 08c71f45e..2309dc35b 100644 --- a/net/ghttp/ghttp_middleware_tracing.go +++ b/net/ghttp/ghttp_middleware_tracing.go @@ -97,7 +97,7 @@ func internalMiddlewareServerTracing(r *Request) { attribute.String(tracingEventHttpRequestUrl, r.URL.String()), attribute.String(tracingEventHttpRequestHeaders, gconv.String(httputil.HeaderToMap(r.Header))), attribute.String(tracingEventHttpRequestBaggage, gtrace.GetBaggageMap(ctx).String()), - attribute.String(tracingEventHttpRequestBody, gstr.StrLimit( + attribute.String(tracingEventHttpRequestBody, gstr.StrLimitRune( string(reqBodyContentBytes), gtrace.MaxContentLogSize(), "...", @@ -112,7 +112,7 @@ func internalMiddlewareServerTracing(r *Request) { span.SetStatus(codes.Error, fmt.Sprintf(`%+v`, err)) } // Response content logging. - var resBodyContent = gstr.StrLimit(r.Response.BufferString(), gtrace.MaxContentLogSize(), "...") + var resBodyContent = gstr.StrLimitRune(r.Response.BufferString(), gtrace.MaxContentLogSize(), "...") if gzipAccepted(r.Response.Header()) { reader, err := gzip.NewReader(strings.NewReader(r.Response.BufferString())) if err != nil { @@ -123,7 +123,7 @@ func internalMiddlewareServerTracing(r *Request) { if err != nil { span.SetStatus(codes.Error, fmt.Sprintf(`get uncompress value err:%+v`, err)) } - resBodyContent = gstr.StrLimit(string(uncompressed), gtrace.MaxContentLogSize(), "...") + resBodyContent = gstr.StrLimitRune(string(uncompressed), gtrace.MaxContentLogSize(), "...") } span.AddEvent(tracingEventHttpResponse, trace.WithAttributes(