@@ -9,7 +9,6 @@ package ghttp
9
9
import (
10
10
"context"
11
11
"fmt"
12
- "io"
13
12
14
13
"go.opentelemetry.io/otel"
15
14
"go.opentelemetry.io/otel/attribute"
@@ -18,9 +17,7 @@ import (
18
17
"go.opentelemetry.io/otel/trace"
19
18
20
19
"github.com/gogf/gf/v2"
21
- "github.com/gogf/gf/v2/errors/gerror"
22
20
"github.com/gogf/gf/v2/internal/httputil"
23
- "github.com/gogf/gf/v2/internal/utils"
24
21
"github.com/gogf/gf/v2/net/gtrace"
25
22
"github.com/gogf/gf/v2/os/gctx"
26
23
"github.com/gogf/gf/v2/util/gconv"
@@ -31,10 +28,8 @@ const (
31
28
tracingEventHttpRequest = "http.request"
32
29
tracingEventHttpRequestHeaders = "http.request.headers"
33
30
tracingEventHttpRequestBaggage = "http.request.baggage"
34
- tracingEventHttpRequestBody = "http.request.body"
35
31
tracingEventHttpResponse = "http.response"
36
32
tracingEventHttpResponseHeaders = "http.response.headers"
37
- tracingEventHttpResponseBody = "http.response.body"
38
33
tracingEventHttpRequestUrl = "http.request.url"
39
34
tracingMiddlewareHandled gctx.StrKey = `MiddlewareServerTracingHandled`
40
35
)
@@ -80,24 +75,10 @@ func internalMiddlewareServerTracing(r *Request) {
80
75
return
81
76
}
82
77
83
- // Request content logging.
84
- reqBodyContentBytes , err := io .ReadAll (r .Body )
85
- if err != nil {
86
- r .SetError (gerror .Wrap (err , `read request body failed` ))
87
- span .SetStatus (codes .Error , fmt .Sprintf (`%+v` , err ))
88
- return
89
- }
90
- r .Body = utils .NewReadCloser (reqBodyContentBytes , false )
91
- reqBodyContent , err := gtrace .SafeContentForHttp (reqBodyContentBytes , r .Header )
92
- if err != nil {
93
- span .SetStatus (codes .Error , fmt .Sprintf (`converting safe content failed: %s` , err .Error ()))
94
- }
95
-
96
78
span .AddEvent (tracingEventHttpRequest , trace .WithAttributes (
97
79
attribute .String (tracingEventHttpRequestUrl , r .URL .String ()),
98
80
attribute .String (tracingEventHttpRequestHeaders , gconv .String (httputil .HeaderToMap (r .Header ))),
99
81
attribute .String (tracingEventHttpRequestBaggage , gtrace .GetBaggageMap (ctx ).String ()),
100
- attribute .String (tracingEventHttpRequestBody , reqBodyContent ),
101
82
))
102
83
103
84
// Continue executing.
@@ -109,18 +90,14 @@ func internalMiddlewareServerTracing(r *Request) {
109
90
}
110
91
111
92
// Error logging.
112
- if err = r .GetError (); err != nil {
93
+ if err : = r .GetError (); err != nil {
113
94
span .SetStatus (codes .Error , fmt .Sprintf (`%+v` , err ))
114
95
}
115
96
116
- // Response content logging.
117
- resBodyContent , err := gtrace .SafeContentForHttp (r .Response .Buffer (), r .Response .Header ())
118
- if err != nil {
119
- span .SetStatus (codes .Error , fmt .Sprintf (`converting safe content failed: %s` , err .Error ()))
120
- }
121
-
122
97
span .AddEvent (tracingEventHttpResponse , trace .WithAttributes (
123
- attribute .String (tracingEventHttpResponseHeaders , gconv .String (httputil .HeaderToMap (r .Response .Header ()))),
124
- attribute .String (tracingEventHttpResponseBody , resBodyContent ),
98
+ attribute .String (
99
+ tracingEventHttpResponseHeaders ,
100
+ gconv .String (httputil .HeaderToMap (r .Response .Header ())),
101
+ ),
125
102
))
126
103
}
0 commit comments