2020-03-24 14:15:01 +01:00
|
|
|
package tracing
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
|
2020-11-20 07:57:39 +01:00
|
|
|
http_trace "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
2020-03-24 14:15:01 +01:00
|
|
|
)
|
|
|
|
|
2020-11-20 07:57:39 +01: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
|
2020-10-21 10:18:34 +02:00
|
|
|
}
|
2020-11-20 07:57:39 +01:00
|
|
|
}
|
|
|
|
return true
|
2020-03-24 14:15:01 +01:00
|
|
|
}
|
|
|
|
}
|
2020-11-20 07:57:39 +01: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()
|
|
|
|
}
|