zitadel/internal/tracing/http_handler.go

32 lines
767 B
Go
Raw Normal View History

2020-03-24 13:15:01 +00:00
package tracing
import (
"net/http"
"strings"
http_trace "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
2020-03-24 13:15:01 +00:00
)
func shouldNotIgnore(endpoints ...string) func(r *http.Request) bool {
return func(r *http.Request) bool {
for _, endpoint := range endpoints {
if strings.HasPrefix(r.URL.RequestURI(), endpoint) {
return false
}
}
return true
2020-03-24 13:15:01 +00:00
}
}
func TraceHandler(handler http.Handler, ignoredEndpoints ...string) http.Handler {
return http_trace.NewHandler(handler,
"zitadel",
http_trace.WithFilter(shouldNotIgnore(ignoredEndpoints...)),
http_trace.WithPublicEndpoint(),
http_trace.WithSpanNameFormatter(spanNameFormatter))
}
func spanNameFormatter(_ string, r *http.Request) string {
return r.Host + r.URL.EscapedPath()
}