diff --git a/caddyconfig/httploader.go b/caddyconfig/httploader.go index 1aa1d380436..b029e19e93e 100644 --- a/caddyconfig/httploader.go +++ b/caddyconfig/httploader.go @@ -98,8 +98,13 @@ func (hl HTTPLoader) LoadConfig(ctx caddy.Context) ([]byte, error) { method = http.MethodGet } + // tr := otel.Tracer("caddyconfig") + + // ctx, span := tr.Start(ctx, "httploader") + // defer span.End() + url := repl.ReplaceAll(hl.URL, "") - req, err := http.NewRequest(method, url, nil) + req, err := http.NewRequestWithContext(ctx, method, url, nil) if err != nil { return nil, err } diff --git a/cmd/commandfuncs.go b/cmd/commandfuncs.go index 746cf3da6b6..50048970f9b 100644 --- a/cmd/commandfuncs.go +++ b/cmd/commandfuncs.go @@ -659,7 +659,7 @@ func AdminAPIRequest(adminAddr, method, uri string, headers http.Header, body io } // form the request - req, err := http.NewRequest(method, origin+uri, body) + req, err := http.NewRequestWithContext(context.TODO(), method, origin+uri, body) if err != nil { return nil, fmt.Errorf("making request: %v", err) } diff --git a/modules/caddyhttp/reverseproxy/healthchecks.go b/modules/caddyhttp/reverseproxy/healthchecks.go index 3b5a6a3af3a..abfac7b29a8 100644 --- a/modules/caddyhttp/reverseproxy/healthchecks.go +++ b/modules/caddyhttp/reverseproxy/healthchecks.go @@ -26,6 +26,7 @@ import ( "strconv" "time" + "go.opentelemetry.io/otel" "go.uber.org/zap" "github.com/caddyserver/caddy/v2" @@ -403,6 +404,12 @@ func (h *Handler) doActiveHealthCheck(dialInfo DialInfo, hostAddr string, networ ctx = context.WithValue(ctx, caddyhttp.VarsCtxKey, map[string]any{ dialInfoVarKey: dialInfo, }) + + tr := otel.Tracer("reverseproxy") + + ctx, span := tr.Start(ctx, "healthcheck") + defer span.End() + req, err := http.NewRequestWithContext(ctx, h.HealthChecks.Active.Method, u.String(), nil) if err != nil { return fmt.Errorf("making request: %v", err) diff --git a/modules/caddyhttp/reverseproxy/reverseproxy.go b/modules/caddyhttp/reverseproxy/reverseproxy.go index 4f97edeadde..d6c4422a2b4 100644 --- a/modules/caddyhttp/reverseproxy/reverseproxy.go +++ b/modules/caddyhttp/reverseproxy/reverseproxy.go @@ -32,6 +32,7 @@ import ( "sync" "time" + "go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace" "go.uber.org/zap" "golang.org/x/net/http/httpguts" @@ -784,6 +785,7 @@ func (h *Handler) reverseProxy(rw http.ResponseWriter, req *http.Request, origRe }, } req = req.WithContext(httptrace.WithClientTrace(req.Context(), trace)) + req = req.WithContext(httptrace.WithClientTrace(req.Context(), otelhttptrace.NewClientTrace(req.Context()))) // if FlushInterval is explicitly configured to -1 (i.e. flush continuously to achieve // low-latency streaming), don't let the transport cancel the request if the client