trace

package
v1.2.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 12, 2024 License: MIT Imports: 8 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AttachTraceID

func AttachTraceID(ctx context.Context) (traceID string, result context.Context)

AttachTraceID 为 context 附加 trace_id

func Context added in v1.2.14

func Context(ctx context.Context, traceID string) context.Context

func ContextKey added in v1.2.14

func ContextKey() string

func ForkContext added in v1.2.12

func ForkContext(ctx context.Context) (forked context.Context)

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

func ForkContextWithOpts(ctx context.Context, fields ...string) (forked context.Context)

ForkContextWithOpts create a new traced context from an existed context which carries the values in fields

func FromContext added in v1.2.12

func FromContext(ctx context.Context) (traced context.Context)

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

func GetClientIPFromPeer(ctx context.Context) (ip string)

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

func GetTid(ctx context.Context) string

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

func NewContext() context.Context

NewContext build a new context with trace id.

func NewContextWithTid added in v1.2.11

func NewContextWithTid(traceID string) context.Context

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.

func Stack

func Stack(skip int) []byte

func TransformContext added in v1.2.12

func TransformContext(ctx context.Context) (traceID string, result context.Context)

TransformContext transform a context to a traced context. if the context is already a traced context, return itself and its trace id.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL