mirror of
https://github.com/kyverno/kyverno.git
synced 2024-12-15 17:51:20 +00:00
39b72eefb9
* feat: add http clients tracing Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> * check we are in a span before creating one and and context to metrics recording calls Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com> Co-authored-by: shuting <shuting@nirmata.com>
24 lines
593 B
Go
24 lines
593 B
Go
package tracing
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
|
)
|
|
|
|
var defaultSpanFormatter = otelhttp.WithSpanNameFormatter(
|
|
func(_ string, request *http.Request) string {
|
|
return fmt.Sprintf("HTTP %s %s", request.Method, request.URL.Path)
|
|
},
|
|
)
|
|
|
|
func RequestFilterIsInSpan(request *http.Request) bool {
|
|
return IsInSpan(request.Context())
|
|
}
|
|
|
|
func Transport(base http.RoundTripper, opts ...otelhttp.Option) *otelhttp.Transport {
|
|
o := []otelhttp.Option{defaultSpanFormatter}
|
|
o = append(o, opts...)
|
|
return otelhttp.NewTransport(base, o...)
|
|
}
|