Source File
correlation_context_propagator.go
Belonging Package
go.opentelemetry.io/otel/api/correlation
package correlation
import (
)
const correlationContextHeader = "otcorrelations"
type CorrelationContext struct{}
var _ propagation.HTTPPropagator = CorrelationContext{}
func () propagation.HTTPPropagator {
return CorrelationContext{}
}
func (CorrelationContext) ( context.Context, propagation.HTTPSupplier) {
:= MapFromContext()
:= true
var strings.Builder
.Foreach(func( label.KeyValue) bool {
if ! {
.WriteRune(',')
}
= false
.WriteString(url.QueryEscape(strings.TrimSpace((string)(.Key))))
.WriteRune('=')
.WriteString(url.QueryEscape(strings.TrimSpace(.Value.Emit())))
return true
})
if .Len() > 0 {
:= .String()
.Set(correlationContextHeader, )
}
}
func (CorrelationContext) ( context.Context, propagation.HTTPSupplier) context.Context {
:= .Get(correlationContextHeader)
if == "" {
return
}
:= strings.Split(, ",")
:= make([]label.KeyValue, 0, len())
for , := range {
:= strings.Split(, ";")
if len() < 1 {
continue
}
:= strings.Split([0], "=")
if len() < 2 {
continue
}
, := url.QueryUnescape([0])
if != nil {
continue
}
:= strings.TrimSpace()
, := url.QueryUnescape([1])
if != nil {
continue
}
:= strings.TrimSpace()
var strings.Builder
.WriteString()
for , := range [1:] {
.WriteRune(';')
.WriteString()
}
= append(, label.String(, .String()))
}
return ContextWithMap(, NewMap(MapUpdate{
MultiKV: ,
}))
}
return
}
func (CorrelationContext) () []string {
return []string{correlationContextHeader}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |