Skip to content

Commit c7a802d

Browse files
committed
more tracing placed
1 parent e68c2df commit c7a802d

File tree

4 files changed

+16
-2
lines changed

4 files changed

+16
-2
lines changed

caddyconfig/httploader.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,13 @@ func (hl HTTPLoader) LoadConfig(ctx caddy.Context) ([]byte, error) {
9898
method = http.MethodGet
9999
}
100100

101+
// tr := otel.Tracer("caddyconfig")
102+
103+
// ctx, span := tr.Start(ctx, "httploader")
104+
// defer span.End()
105+
101106
url := repl.ReplaceAll(hl.URL, "")
102-
req, err := http.NewRequest(method, url, nil)
107+
req, err := http.NewRequestWithContext(ctx, method, url, nil)
103108
if err != nil {
104109
return nil, err
105110
}

cmd/commandfuncs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ func AdminAPIRequest(adminAddr, method, uri string, headers http.Header, body io
659659
}
660660

661661
// form the request
662-
req, err := http.NewRequest(method, origin+uri, body)
662+
req, err := http.NewRequestWithContext(context.TODO(), method, origin+uri, body)
663663
if err != nil {
664664
return nil, fmt.Errorf("making request: %v", err)
665665
}

modules/caddyhttp/reverseproxy/healthchecks.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"strconv"
2727
"time"
2828

29+
"go.opentelemetry.io/otel"
2930
"go.uber.org/zap"
3031

3132
"github.com/caddyserver/caddy/v2"
@@ -403,6 +404,12 @@ func (h *Handler) doActiveHealthCheck(dialInfo DialInfo, hostAddr string, networ
403404
ctx = context.WithValue(ctx, caddyhttp.VarsCtxKey, map[string]any{
404405
dialInfoVarKey: dialInfo,
405406
})
407+
408+
tr := otel.Tracer("reverseproxy")
409+
410+
ctx, span := tr.Start(ctx, "healthcheck")
411+
defer span.End()
412+
406413
req, err := http.NewRequestWithContext(ctx, h.HealthChecks.Active.Method, u.String(), nil)
407414
if err != nil {
408415
return fmt.Errorf("making request: %v", err)

modules/caddyhttp/reverseproxy/reverseproxy.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"sync"
3333
"time"
3434

35+
"go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace"
3536
"go.uber.org/zap"
3637
"golang.org/x/net/http/httpguts"
3738

@@ -784,6 +785,7 @@ func (h *Handler) reverseProxy(rw http.ResponseWriter, req *http.Request, origRe
784785
},
785786
}
786787
req = req.WithContext(httptrace.WithClientTrace(req.Context(), trace))
788+
req = req.WithContext(httptrace.WithClientTrace(req.Context(), otelhttptrace.NewClientTrace(req.Context())))
787789

788790
// if FlushInterval is explicitly configured to -1 (i.e. flush continuously to achieve
789791
// low-latency streaming), don't let the transport cancel the request if the client

0 commit comments

Comments
 (0)