1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2024-12-14 11:57:48 +00:00
kyverno/pkg/tracing/http.go
Charles-Edouard Brétéché 39b72eefb9
feat: add http clients tracing (#5630)
* 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>
2022-12-09 09:09:11 +00:00

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...)
}