zitadel/internal/tracing/http_handler.go
Silvan 168242e725
fix(tracing): from opencensus to opentelemetry (#937)
* refactor: switch from opencensus to opentelemetry

* tempo works as designed nooooot

* fix: log traceids

* with grafana agent

* fix: http tracing

* fix: cleanup files

* chore: remove todo

* fix: bad test

* fix: ignore methods in grpc interceptors

* fix: remove test log

* clean up

* typo

* fix(config): configure tracing endpoint

* fix(span): add error id to span
2020-11-20 07:57:39 +01:00

32 lines
767 B
Go

package tracing
import (
"net/http"
"strings"
http_trace "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
)
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
}
}
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()
}