trace

package module
v0.0.0-...-355dc4f Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2024 License: MulanPSL-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const Header = "TRACE-ID"

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	Name                  string      `json:"name"`                    // 缓存组件名
	TraceTime             string      `json:"trace_time"`              // 时间,格式:2006-01-02 15:04:05
	CMD                   string      `json:"cmd"`                     // 操作,SET/GET 等
	Key                   string      `json:"key"`                     // Key
	Value                 interface{} `json:"value,omitempty"`         // Value
	TTL                   float64     `json:"ttl,omitempty"`           // 超时时长(单位分)
	CostMillisecond       int64       `json:"cost_millisecond"`        // 执行时长(单位ms)
	SlowLoggerMillisecond int64       `json:"slow_logger_millisecond"` // 慢查记录时间
	Logger                *zap.Logger `json:"-"`
	AlwaysTrace           bool        `json:"always_trace"`
}

type D

type D interface {
	AppendResponse(resp *Response)
}

type Debug

type Debug struct {
	Key             string      `json:"key"`              // 标示
	Value           interface{} `json:"value"`            // 值
	CostMillisecond int64       `json:"cost_millisecond"` // 执行时长(单位ms)
	Logger          *zap.Logger `json:"-"`
}

Debug 自定义调试信息

type Dialog

type Dialog struct {
	Request         *Request    `json:"request"`          // 请求信息
	Responses       []*Response `json:"responses"`        // 返回信息
	Success         bool        `json:"success"`          // 是否成功,true 或 false
	CostMillisecond int64       `json:"cost_millisecond"` // 执行时长(单位ms)
	Logger          *zap.Logger `json:"-"`
	AlwaysTrace     bool        `json:"always_trace"`
	// contains filtered or unexported fields
}

内部调用其它方接口的会话信息;失败时会有retry操作,所以 response 会有多次。

func (*Dialog) AppendResponse

func (d *Dialog) AppendResponse(resp *Response)

AppendResponse 按转的追加response信息

type Request

type Request struct {
	TTL         string      `json:"ttl"`         // 请求超时时间
	Method      string      `json:"method"`      // 请求方式
	DecodedURL  string      `json:"decoded_url"` // 请求地址
	Header      interface{} `json:"header"`      // 请求 Header 信息
	Body        interface{} `json:"body"`        // 请求 Body 信息
	Logger      *zap.Logger `json:"-"`
	AlwaysTrace bool        `json:"always_trace"`
}

Request 请求信息

type Response

type Response struct {
	Header          interface{} `json:"header"`                      // Header 信息
	Body            interface{} `json:"body"`                        // Body 信息
	BusinessCode    int         `json:"business_code,omitempty"`     // 业务码
	BusinessCodeMsg string      `json:"business_code_msg,omitempty"` // 提示信息
	HttpCode        int         `json:"http_code"`                   // HTTP 状态码
	HttpCodeMsg     string      `json:"http_code_msg"`               // HTTP 状态码信息
	CostMillisecond int64       `json:"cost_millisecond"`            // 执行时间(单位ms)
	Logger          *zap.Logger `json:"-"`
	AlwaysTrace     bool        `json:"always_trace"`
}

Response 响应信息

type SQL

type SQL struct {
	TraceTime             string      `json:"trace_time"`              // 时间,格式:2006-01-02 15:04:05
	Stack                 string      `json:"stack"`                   // 文件地址和行号
	SQL                   string      `json:"sql"`                     // SQL 语句
	AffectedRows          int64       `json:"affected_rows"`           // 影响行数
	CostMillisecond       int64       `json:"cost_millisecond"`        // 执行时长(单位ms)
	SlowLoggerMillisecond int64       `json:"slow_logger_millisecond"` //慢查记录时间
	Logger                *zap.Logger `json:"-"`
	AlwaysTrace           bool        `json:"always_trace"`
}

type T

type T interface {
	ID() string
	WithRequest(req *Request) *Trace
	WithResponse(resp *Response) *Trace
	AppendDialog(dialog *Dialog) *Trace
	AppendSQL(sql *SQL) *Trace
	AppendCache(Cache *Cache) *Trace
	SetLogger(logger *zap.Logger)
	SetAlwaysTrace(b bool)
}

type Trace

type Trace struct {
	Identifier         string      `json:"trace_id"`             // 链路ID
	Request            *Request    `json:"request"`              // 请求信息
	Response           *Response   `json:"response"`             // 返回信息
	ThirdPartyRequests []*Dialog   `json:"third_party_requests"` // 调用第三方接口的信息
	Debugs             []*Debug    `json:"debugs"`               // 调试信息
	SQLs               []*SQL      `json:"sqls"`                 // 执行的 SQL 信息
	Cache              []*Cache    `json:"Cache"`                // 执行的 Cache 信息
	Success            bool        `json:"success"`              // 请求结果 true or false
	CostMillisecond    float64     `json:"cost_millisecond"`     // 执行时长(单位ms)
	Logger             *zap.Logger `json:"-"`
	AlwaysTrace        bool        `json:"always_trace"`
	// contains filtered or unexported fields
}

Trace 记录的参数

func New

func New(id string) *Trace

func (*Trace) AppendCache

func (t *Trace) AppendCache(Cache *Cache) *Trace

AppendCache 追加 Cache

func (*Trace) AppendDebug

func (t *Trace) AppendDebug(debug *Debug) *Trace

AppendDebug 追加 debug

func (*Trace) AppendDialog

func (t *Trace) AppendDialog(dialog *Dialog) *Trace

AppendDialog 安全的追加内部调用过程dialog

func (*Trace) AppendSQL

func (t *Trace) AppendSQL(sql *SQL) *Trace

AppendSQL 追加 SQL

func (*Trace) ID

func (t *Trace) ID() string

ID 唯一标识符

func (*Trace) SetAlwaysTrace

func (t *Trace) SetAlwaysTrace(b bool)

SetAlwaysTrace 始终记录trace信息

func (*Trace) SetLogger

func (t *Trace) SetLogger(logger *zap.Logger)

SetLogger 设置日志

func (*Trace) WithRequest

func (t *Trace) WithRequest(req *Request) *Trace

WithRequest 设置request

func (*Trace) WithResponse

func (t *Trace) WithResponse(resp *Response) *Trace

WithResponse 设置response

Jump to

Keyboard shortcuts

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