github.com/mailgun/holster/v4@v4.20.0/tracing/http.go (about) 1 package tracing 2 3 import ( 4 "net/http" 5 6 "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" 7 "go.opentelemetry.io/otel/trace" 8 ) 9 10 // NewHTTPClient creates an HTTP client configured with OpenTelemetry 11 // middleware to generate a span on request and propagate the trace to the 12 // server. 13 func NewHTTPClient() *http.Client { 14 opts := []otelhttp.Option{ 15 otelhttp.WithSpanOptions(trace.WithSpanKind(trace.SpanKindClient)), 16 otelhttp.WithSpanNameFormatter(spanNameFormatter), 17 } 18 return &http.Client{ 19 Transport: otelhttp.NewTransport(http.DefaultTransport, opts...), 20 } 21 } 22 23 func spanNameFormatter(_ string, r *http.Request) string { 24 return r.Method + " " + r.URL.Path 25 }