add the feature for observability
This commit is contained in:
24
pkg/metrics/http.go
Normal file
24
pkg/metrics/http.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package metrics
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
||||
)
|
||||
|
||||
// HTTPMiddleware wraps an HTTP handler with OpenTelemetry instrumentation.
|
||||
func HTTPMiddleware(handler http.Handler, operation string) http.Handler {
|
||||
if !IsEnabled() {
|
||||
return handler
|
||||
}
|
||||
|
||||
return otelhttp.NewHandler(
|
||||
handler,
|
||||
operation,
|
||||
)
|
||||
}
|
||||
|
||||
// HTTPHandler wraps an HTTP handler function with OpenTelemetry instrumentation.
|
||||
func HTTPHandler(handler http.HandlerFunc, operation string) http.Handler {
|
||||
return HTTPMiddleware(handler, operation)
|
||||
}
|
||||
Reference in New Issue
Block a user