17 | 17 |
const (
|
18 | 18 |
keyTracer contextKey = iota
|
19 | 19 |
)
|
|
20 |
|
|
21 |
const defaultComponentName = "net/http"
|
20 | 22 |
|
21 | 23 |
// Transport wraps a RoundTripper. If a request is being traced with
|
22 | 24 |
// Tracer, Transport will inject the current span into the headers,
|
|
28 | 30 |
}
|
29 | 31 |
|
30 | 32 |
type clientOptions struct {
|
31 | |
opName string
|
|
33 |
operationName string
|
|
34 |
componentName string
|
32 | 35 |
disableClientTrace bool
|
33 | 36 |
}
|
34 | 37 |
|
|
37 | 40 |
|
38 | 41 |
// OperationName returns a ClientOption that sets the operation
|
39 | 42 |
// name for the client-side span.
|
40 | |
func OperationName(opName string) ClientOption {
|
|
43 |
func OperationName(operationName string) ClientOption {
|
41 | 44 |
return func(options *clientOptions) {
|
42 | |
options.opName = opName
|
|
45 |
options.operationName = operationName
|
|
46 |
}
|
|
47 |
}
|
|
48 |
|
|
49 |
// ComponentName returns a ClientOption that sets the component
|
|
50 |
// name for the client-side span.
|
|
51 |
func ComponentName(componentName string) ClientOption {
|
|
52 |
return func(options *clientOptions) {
|
|
53 |
options.componentName = componentName
|
43 | 54 |
}
|
44 | 55 |
}
|
45 | 56 |
|
|
149 | 160 |
if parent != nil {
|
150 | 161 |
spanctx = parent.Context()
|
151 | 162 |
}
|
152 | |
opName := h.opts.opName
|
153 | |
if opName == "" {
|
154 | |
opName = "HTTP Client"
|
|
163 |
operationName := h.opts.operationName
|
|
164 |
if operationName == "" {
|
|
165 |
operationName = "HTTP Client"
|
155 | 166 |
}
|
156 | |
root := h.tr.StartSpan(opName, opentracing.ChildOf(spanctx))
|
|
167 |
root := h.tr.StartSpan(operationName, opentracing.ChildOf(spanctx))
|
157 | 168 |
h.root = root
|
158 | 169 |
}
|
159 | 170 |
|
160 | 171 |
ctx := h.root.Context()
|
161 | 172 |
h.sp = h.tr.StartSpan("HTTP "+req.Method, opentracing.ChildOf(ctx))
|
162 | 173 |
ext.SpanKindRPCClient.Set(h.sp)
|
163 | |
ext.Component.Set(h.sp, "net/http")
|
|
174 |
|
|
175 |
componentName := h.opts.componentName
|
|
176 |
if componentName == "" {
|
|
177 |
componentName = defaultComponentName
|
|
178 |
}
|
|
179 |
ext.Component.Set(h.sp, componentName)
|
164 | 180 |
|
165 | 181 |
return h.sp
|
166 | 182 |
}
|