Core

/app/lib/telemetry/httpmetrics/httpheaders.go (808 B)

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package httpmetrics

import (
"context"

"github.com/valyala/fasthttp"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/propagation"

"{{{ .Package }}}/app/util"
)

var _ propagation.TextMapCarrier = (*headerCarrier)(nil)

type headerCarrier struct {
h *fasthttp.RequestHeader
}

func (hc headerCarrier) Get(key string) string {
return string(hc.h.Peek(key))
}

func (hc headerCarrier) Set(key string, value string) {
hc.h.Set(key, value)
}

func (hc headerCarrier) Keys() []string {
var keys []string
hc.h.VisitAll(func(key []byte, _ []byte) {
keys = append(keys, string(key))
})
return keys
}

func ExtractHeaders(rc *fasthttp.RequestCtx, logger util.Logger) (context.Context, util.Logger) {
return otel.GetTextMapPropagator().Extract(rc, headerCarrier{h: &rc.Request.Header}), logger
}