mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-15 20:38:00 +00:00
25ef3da9d5
chore(fmt): run gci on complete project Fix global import formatting in go code by running the `gci` command. This allows us to just use the command directly, instead of fixing the import order manually for the linter, on each PR. Co-authored-by: Elio Bischof <elio@zitadel.com>
35 lines
872 B
Go
35 lines
872 B
Go
package telemetry
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
|
|
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
|
|
|
"github.com/zitadel/zitadel/internal/telemetry/metrics"
|
|
)
|
|
|
|
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()
|
|
}
|