feat: add tracingHandler
parent
d7a0e82797
commit
1c575a19c9
|
@ -59,6 +59,9 @@ func Handle[In any, Out any](fn UnaryFunc[In, Out]) func(w http.ResponseWriter,
|
||||||
}
|
}
|
||||||
_ = render.Render(w, r, APIOK(out))
|
_ = render.Render(w, r, APIOK(out))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
f = tracingHandler(handleName, f)
|
||||||
|
|
||||||
return 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))
|
_ = render.Render(w, r, APIError(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
f = tracingHandler(handleName, f)
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,14 +56,9 @@ func collectHandleMetrics(funcName, method string, st time.Time, err error) {
|
||||||
responseTimeDuration.WithLabelValues(funcName, method, codeStr).Observe(duration)
|
responseTimeDuration.WithLabelValues(funcName, method, codeStr).Observe(duration)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TracingHandler
|
// tracingHandler
|
||||||
func tracingHandler(operation string) func(next http.Handler) http.Handler {
|
func tracingHandler(operation string, fn func(w http.ResponseWriter, r *http.Request)) func(w http.ResponseWriter, r *http.Request) {
|
||||||
return func(next http.Handler) http.Handler {
|
return otelhttp.NewHandler(http.HandlerFunc(fn), operation).ServeHTTP
|
||||||
fn := func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
next.ServeHTTP(w, r)
|
|
||||||
}
|
|
||||||
return otelhttp.NewHandler(http.HandlerFunc(fn), operation)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
Loading…
Reference in New Issue