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