Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

convert l1 timing headers into otel spans #158

Merged
merged 2 commits into from
Sep 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -306,14 +307,22 @@ 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 {
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()
}
}
}
Expand Down