go-stdlib icon indicating copy to clipboard operation
go-stdlib copied to clipboard

why create span twice

Open wuyouyu1992 opened this issue 3 years ago • 0 comments

When i used nethttp,create span twice,I don't think it makes sense req, ht := nethttp.TraceRequest(c.Tracer, req, nethttp.OperationName("HTTP GET: "+endpoint)) defer ht.Finish()

Then I look at the source code func (h *Tracer) start(req *http.Request) opentracing.Span { if h.root == nil { parent := opentracing.SpanFromContext(req.Context()) var spanctx opentracing.SpanContext if parent != nil { spanctx = parent.Context() } operationName := h.opts.operationName if operationName == "" { operationName = "HTTP Client" } root := h.tr.StartSpan(operationName, opentracing.ChildOf(spanctx)) h.root = root }

ctx := h.root.Context()
h.sp = h.tr.StartSpan("HTTP "+req.Method, opentracing.ChildOf(ctx))
ext.SpanKindRPCClient.Set(h.sp)

componentName := h.opts.componentName
if componentName == "" {
	componentName = defaultComponentName
}
ext.Component.Set(h.sp, componentName)

return h.sp

}

I don't understand why span h.sp is created

wuyouyu1992 avatar Jul 13 '21 12:07 wuyouyu1992