Skip to content

Commit

Permalink
more tracing placed
Browse files Browse the repository at this point in the history
  • Loading branch information
trajano committed Aug 10, 2024
1 parent e68c2df commit c7a802d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
7 changes: 6 additions & 1 deletion caddyconfig/httploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/commandfuncs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
7 changes: 7 additions & 0 deletions modules/caddyhttp/reverseproxy/healthchecks.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"strconv"
"time"

"go.opentelemetry.io/otel"
"go.uber.org/zap"

"github.com/caddyserver/caddy/v2"
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions modules/caddyhttp/reverseproxy/reverseproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c7a802d

Please sign in to comment.