zitadel/internal/telemetry/http_handler.go
Florian Forster fa9f581d56
chore(v2): move to new org (#3499)
* chore: move to new org

* logging

* fix: org rename caos -> zitadel

Co-authored-by: adlerhurst <silvan.reusser@gmail.com>
2022-04-26 23:01:45 +00:00

35 lines
872 B
Go

package telemetry
import (
"net/http"
"strings"
"github.com/zitadel/zitadel/internal/telemetry/metrics"
"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 TelemetryHandler(handler http.Handler, ignoredEndpoints ...string) http.Handler {
return otelhttp.NewHandler(handler,
"zitadel",
otelhttp.WithFilter(shouldNotIgnore(ignoredEndpoints...)),
otelhttp.WithPublicEndpoint(),
otelhttp.WithSpanNameFormatter(spanNameFormatter),
otelhttp.WithMeterProvider(metrics.GetMetricsProvider()))
}
func spanNameFormatter(_ string, r *http.Request) string {
return r.Host + r.URL.EscapedPath()
}