trace

package
v1.0.0-alpha Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2023 License: Apache-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 D

type D interface {
	AppendResponse(resp *Response)
}

type Debug

type Debug struct {
	Key         string      `json:"key"`          // 标示
	Value       interface{} `json:"value"`        // 值
	CostSeconds float64     `json:"cost_seconds"` // 执行时间(单位秒)
}

type Dialog

type Dialog struct {
	Request     *Request    `json:"request"`      // 请求信息
	Responses   []*Response `json:"responses"`    // 返回信息
	Success     bool        `json:"success"`      // 是否成功,true 或 false
	CostSeconds float64     `json:"cost_seconds"` // 执行时长(单位秒)
	// contains filtered or unexported fields
}

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

func (*Dialog) AppendResponse

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

AppendResponse 按转的追加response信息

type Grpc

type Grpc struct {
	Timestamp   string                 `json:"timestamp"`             // 时间,格式:2006-01-02 15:04:05
	Addr        string                 `json:"addr"`                  // 地址
	Method      string                 `json:"method"`                // 操作方法
	Meta        metadata.MD            `json:"meta"`                  // Mate
	Request     map[string]interface{} `json:"request"`               // 请求信息
	Response    map[string]interface{} `json:"response"`              // 返回信息
	CostSeconds float64                `json:"cost_seconds"`          // 执行时间(单位秒)
	Code        string                 `json:"err_code,omitempty"`    // 错误码
	Message     string                 `json:"err_message,omitempty"` // 错误信息
}

type Kafka

type Kafka struct {
	Timestamp   string  `json:"timestamp"`    // 时间,格式:2006-01-02 15:04:05
	Handle      string  `json:"handle"`       // 操作,CURD
	Topic       string  `json:"topic"`        // 操作的topic
	Offset      int64   `json:"offset"`       // offset
	TTL         float64 `json:"ttl"`          // 超时时长(单位分)
	CostSeconds float64 `json:"cost_seconds"` // 执行时间(单位秒)
}

type Mongo

type Mongo struct {
	Timestamp   string  `json:"timestamp"`      // 时间,格式:2006-01-02 15:04:05
	Handle      string  `json:"handle"`         // 操作,CURD
	Collection  string  `json:"collection"`     // 操作的MongoDB表
	Count       int64   `json:"count_affected"` // 影响文档数
	TTL         float64 `json:"ttl"`            // 超时时长(单位分)
	CostSeconds float64 `json:"cost_seconds"`   // 执行时间(单位秒)
}

type Redis

type Redis struct {
	Timestamp   string  `json:"timestamp"`    // 时间,格式:2006-01-02 15:04:05
	Handle      string  `json:"handle"`       // 操作,SET/GET 等
	Key         string  `json:"key"`          // Key
	Value       string  `json:"value"`        // Value
	TTL         float64 `json:"ttl"`          // key的过期时间(单位分)
	CostSeconds float64 `json:"cost_seconds"` // 执行时间(单位秒)
}

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 信息
}

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 状态码信息
	CostSeconds     float64     `json:"cost_seconds"`                // 执行时间(单位秒)
}

Response 响应信息

type SQL

type SQL struct {
	Timestamp   string  `json:"timestamp"`     // 时间,格式:2006-01-02 15:04:05
	Stack       string  `json:"stack"`         // 文件地址和行号
	SQL         string  `json:"sql"`           // SQL 语句
	Rows        int64   `json:"rows_affected"` // 影响行数
	CostSeconds float64 `json:"cost_seconds"`  // 执行时长(单位秒)
}

type T

type T interface {
	ID() string
	WithRequest(req *Request) *Trace
	WithResponse(resp *Response) *Trace
	AppendDialog(dialog *Dialog) *Trace
	AppendSQL(sql *SQL) *Trace
	AppendMongo(mongo *Mongo) *Trace
	AppendRedis(redis *Redis) *Trace
	AppendGRPC(grpc *Grpc) *Trace
}

type Trace

type Trace struct {
	TraceID            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 信息
	Mongos             []*Mongo  `json:"mongos"`               // 执行的 Mongo 信息
	Kafka              []*Kafka  `json:"kafka "`               // 执行的 Kafka 信息
	Redis              []*Redis  `json:"redis"`                // 执行的 Redis 信息
	GRPCs              []*Grpc   `json:"grpc"`                 // 执行的 gRPC 信息
	Success            bool      `json:"success"`              // 请求结果 true or false
	CostSeconds        float64   `json:"cost_seconds"`         // 执行时长(单位秒)
	// contains filtered or unexported fields
}

Trace 记录的参数

func New

func New(id string) *Trace

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) AppendGRPC

func (t *Trace) AppendGRPC(grpc *Grpc) *Trace

AppendGRPC 追加 gRPC 调用信息

func (*Trace) AppendKafka

func (t *Trace) AppendKafka(kafka *Kafka) *Trace

AppendKafka 追加 Kafka

func (*Trace) AppendMongo

func (t *Trace) AppendMongo(mongo *Mongo) *Trace

AppendMongo 追加 Mongo

func (*Trace) AppendRedis

func (t *Trace) AppendRedis(redis *Redis) *Trace

AppendRedis 追加 Redis

func (*Trace) AppendSQL

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

AppendSQL 追加 SQL

func (*Trace) ID

func (t *Trace) ID() string

ID 唯一标识符

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