trace

package
v0.0.0-...-2c80a5e Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetRealIPFromContext

func GetRealIPFromContext(ctx context.Context) string

GetRealIPFromContext get the remote endpoint from request, if not found, return an empty string

func HandleCrash

func HandleCrash(fn ...func(r interface{}))

HandleCrash xx

func HandleFunc

func HandleFunc(name string, handler func(w http.ResponseWriter, r *http.Request)) func(w http.ResponseWriter, r *http.Request)

HandleFunc wrap a trace handle func outer the original http handle func

func Handler

func Handler(name string, handler http.Handler) http.Handler

Handler wrap a trace handler outer the original http.Handler

func LogCrashStack

func LogCrashStack(ctx context.Context, r interface{})

LogCrashStack for stack

func Stacks

func Stacks(all bool) []byte

copy this from glog

func WithTraceForContext

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

WithTraceForContext will return a new context wrapped a trace handler around the original ctx

func WithTraceForContext2

func WithTraceForContext2(ctx context.Context, tracer Trace) context.Context

WithTraceForContext2 will return a new context wrapped a trace handler around the original ctx

Types

type Trace

type Trace interface {
	// Parent will return the parent trace
	Parent() Trace
	// Name will return the current trace name
	Name() string
	// SetName will set a new name for the Trace object
	SetName(name string)
	// ID will return the current trace id
	ID() string
	// Start will return the current trace start time
	Start() time.Time
	// Duration will return the current trace Duration
	Duration() time.Duration
	// Info will print the args as the info level log
	Info(args ...interface{})
	// Infof will print the args with a format as the info level log
	Infof(format string, args ...interface{})
	// Warn will print the args as the warn level log
	Warn(args ...interface{})
	// Warnf will print the args with a format as the warn level log
	Warnf(format string, args ...interface{})
	// Error will print the args as the error level log
	Error(args ...interface{})
	// Errorf will print the args with a format as the error level log
	Errorf(format string, args ...interface{})
	// Stack will return current stack
	Stack(all ...bool) string
	// String will return a string-serialized trace
	String() string
	// Fatalf will print log and exit process
	Fatalf(format string, args ...interface{})
	// Fatalf will print log and exit process
	Fatal(args ...interface{})

	Debug(args ...interface{})

	Debugf(format string, args ...interface{})
	// 1. 支持命令行参数指定Level, eg:  -v=3
	// 2. 支持环境变量支持Level, export LOGVERB=3
	V(level int) Trace
	Enable() bool
}

Trace is a log trace utils wrapped on glog, can be used to trace a http request and its subrequests

func GetTraceFromContext

func GetTraceFromContext(ctx context.Context) Trace

GetTraceFromContext get the Trace var from the context, if there is no such a trace utility, return nil

func GetTraceFromRequest

func GetTraceFromRequest(r *http.Request) Trace

GetTraceFromRequest get the Trace var from the req context, if there is no such a trace utility, return nil

func New

func New(name string, id ...string) Trace

New will create a Trace using a name, identifying the trace process

func WithID

func WithID(name string, id string) Trace

WithID will create a Trace with a name and a trace id

func WithParent

func WithParent(p Trace, name string) Trace

WithParent will create a Trace use a parent Trace and a identified name

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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