forked from zitadel/zitadel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
http_handler.go
34 lines (28 loc) · 874 Bytes
/
http_handler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package telemetry
import (
"net/http"
"strings"
"github.com/dennigogo/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()
}