add the feature for observability

This commit is contained in:
Manendra Pal Singh
2025-11-13 13:16:16 +05:30
parent a29e97b035
commit ac27fa0666
6 changed files with 874 additions and 0 deletions

24
pkg/metrics/http.go Normal file
View 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)
}