trace

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package trace

Index

Constants

View Source
const (
	//TraceId
	DIDI_HEADER_RID = "Didi-Header-Rid"
	//SpanId
	DIDI_HEADER_SPANID       = "Didi-Header-Spanid"
	DIDI_HEADER_HINT_CODE    = "Didi-Header-Hint-Code"
	DIDI_HEADER_HINT_CONTENT = "Didi-Header-Hint-Content"

	EMPRY_TRACE_ID = ""
	TRACEID        = "traceid"
	SPANID         = "spanid"
	CALLER         = "caller"
	SRC_METHOD     = "srcMethod"
	HINT_CODE      = "hintCode"
	HINT_CONTENT   = "hintContent"

	DLTagUndefined        = " _undef"
	DLTagMysqlFailed      = " _com_mysql_failure"
	DLTagMysqlSuccess     = " _com_mysql_success"
	DLTagRedisFailed      = " _com_redis_failure"
	DLTagRedisSuccess     = " _com_redis_success"
	DLTagThriftFailed     = " _com_thrift_failure"
	DLTagThriftSuccess    = " _com_thrift_success"
	DLTagHTTPSuccess      = " _com_http_success"
	DLTagHTTPFailed       = " _com_http_failure"
	DLTagBackendRPCFailed = " _com_interactive_failure"
	DLTagRequestIn        = " _com_request_in"
	DLTagRequestOut       = " _com_request_out"

	EMPTY_SPAN_ID             string = "0"
	HINT_PRESSURE_TRAFFIC            = "1"
	HINT_NORMAL_TRAFFIC              = "0"
	HINT_TRACE_SAMPLE_INIT    int64  = 0x80
	HINT_TRACE_SAMPLE         int64  = 0x40
	DEFAULT_TRACE_SAMPLE_RATE int64  = 10000
)

Variables

This section is empty.

Functions

func FormatCtx

func FormatCtx(ctx context.Context) string

func GenSpanId

func GenSpanId() string

GenSpanId 生成新的spanId 用作 CSPanid

func GenTraceId

func GenTraceId() string

GenTraceId

func GetClientAddr

func GetClientAddr(req *http.Request) string

GetClientAddr ...

func PutTrace

func PutTrace(trace *Trace)

func SetCtxTrace

func SetCtxTrace(ctx context.Context, val *Trace) context.Context

SetCtxTrace set context ctxKey *Trace

Types

type HintContent

type HintContent struct {
	Sample HintSampling `json:"Sample"`
}

type HintSampling

type HintSampling struct {
	Rate int64 `json:"Rate"`
	Code int64 `json:"Code"`
}

type ICtxKey

type ICtxKey interface {
	GetCtxKey() interface{}
}

func NewCtxKey

func NewCtxKey() ICtxKey

NewCtxKey return ctx key for get trace

type Trace

type Trace struct {
	TraceId      string
	SpanId       string
	Caller       string
	SrcMethod    string
	Method       string
	Host         string
	URL          string
	Params       string
	From         string
	HintCode     string
	Sampling     int
	HintContent  string
	FormatString string
}

func GetCtxTrace

func GetCtxTrace(ctx context.Context) (*Trace, bool)

GetCtxTrace get context *Trace

func New

func New(req *http.Request) (trace *Trace)

New Trace,req 可为nil

func NewWithMap

func NewWithMap(m map[string]string) (trace *Trace)

func (*Trace) AddHttpHeader

func (tr *Trace) AddHttpHeader(request *http.Request)

AddHttpHeader 向http request header中添加trace信息

func (*Trace) GenSpanId

func (tr *Trace) GenSpanId() string

GenSpanId 生成新的spanId 用作 CSPanid

func (*Trace) GetClientAddr

func (tr *Trace) GetClientAddr(req *http.Request) string

func (*Trace) GetHintCode

func (tr *Trace) GetHintCode(req *http.Request) string

GetHintCode 获取HintCode

func (*Trace) GetHintContent

func (tr *Trace) GetHintContent(req *http.Request) string

GetHintContent 获取HintContent

func (*Trace) GetHttpHost

func (tr *Trace) GetHttpHost(req *http.Request) string

func (*Trace) GetHttpMethod

func (tr *Trace) GetHttpMethod(req *http.Request) string

func (*Trace) GetHttpParams

func (tr *Trace) GetHttpParams(req *http.Request) string

func (*Trace) GetHttpURL

func (tr *Trace) GetHttpURL(req *http.Request) string

func (*Trace) GetSpanId

func (tr *Trace) GetSpanId(req *http.Request) string

GetSpanId 获取TraceId,如果不存在就生成

func (*Trace) GetTraceId

func (tr *Trace) GetTraceId(req *http.Request) string

GetTraceId 获取TraceId,如果不存在就生成

func (*Trace) IsPressureTraffic

func (tr *Trace) IsPressureTraffic() bool

IsPressureTraffic 判断是否是压测流量

func (*Trace) IsTraceSampleEnabled

func (tr *Trace) IsTraceSampleEnabled() (hit bool)

IsTraceSampleEnabled 判断采样相关逻辑

func (*Trace) String

func (tr *Trace) String() string

Jump to

Keyboard shortcuts

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