Documentation ¶
Index ¶
- Constants
- Variables
- func Bool(ctx context.Context, key string) bool
- func GetGrpcTrace(ctx context.Context) []string
- func GetHttpTrace(ctx context.Context) map[string]string
- func GetTraceId(ctx context.Context) string
- func Int64(ctx context.Context, key string) int64
- func IsIncomingKey(key string) (ok bool)
- func IsOutgoingKey(key string) bool
- func NewContext(ctx context.Context, md MD) context.Context
- func Range(ctx context.Context, rangeFunc func(key string, value interface{}), ...)
- func String(ctx context.Context, key string) string
- func Value(ctx context.Context, key string) interface{}
- func WithContext(c context.Context) context.Context
- type MD
Constants ¶
const ( // Network RemoteIP = "remote_ip" RemotePort = "remote_port" ServerAddr = "server_addr" ClientAddr = "client_addr" // Router Cluster = "cluster" Color = "color" // Trace Trace = "trace" Caller = "caller" // Timeout Timeout = "timeout" // Dispatch CPUUsage = "cpu_usage" Errors = "errors" Requests = "requests" // Mirror Mirror = "mirror" // Mid 外网账户用户id Mid = "mid" // NOTE: !!!业务可重新修改key名!!! // Device 客户端信息 Device = "device" // Criticality 重要性 Criticality = "criticality" )
metadata common key
Variables ¶
var Incomingheaders = []string{
"x-request-id",
"x-ot-span-context",
"x-datadog-trace-id",
"x-datadog-parent-id",
"x-datadog-sampling-priority",
"traceparent",
"tracestate",
"x-cloud-trace-context",
"grpc-trace-bin",
"x-b3-traceid",
"x-b3-spanid",
"x-b3-parentspanid",
"x-b3-sampled",
"x-b3-flags",
"end-user",
"user-agent",
}
Functions ¶
func GetGrpcTrace ¶ added in v0.1.6
grpc server从请求中获取向外传递的链路追踪信息
func GetHttpTrace ¶ added in v0.1.6
http server从请求中获取向外传递的链路追踪信息
func GetTraceId ¶ added in v0.1.6
func IsIncomingKey ¶
IsIncomingKey represent this key should extract from rpc metadata.
func IsOutgoingKey ¶
IsOutgoingKey represent this key should propagate by rpc.
func NewContext ¶
NewContext creates a new context with md attached.
func Range ¶
func Range(ctx context.Context, rangeFunc func(key string, value interface{}), filterFunc ...func(key string) bool)
Range range value from metadata in context filtered by filterFunc.
Types ¶
type MD ¶
type MD map[string]interface{}
MD is a mapping from metadata keys to values.
func FromContext ¶
FromContext returns the incoming metadata in ctx if it exists. The returned MD should not be modified. Writing to it may cause races. Modification should be made to copies of the returned MD.
func Join ¶
Join joins any number of mds into a single MD. The order of values for each key is determined by the order in which the mds containing those values are presented to Join.