dtrace

package
v0.0.0-...-a2bc238 Latest Latest
Warning

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

Go to latest
Published: May 16, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package trace A log wrapper based on google glog. Mainly used for a http request process.

Index

Constants

View Source
const (
	DefaultLoginUser = "203832"
)

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 GetUserInfoFromContext

func GetUserInfoFromContext(ctx context.Context) (string, error)

func HandleCrash

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

HandleCrash xx

func HandlerFunc

func HandlerFunc(name string, handler gin.HandlerFunc) gin.HandlerFunc

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

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

func WithTraceForGinContext

func WithTraceForGinContext(ctx context.Context, traceName string, traceID ...string) *gin.Context

WithTraceForContext 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
	// Stack will return current stack
	Stack(all ...bool) string
	// String will return a string-serialized trace
	String() string

	SetLogger(l *dlog.Logger) Trace
	// contains filtered or unexported methods
}

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