more tracing

This commit is contained in:
Archimedes Trajano 2024-07-30 13:07:38 -04:00
parent 9c4d0943a4
commit 9467bf8d12
4 changed files with 16 additions and 2 deletions
caddyconfig
cmd
modules/caddyhttp/reverseproxy

@ -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
}

@ -670,7 +670,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)
}

@ -28,6 +28,7 @@ import (
"strings"
"time"
"go.opentelemetry.io/otel"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
@ -429,6 +430,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(), requestBody)
if err != nil {
return fmt.Errorf("making request: %v", err)

@ -34,6 +34,7 @@ import (
"sync"
"time"
"go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"golang.org/x/net/http/httpguts"
@ -863,6 +864,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())))
// do the round-trip
start := time.Now()