chore(tracing): embed the opentracing.Span
Signed-off-by: Gianluca Arbezzano <gianarb92@gmail.com>pull/17499/head
parent
af06897014
commit
8e5bd1a2dd
|
@ -79,30 +79,25 @@ func annotateSpan(span opentracing.Span, handlerName string, req *http.Request)
|
|||
|
||||
// span is a simple wrapper around opentracing.Span in order to
|
||||
// get access to the duration of the span for metrics reporting.
|
||||
type WrappedSpan struct {
|
||||
s opentracing.Span
|
||||
type Span struct {
|
||||
opentracing.Span
|
||||
start time.Time
|
||||
Duration time.Duration
|
||||
hist prometheus.Observer
|
||||
gauge prometheus.Gauge
|
||||
}
|
||||
|
||||
func StartSpanFromContextWithPromMetircs(ctx context.Context, operationName string, hist prometheus.Observer, gauge prometheus.Gauge, opts ...opentracing.StartSpanOption) (*WrappedSpan, context.Context) {
|
||||
func StartSpanFromContextWithPromMetrics(ctx context.Context, operationName string, hist prometheus.Observer, gauge prometheus.Gauge, opts ...opentracing.StartSpanOption) (*Span, context.Context) {
|
||||
start := time.Now()
|
||||
s, sctx := StartSpanFromContextWithOperationName(ctx, operationName, opentracing.StartTime(start))
|
||||
gauge.Inc()
|
||||
return &WrappedSpan{
|
||||
s: s,
|
||||
start: start,
|
||||
hist: hist,
|
||||
gauge: gauge,
|
||||
}, sctx
|
||||
return &Span{s, start, 0, hist, gauge}, sctx
|
||||
}
|
||||
|
||||
func (s *WrappedSpan) Finish() {
|
||||
func (s *Span) Finish() {
|
||||
finish := time.Now()
|
||||
s.Duration = finish.Sub(s.start)
|
||||
s.s.FinishWithOptions(opentracing.FinishOptions{
|
||||
s.Span.FinishWithOptions(opentracing.FinishOptions{
|
||||
FinishTime: finish,
|
||||
})
|
||||
s.hist.Observe(s.Duration.Seconds())
|
||||
|
|
|
@ -261,7 +261,7 @@ func (c *Controller) createQuery(ctx context.Context, ct flux.CompilerType) (*Qu
|
|||
compileLabelValues[len(compileLabelValues)-1] = string(ct)
|
||||
|
||||
cctx, cancel := context.WithCancel(ctx)
|
||||
parentSpan, parentCtx := tracing.StartSpanFromContextWithPromMetircs(
|
||||
parentSpan, parentCtx := tracing.StartSpanFromContextWithPromMetrics(
|
||||
cctx,
|
||||
"all",
|
||||
c.metrics.allDur.WithLabelValues(labelValues...),
|
||||
|
@ -523,7 +523,7 @@ type Query struct {
|
|||
cancel func()
|
||||
|
||||
parentCtx context.Context
|
||||
parentSpan, currentSpan *tracing.WrappedSpan
|
||||
parentSpan, currentSpan *tracing.Span
|
||||
stats flux.Statistics
|
||||
|
||||
done sync.Once
|
||||
|
@ -750,7 +750,7 @@ TRANSITION:
|
|||
return q.parentCtx, true
|
||||
}
|
||||
var currentCtx context.Context
|
||||
q.currentSpan, currentCtx = tracing.StartSpanFromContextWithPromMetircs(
|
||||
q.currentSpan, currentCtx = tracing.StartSpanFromContextWithPromMetrics(
|
||||
q.parentCtx,
|
||||
newState.String(),
|
||||
dur.WithLabelValues(labelValues...),
|
||||
|
|
Loading…
Reference in New Issue