From fd9b68c132c4daec9c1864a73ad4668330cee412 Mon Sep 17 00:00:00 2001 From: Will Scott Date: Mon, 11 Sep 2023 10:40:40 +0200 Subject: [PATCH 1/2] convert l1 timing headers into otel spans --- fetcher.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fetcher.go b/fetcher.go index 9b000e6..faa011f 100644 --- a/fetcher.go +++ b/fetcher.go @@ -16,6 +16,7 @@ import ( "github.com/filecoin-saturn/caboose/tieredhashing" "github.com/willscott/go-requestcontext" "go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace" + "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" @@ -311,9 +312,17 @@ func (p *pool) fetchResource(ctx context.Context, from string, resource string, for _, th := range timingHeaders { if subReqTiming, err := servertiming.ParseHeader(th); err == nil { for _, m := range subReqTiming.Metrics { + // forward upstream m.Extra["attempt"] = fmt.Sprintf("%d", attempt) m.Extra["subreq"] = subReqID(from, resource) timing.Add(m) + + // record the otel span + _, subSpan := otel.Tracer("caboose/l1").Start(ctx, m.Name, trace.WithTimestamp(time.Now().Add(m.Duration*-1))) + for eK, eV := range m.Extra { + subSpan.SetAttributes(attribute.String(eK, eV)) + } + subSpan.End() } } } From 3700ba6a2c5001f7ef3f62e4c5f6f03223b89e4e Mon Sep 17 00:00:00 2001 From: Will Scott Date: Tue, 12 Sep 2023 08:22:10 +0200 Subject: [PATCH 2/2] only otel / forward timing headers on cache misses where they're relevant / not-cached --- fetcher.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fetcher.go b/fetcher.go index faa011f..46f7e4b 100644 --- a/fetcher.go +++ b/fetcher.go @@ -307,7 +307,7 @@ func (p *pool) fetchResource(ctx context.Context, from string, resource string, proto = resp.Proto respReq = resp.Request - if timing != nil { + if timing != nil && respHeader.Get(saturnCacheHitKey) != saturnCacheHit { timingHeaders := respHeader.Values(servertiming.HeaderKey) for _, th := range timingHeaders { if subReqTiming, err := servertiming.ParseHeader(th); err == nil {