Skip to content

Commit fec77c8

Browse files
authored
Use local variable for span (#63)
Signed-off-by: Yuri Shkuro <[email protected]>
1 parent a144f18 commit fec77c8

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

nethttp/client.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build go1.7
12
// +build go1.7
23

34
package nethttp
@@ -182,36 +183,36 @@ func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) {
182183
return rt.RoundTrip(req)
183184
}
184185

185-
tracer.start(req)
186+
sp := tracer.start(req)
186187

187-
ext.HTTPMethod.Set(tracer.sp, req.Method)
188-
ext.HTTPUrl.Set(tracer.sp, tracer.opts.urlTagFunc(req.URL))
189-
ext.PeerAddress.Set(tracer.sp, req.URL.Host)
190-
tracer.opts.spanObserver(tracer.sp, req)
188+
ext.HTTPMethod.Set(sp, req.Method)
189+
ext.HTTPUrl.Set(sp, tracer.opts.urlTagFunc(req.URL))
190+
ext.PeerAddress.Set(sp, req.URL.Host)
191+
tracer.opts.spanObserver(sp, req)
191192

192193
if !tracer.opts.disableInjectSpanContext {
193194
carrier := opentracing.HTTPHeadersCarrier(req.Header)
194-
tracer.sp.Tracer().Inject(tracer.sp.Context(), opentracing.HTTPHeaders, carrier)
195+
sp.Tracer().Inject(sp.Context(), opentracing.HTTPHeaders, carrier)
195196
}
196197

197198
resp, err := rt.RoundTrip(req)
198199

199200
if err != nil {
200-
tracer.sp.Finish()
201+
sp.Finish()
201202
return resp, err
202203
}
203-
ext.HTTPStatusCode.Set(tracer.sp, uint16(resp.StatusCode))
204+
ext.HTTPStatusCode.Set(sp, uint16(resp.StatusCode))
204205
if resp.StatusCode >= http.StatusInternalServerError {
205-
ext.Error.Set(tracer.sp, true)
206+
ext.Error.Set(sp, true)
206207
}
207208
if req.Method == "HEAD" {
208-
tracer.sp.Finish()
209+
sp.Finish()
209210
} else {
210211
readWriteCloser, ok := resp.Body.(io.ReadWriteCloser)
211212
if ok {
212-
resp.Body = writerCloseTracker{readWriteCloser, tracer.sp}
213+
resp.Body = writerCloseTracker{readWriteCloser, sp}
213214
} else {
214-
resp.Body = closeTracker{resp.Body, tracer.sp}
215+
resp.Body = closeTracker{resp.Body, sp}
215216
}
216217
}
217218
return resp, nil

0 commit comments

Comments
 (0)