Documentation ¶
Index ¶
- func AttachTraceID(ctx context.Context) (traceID string, result context.Context)
- func ForkContext(ctx context.Context) (forked context.Context)
- func ForkContextWithOpts(ctx context.Context, fields ...string) (forked context.Context)
- func FromContext(ctx context.Context) (traced context.Context)
- func GetClientIPFromPeer(ctx context.Context) (ip string)
- func GetTid(ctx context.Context) string
- func GetTraceID(ctx context.Context) (traceID string, result context.Context)deprecated
- func NewContext() context.Context
- func NewContextWithTid(traceID string) context.Context
- func SetTraceIDKey(key string)
- func Stack(skip int) []byte
- func TransformContext(ctx context.Context) (traceID string, result context.Context)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AttachTraceID ¶
AttachTraceID 为 context 附加 trace_id
func ForkContext ¶ added in v1.2.12
ForkContext create a new traced context from an existed context. only the trace id will be copied, if no trace id, a new trace id will be generated.
func ForkContextWithOpts ¶ added in v1.2.12
ForkContextWithOpts create a new traced context from an existed context which carries the values in fields
func FromContext ¶ added in v1.2.12
FromContext if ctx has trace_id, return itself, else return the context with trace_id example:
tracedCtx := trace.FromContext(ctx)
then you can use tracedCtx to do something
func GetClientIPFromPeer ¶ added in v1.2.11
GetClientIPFromPeer get client ip from a grpc request, if not a grpc request or no client ip, return empty string example:
clientIP := trace.GetClientIPFromPeer(ctx) if clientIP == "" { // not a grpc request or no client ip }
func GetTid ¶ added in v1.2.12
GetTid get trace if from a traced context, if not a traced context, return empty string. example:
var tid string tid = trace.GetTid(trace.NewContext()) // tid is a full 36 length uuid string tid = trace.GetTid(context.Background()) // tid is empty string
func NewContext ¶ added in v1.2.11
NewContext build a new context with trace id.
func NewContextWithTid ¶ added in v1.2.11
NewContextWithTid build a new context with existed trace id.
func SetTraceIDKey ¶ added in v1.2.12
func SetTraceIDKey(key string)
SetTraceIDKey it will set the key of trace_id in context globally, only set once. if you need to call it, make sure to set it before any other operation.
Types ¶
This section is empty.