mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 19:14:23 +00:00
fa9f581d56
* chore: move to new org * logging * fix: org rename caos -> zitadel Co-authored-by: adlerhurst <silvan.reusser@gmail.com>
35 lines
872 B
Go
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()
|
|
}
|