telemetry/tracing/handler.go
package tracing
// __
// .-----.-----.______.-----.----.-----.--.--.--.--.______.----.---.-.----| |--.-----.
// | _ | _ |______| _ | _| _ |_ _| | |______| __| _ | __| | -__|
// |___ |_____| | __|__| |_____|__.__|___ | |____|___._|____|__|__|_____|
// |_____| |__| |_____|
//
// Copyright (c) 2023 Fabio Cicerchia. https://fabiocicerchia.it. MIT License
// Repo: https://github.com/fabiocicerchia/go-proxy-cache
import (
"net/http"
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
"go.opentelemetry.io/otel"
)
// HTTPHandlerFunc - Add OpenTelemetry data to a HTTP handler.
func HTTPHandlerFunc(handler http.HandlerFunc, operation string) http.HandlerFunc {
otelOpts := otelhttp.WithTracerProvider(otel.GetTracerProvider())
return otelhttp.NewHandler(handler, operation, otelOpts).ServeHTTP
}