feat: add tracingHandler

main
git 2024-12-28 22:56:54 +08:00
parent d7a0e82797
commit 1c575a19c9
Signed by: git
GPG Key ID: 3F65EFFA44207ADD
2 changed files with 8 additions and 8 deletions

View File

@ -59,6 +59,9 @@ func Handle[In any, Out any](fn UnaryFunc[In, Out]) func(w http.ResponseWriter,
}
_ = render.Render(w, r, APIOK(out))
}
f = tracingHandler(handleName, f)
return f
}
@ -106,6 +109,8 @@ func Stream[In any](fn StreamFunc[In]) func(w http.ResponseWriter, r *http.Reque
_ = render.Render(w, r, APIError(err))
}
}
f = tracingHandler(handleName, f)
return f
}

View File

@ -56,14 +56,9 @@ func collectHandleMetrics(funcName, method string, st time.Time, err error) {
responseTimeDuration.WithLabelValues(funcName, method, codeStr).Observe(duration)
}
// TracingHandler
func tracingHandler(operation string) func(next http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
next.ServeHTTP(w, r)
}
return otelhttp.NewHandler(http.HandlerFunc(fn), operation)
}
// tracingHandler
func tracingHandler(operation string, fn func(w http.ResponseWriter, r *http.Request)) func(w http.ResponseWriter, r *http.Request) {
return otelhttp.NewHandler(http.HandlerFunc(fn), operation).ServeHTTP
}
func init() {