tapper

package
v0.0.0-...-a36dcc1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// 定义spanContext
	HTTP_KEY_TRACE_ID = "X_bd_logid"
	HTTP_KEY_SPAN_ID  = "X_bd_spanid" // 0.0.0 规则, 此处第一调用为,0.3.0
	HTTP_KEY_UNIQ_ID  = "X_bd_uniqid"
	HTTP_KEY_CALLER   = "X_bd_module"

	HTTP_KEY_IDC        = "X_bd_idc"
	HTTP_KEY_CALLER_URI = "X_bd_caller_uri" //osc 限流,此处不设置
	HTTP_KEY_SUBSYS     = "X_bd_subsys"

	// 自定义baggage,需全程透传
	HTTP_KEY_PRODUCT = "X_bd_product"
	HTTP_KEY_USERIP  = "X_bd_userip"

	HTTP_USER_AGENT = "User-Agent"
)
View Source
const (
	TRACECTX = "TRACECTX"
	TRACELOG = "TRACELOG"
)
View Source
const (
	MONITORCTX = "MONITORCTX"
)
View Source
const (
	NOTICECTX = "NOTICECTX"
)

Variables

View Source
var EmptyTraceLog = &TraceLog{}
View Source
var Project = ""

Functions

func GenLogId

func GenLogId() string

生成logId

func PushMonitor

func PushMonitor(ctx context.Context, args ...interface{})

参数args: [key value]...

func PushNotice

func PushNotice(ctx context.Context, args ...interface{})

参数args: [key value]...

func PushTrace

func PushTrace(ctx context.Context, args ...interface{})

参数args: [key value]...

func SetTraceHeaderByGinContext

func SetTraceHeaderByGinContext(ctx context.Context, header map[string]string) map[string]string

Types

type BDTraceLog

type BDTraceLog struct {
}

func (*BDTraceLog) SetTraceLogFromGinHeader

func (l *BDTraceLog) SetTraceLogFromGinHeader(c *gin.Context) *TraceLog

type ITraceLog

type ITraceLog interface {
	SetTraceLogFromGinHeader(c *gin.Context) *TraceLog
}
var TraceLogger ITraceLog

type LogUnits

type LogUnits struct {
	// contains filtered or unexported fields
}

func (*LogUnits) AddLogUnit

func (p *LogUnits) AddLogUnit(k string, v string)

add log unit like bd odp addNotice

func (*LogUnits) AddLogUnitThreadSafe

func (p *LogUnits) AddLogUnitThreadSafe(k string, v string)

multi go routine safe add

func (*LogUnits) AddTimeCost

func (p *LogUnits) AddTimeCost(k string, tNs int64)

func (*LogUnits) AddTimeCostThreadSafe

func (p *LogUnits) AddTimeCostThreadSafe(k string, tNs int64)

multi go routine 版本

func (*LogUnits) MergeLogUnit

func (p *LogUnits) MergeLogUnit(o *LogUnits, prefix string)

func (*LogUnits) SerializeTimeCost

func (p *LogUnits) SerializeTimeCost() string

func (*LogUnits) SetBeginTime

func (p *LogUnits) SetBeginTime()

func (*LogUnits) SetCmd

func (p *LogUnits) SetCmd(cmd string)

func (*LogUnits) String

func (p *LogUnits) String() string

type Monitor

type Monitor struct {
	// contains filtered or unexported fields
}

func GetMonitorFromContext

func GetMonitorFromContext(ctx context.Context) (context.Context, *Monitor)

func (*Monitor) Marshal

func (monitor *Monitor) Marshal() string

func (*Monitor) Push

func (monitor *Monitor) Push(args ...interface{}) *Monitor

type Notice

type Notice struct {
	// contains filtered or unexported fields
}

func GetNoticeFromContext

func GetNoticeFromContext(ctx context.Context) (context.Context, *Notice)

func (*Notice) Marshal

func (notice *Notice) Marshal() string

func (*Notice) Push

func (notice *Notice) Push(args ...interface{}) *Notice

type Option

type Option func(*options)

func WithError

func WithError(err error) Option

func WithGinCtx

func WithGinCtx(ctx context.Context) Option

func WithUrlPath

func WithUrlPath(urlPath string) Option

type Trace

type Trace struct {
	// contains filtered or unexported fields
}

func GetTraceFromContext

func GetTraceFromContext(ctx context.Context) (context.Context, *Trace)

func (*Trace) Marshal

func (trace *Trace) Marshal() string

func (*Trace) Push

func (trace *Trace) Push(args ...interface{}) *Trace

type TraceLog

type TraceLog struct {
	SpanNum atomic.Int64 //用于计算本地spanId自增拼接
	LogId   string
	SpanId  string
	UniqId  string

	UserIP  string
	Product string

	Caller string
	Refer  string
	Path   string // 当前请求的地址,用作请求下游时,设置成refer

	MqTransId string //mq tranId 比如mq push模式 push uri地址参数中会有带上事务id
}

func GetTraceLogFromContext

func GetTraceLogFromContext(ctx context.Context) (context.Context, *TraceLog)

从context中获取span信息集合

func GetTraceLogFromGinContext

func GetTraceLogFromGinContext(ctx context.Context) (*TraceLog, bool)

从gin context中获取span信息集合

func (*TraceLog) FormatTraceString

func (tl *TraceLog) FormatTraceString() string

func (*TraceLog) GetCurrentSpanId

func (tl *TraceLog) GetCurrentSpanId() string

type UserContext

type UserContext struct {
	LogUnit *LogUnits
	GinCtx  context.Context
	Error   error
}

func CtxTransfer

func CtxTransfer(ctx context.Context, key string) *UserContext

func NewUserContext

func NewUserContext(opts ...Option) *UserContext

func (*UserContext) Clone

func (this *UserContext) Clone() *UserContext

gin.Context 属于对象池,因此在异步执行时,需要拷贝一个再使用.注:在多个goroutine中,应使用线程安全的AddLogUnit方法

func (*UserContext) SetErr

func (this *UserContext) SetErr(err error)

Jump to

Keyboard shortcuts

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