opentelemetry-go的分布式追踪
调试
自制一个propagator实现
propagation.TextMapPropagator
接口import (
propagation "go.opentelemetry.io/otel/propagation"
)
type myPropagator struct {
}
func (ppgt myPropagator) Inject(ctx context.Context, carrier propagation.TextMapCarrier) {
}
func (ppgt myPropagator) Extract(ctx context.Context, carrier propagation.TextMapCarrier) context.Context {
sb := strings.Builder{}
for _, key := range carrier.Keys() {
value := carrier.Get(key)
sb.WriteString(key)
sb.WriteString(":")
sb.WriteString(value)
sb.WriteString("; ")
}
log.Debug(sb.String())
return ctx
}
func (ppgt myPropagator) Fields() []string {
return []string{}
}
把它与别的propagator组合起来
pgt := propagation.NewCompositeTextMapPropagator(
myPropagator{},
sentryotel.NewSentryPropagator(),
)
otel.SetTextMapPropagator(pgt)