chore(trace): improve rest tracinghandler (#2783)
This commit is contained in:
@@ -31,7 +31,7 @@ func TracingHandler(serviceName, path string, opts ...TracingOption) func(http.H
|
|||||||
|
|
||||||
ignorePaths := collection.NewSet()
|
ignorePaths := collection.NewSet()
|
||||||
ignorePaths.AddStr(tracingOpts.traceIgnorePaths...)
|
ignorePaths.AddStr(tracingOpts.traceIgnorePaths...)
|
||||||
|
traceHandler := func(checkIgnore bool) func(http.Handler) http.Handler {
|
||||||
return func(next http.Handler) http.Handler {
|
return func(next http.Handler) http.Handler {
|
||||||
propagator := otel.GetTextMapPropagator()
|
propagator := otel.GetTextMapPropagator()
|
||||||
tracer := otel.GetTracerProvider().Tracer(trace.TraceName)
|
tracer := otel.GetTracerProvider().Tracer(trace.TraceName)
|
||||||
@@ -42,7 +42,7 @@ func TracingHandler(serviceName, path string, opts ...TracingOption) func(http.H
|
|||||||
spanName = r.URL.Path
|
spanName = r.URL.Path
|
||||||
}
|
}
|
||||||
|
|
||||||
if ignorePaths.Contains(spanName) {
|
if checkIgnore && ignorePaths.Contains(spanName) {
|
||||||
next.ServeHTTP(w, r)
|
next.ServeHTTP(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -68,10 +68,13 @@ func TracingHandler(serviceName, path string, opts ...TracingOption) func(http.H
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
checkIgnore := ignorePaths.Count() > 0
|
||||||
|
return traceHandler(checkIgnore)
|
||||||
|
}
|
||||||
|
|
||||||
// WithTraceIgnorePaths specifies the traceIgnorePaths option for TracingHandler.
|
// WithTraceIgnorePaths specifies the traceIgnorePaths option for TracingHandler.
|
||||||
func WithTraceIgnorePaths(traceIgnorePaths []string) TracingOption {
|
func WithTraceIgnorePaths(traceIgnorePaths []string) TracingOption {
|
||||||
return func(options *tracingOptions) {
|
return func(options *tracingOptions) {
|
||||||
options.traceIgnorePaths = traceIgnorePaths
|
options.traceIgnorePaths = append(options.traceIgnorePaths, traceIgnorePaths...)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user