tingyun3

package module
v0.6.7 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2021 License: Apache-2.0 Imports: 32 Imported by: 0

README

goagent

TingYun APM3.0 - GoAgent

嵌码

自动嵌码
  1. 内置http框架自动嵌码

    package main
    /*****************************************************************************/
    /* http 框架嵌码方法:                                                          */
    /* 在项目任意模块中添加代码 import "github.com/TingYunGo/goagent"                */
    /*****************************************************************************/
    import (
    	_ "github.com/TingYunGo/goagent"
    )
    
  2. gin框架自动嵌码

    package main
    /*****************************************************************************/
    /* gin 框架嵌码方法:                                                           */
    /* 在项目任意模块中添加代码 import "github.com/TingYunGo/goagent/frameworks/gin" */
    /*****************************************************************************/
    import (
    	_ "github.com/TingYunGo/goagent/frameworks/gin"
    )
    
  3. beego框架自动嵌码

    • 3.1 gopath模式自动嵌码
      • 3.1.1 github.com/astaxie/beego

        package main
        /*****************************************************************************/
        /* github.com/astaxie/beego 嵌码                                              */
        /*****************************************************************************/
        import (
        	_ "github.com/TingYunGo/goagent/frameworks/beego/path/astaxie"
        )
        
      • 3.1.2 github.com/beego/beego

        package main
        /*****************************************************************************/
        /* github.com/beego/beego 嵌码                                                */
        /*****************************************************************************/
        import (
        	_ "github.com/TingYunGo/goagent/frameworks/beego/path"
        )
        
    • 3.2 gomod模式自动嵌码
      • 3.2.1 beego v1

        package main
        /*****************************************************************************/
        /* github.com/beego/beego 嵌码                                                */
        /*****************************************************************************/
        import (
        	_ "github.com/TingYunGo/goagent/frameworks/beego"
        )
        
      • 3.2.2 beego v2

        package main
        /*****************************************************************************/
        /* github.com/beego/beego/v2 嵌码                                             */
        /*****************************************************************************/
        import (
        	_ "github.com/TingYunGo/goagent/frameworks/beego/v2"
        )
        
  4. echo框架自动嵌码

    • 4.1 gopath模式自动嵌码

      package main
      /*****************************************************************************/
      /* go path 模式 echo框架嵌码方法:                                               */
      /* 在项目任意模块中添加代码 import "github.com/TingYunGo/goagent/frameworks/echo" */
      /*****************************************************************************/
      import (
      	_ "github.com/TingYunGo/goagent/frameworks/echo"
      )
      
    • 4.2 gomod模式自动嵌码

      package main
      /********************************************************************************/
      /* go mod 模式 echo框架嵌码方法:                                                   */
      /* 在项目任意模块中添加代码 import "github.com/TingYunGo/goagent/frameworks/echo/v4" */
      /********************************************************************************/
      import (
      	_ "github.com/TingYunGo/goagent/frameworks/echo/v4"
      )
      
  5. iris框架自动嵌码

    • 5.1 irisv12.1.x自动嵌码

      package main
      /*********************************************************************************/
      /* 在项目任意模块中添加代码 import "github.com/TingYunGo/goagent/frameworks/iris/v12" */
      /*********************************************************************************/
      import (
      	_ "github.com/TingYunGo/goagent/frameworks/iris/v12"
      )
      
    • 5.1 irisv12.2自动嵌码

      package main
      /***********************************************************************************/
      /* 在项目任意模块中添加代码 import "github.com/TingYunGo/goagent/frameworks/iris/v12/2" */
      /***********************************************************************************/
      import (
      	_ "github.com/TingYunGo/goagent/frameworks/iris/v12/2"
      )
      
  6. 数据库自动嵌码

    package main
    /*****************************************************************************/
    /* database :                                                                */
    /* 在项目任意模块中添加代码 import "github.com/TingYunGo/goagent/database"       */
    /*****************************************************************************/
    import (
    	_ "github.com/TingYunGo/goagent/database"
    )
    
  7. redis自动嵌码

    • 7.1 redigo(github.com/gomodule/redigo)自动嵌码

      package main
      /***************************************************************************/
      /* redigo driver:                                                          */
      /* 在项目任意模块中添加代码 import "github.com/TingYunGo/goagent/nosql/redigo" */
      /***************************************************************************/
      import (
      	_ "github.com/TingYunGo/goagent/nosql/redigo"
      )
      
    • 7.2 go-redis(github.com/go-redis/redis)自动嵌码

      • 7.2.1 gopath模式嵌码

        package main
        /*****************************************************************************/
        /* go-redis (with GOPATH):                                                   */
        /* 在项目任意模块中添加代码 import "github.com/TingYunGo/goagent/nosql/go-redis" */
        /*****************************************************************************/
        import (
        	_ "github.com/TingYunGo/goagent/nosql/go-redis"
        )
        
      • 7.2.2 gomod模式嵌码

        • 7.2.2.1 go-redis v6(缺省)版本嵌码

          package main
          /*****************************************************************************/
          /* go-redis v6:                                                              */
          /* 在项目任意模块中添加代码 import "github.com/TingYunGo/goagent/nosql/go-redis" */
          /*****************************************************************************/
          import (
          	_ "github.com/TingYunGo/goagent/nosql/go-redis"
          )
          
        • 7.2.2.2 go-redis v7版本嵌码

          package main
          /********************************************************************************/
          /* go-redis v7:                                                                 */
          /* 在项目任意模块中添加代码 import "github.com/TingYunGo/goagent/nosql/go-redis/v7" */
          /********************************************************************************/
          import (
          	_ "github.com/TingYunGo/goagent/nosql/go-redis/v7"
          )
          
        • 7.2.2.3 go-redis v8版本嵌码

          package main
          /********************************************************************************/
          /* go-redis V8        :                                                         */
          /* 在项目任意模块中添加代码 import "github.com/TingYunGo/goagent/nosql/go-redis/v8" */
          /********************************************************************************/
          import (
          	_ "github.com/TingYunGo/goagent/nosql/go-redis/v8"
          )
          
  8. MongoDB自动嵌码

    package main
    /***********************************************************************************/
    /* MongoDB :                                                                       */
    /* 在项目任意模块中添加代码 import "github.com/TingYunGo/goagent/nosql/mongodb" */
    /***********************************************************************************/
    import (
    	_ "github.com/TingYunGo/goagent/nosql/mongodb"
    )
    

手动嵌码

对于自动嵌码不能满足需求的情况,可以使用手动嵌码方案. 手动嵌码相关知识:

概念

为了方便对程序问题的追踪, 我们将应用程序执行过程拆分出 事务组件 两个概念.

1. 事务:

事务 是一次服务请求的处理过程,例如:一次web请求, 或者rpc调用的server端处理过程。

2. 组件:

组件 是事务处理过程中各个子功能的处理过程,例如: rpc外部调用, 数据库调用, nosql调用, 消息队列访问的生产者和消费者请求,功能/逻辑算法的计算过程,模块封装的过程等.

SDK API
API 函数声明 功能
CreateAction
func CreateAction(name string, method string) (*Action, error)
创建事务对象.
如果是基于 net/http 的应用,请使用GetAction
GetAction
func GetAction() *Action
取当前协程上的事务对象(使用net/http的应用,探针会自动创建事务对象.使用本函数获取)
(*Action).CreateExternalComponent
func (*Action) CreateExternalComponent(url string, method string) *Component
创建一个外部服务访问组件
(*Action).CreateMQComponent
func (*Action) CreateMQComponent(vender string, isConsumer bool, host, queue string) *Component
创建一个消息队列访问组件
(*Action).CreateMongoComponent
func (*Action) CreateMongoComponent(host, database, collection, op, method string) *Component
创建mongos访问组件
(*Action).CreateComponent
func (*Action) CreateComponent(method string) *Component
创建自定义过程监控组件
(*Action).AddRequestParam
func (*Action) AddRequestParam(k string, v string)
添加事务请求参数
(*Action).AddResponseParam
func (*Action) AddResponseParam(k string, v string)
添加事务应答参数
(*Action).AddCustomParam
func (*Action) AddCustomParam(k string, v string)
添加事务自定义参数
(*Action).GetTxData
func (*Action) GetTxData() string
用于跨应用追踪被调用端,获取事务数据
(*Action).SetTrackID
func (*Action) SetTrackID(id string)
用于跨应用追踪被调用端,传递跨应用追踪ID
(*Action).SetName
func (*Action) SetName(name string, method string)
设置事务名, 参数同CreateAction
(*Action).SetHTTPMethod
func (*Action) SetHTTPMethod(httpMethod string)
设置http请求方法类型(GET/POST/PUT/OPTIONS/HEAD)
(*Action).SetURL
func (*Action) SetURL(name string)
设置事务的URI
(*Action).Ignore
func (*Action) Ignore()
忽略本次事务数据采集
(*Action).SetError
func (*Action) SetError(e interface{})
采集事务错误信息
(*Action).Finish
func (*Action) Finish()
事务采集结束
(*Action).SetStatusCode
func (*Action) SetStatusCode(code uint16) int
采集事务状态码
(*Component).GetAction
func (*Component) GetAction() *Action
取组件对应事务对象
(*Component).SetError
func (*Component) SetError(e interface{}, errType string, skipStack int)
采集错误
(*Component).Finish
func (*Component) Finish()
组件过程结束
(*Component).CreateTrackID
func (*Component) CreateTrackID() string
生成跨应用追踪ID
(*Component).SetTxData
func (*Component) SetTxData(txData string)
接收被调用端返回的跨应用追踪ID
(*Component).CreateComponent
func (*Component) CreateComponent(method string) *Component
创建组件的子过程(组件再分解)

CreateAction

/* 功能 : 创建事务组件
 * 参数 :
 *      name : 对应包/struct名
 *      method : 函数名
 * 返回值 :
 *      (事务对象指针, 错误)
 */
func CreateAction(name string, method string) (*Action, error)

GetAction

/* 功能 : 取当前协程对应的事务对象
 * 参数 : 无
 * 返回值 :
 *      事务组件对象指针
 */
GetAction() *Action

(*Action).CreateExternalComponent

/* 功能 : 创建外部调用组件
 * 参数 : 
 *         url : 外部服务调用url
 *         method : 外部调用过程识别名
 * 返回值 :
 *      外部调用组件指针
 */
func (*Action) CreateExternalComponent(url string, method string) *Component

(*Action).CreateMQComponent

/*
 * 功能 : 创建消息队列组件
 * 参数 :
 *     vender : 消息队列类型(rabbitMQ/Kafka/ActiveMQ)
 *     isConsumer : 是否消费者组件
 *     host : MQ地址
 *     queue : 消息队列名
 * 返回值 :
 *     消息队列组件指针
 */
func (*Action) CreateMQComponent(vender string, isConsumer bool, host, queue string) *Component

(*Action).CreateMongoComponent

/*
 * 功能 :  创建MongoDB访问组件
 * 参数 :
 *       host : 服务器地址
 *       database : 库名
 *       collection : collection 名
 *       op : mongo访问操作
 *       method : 组件过程识别名
 * 返回值 :
 *       MongoDB访问组件指针
 */
func (*Action) CreateMongoComponent(host, database, collection, op, method string) *Component

(*Action).CreateComponent

/*
 * 功能 : 创建自定义应用过程
 * 参数 :
 *        method : 组件过程识别名
 * 返回值 :
 *       自定义组件指针
 */
func (*Action) CreateComponent(method string) *Component

(*Action).AddRequestParam

/*
 * 功能 : 采集事务请求参数
 * 参数 : 
 *        k : 参数名
 *        v : 参数值
 * 返回值 : 无
 */
func (*Action) AddRequestParam(k string, v string)

(*Action).AddResponseParam

/*
 * 功能 : 采集事务响应参数
 * 参数 :
 *        k : 参数名
 *        v : 参数值
 * 返回值 : 无
 */
func (*Action) AddResponseParam(k string, v string)

(*Action).AddCustomParam

/*
 * 功能 : 采集自定义参数
 * 参数 :
 *        k : 参数名
 *        v : 参数值
 * 返回值 : 无
 */
func (*Action) AddCustomParam(k string, v string)

(*Action).GetTxData

/*
 * 功能 : 取事务执行性能数据 (跨应用追踪: 被调用端执行)
 * 参数 : 无
 * 返回值 : 
 *         事务性能数据
 */
func (*Action) GetTxData() string

(*Action).SetTrackID

/*
 * 功能 : 写入跨应用追踪数据 (跨应用追踪: 被调用端执行)
 * 参数 :
 *        id : 由调用端(*Component).CreateTrackID生成的, 调用过程携带到被调用端的字符串.
 * 返回值 : 无
 */
func (*Action) SetTrackID(id string)

(*Action).SetName

/*
 * 功能 : 重新设置事务名
 * 参数 :
 *      name : 定位更准确的包名/类(结构)名
 *      method : 函数名
 * 返回值 : 无
 */
func (*Action) SetName(name string, method string)

(*Action).SetHTTPMethod

/*
 * 功能 : 采集 http 请求方法
 * 参数 :
 *        httpMethod: GET/POST/HEAD/OPTIONS/PUT
 * 返回值 : 无
 */
func (*Action) SetHTTPMethod(httpMethod string)

(*Action).SetURL

/*
 * 功能 : 采集事务 URI
 * 参数 :
 *          name : 请求的URI
 * 返回值 : 无
 */
func (*Action) SetURL(name string)

(*Action).Ignore

/*
 * 功能 : 放弃本次采集的事务性能数据
 * 参数 :  无
 * 返回值 : 无
 */
func (*Action) Ignore()

(*Action).SetError

/*
 * 功能 : 采集错误数据, 抓取调用栈
 * 参数 : 
 *        e : error 对象
 * 返回值 : 无
 */
func (*Action) SetError(e interface{})

(*Action).Finish

/*
 * 功能 : 事务数据采集结束
 * 参数 :  无
 * 返回值 : 无
 */
func (*Action) Finish()

(*Action).SetStatusCode

/*
 * 功能 : 采集事务状态码
 * 参数 : 
 *      code : 事务应答状态码
 * 返回值 : 
 *        整数, 成功为0, 失败为非0
 */
func (*Action) SetStatusCode(code uint16) int

(*Component).GetAction

/*
 * 功能 : 取组件关联的事务对象
 * 参数 : 无
 * 返回值 :
 *        事务对象
 */
func (*Component) GetAction() *Action

(*Component).SetError

/*
 * 功能 : 采集组件错误
 * 参数 :
 *       e : error 对象
 *       errorType : 错误相关类型
 *       skipStack : 跳过采集的调用栈个数, 通常写0
 * 返回值 : 无
 */
func (*Component) SetError(e interface{}, errType string, skipStack int)

(*Component).Finish

/*
 * 功能 : 组件性能数据采集结束
 * 参数 : 无
 * 返回值 : 无
 */
func (*Component) Finish()

(*Component).CreateTrackID

/*
 * 功能 : 创建跨应用追踪ID字符串 (跨应用追踪: 调用端执行)
 * 参数 : 无
 * 返回值 :
 *        跨应用追踪ID信息(通过调用请求发送到被调用端)
 */
func (*Component) CreateTrackID() string

(*Component).SetTxData

/*
* 功能 : 写入被调用端事务执行性能数据 (跨应用追踪: 调用端执行). 将rpc调用返回时携带的事务数据写入 
 * 参数 :  
 *        txData : 由被调用端 (*Action).GetTxData 生成的数据
 * 返回值 : 无
 */
func (*Component) SetTxData(txData string)

(*Component).CreateComponent

/*
 * 功能 : 组件再细分子组件
 * 参数 :
 *       子组件方法名
 * 返回值 :
 *       组件对象
 */
func (*Component) CreateComponent(method string) *Component

配置&运行

已经嵌码的程序需要通过环境变量指定配置文件路径

export TINGYUN_GO_APP_CONFIG=`pwd`/tingyun.json

配置文件格式

{
  "nbs.app_name" : "替换为您的应用名称",
  "nbs.license_key" : "替换为您的license",
  "nbs.host" : "替换为collector的ip:port",  
  "nbs.agent_enabled" : true,  
  "nbs.log_file_name" : "agent.log",
  "nbs.audit" : false,
  "nbs.max_log_count": 5,
  "nbs.max_log_size": 10,
  "nbs.action_cache_max" : 10000,
  "nbs.ssl" : false,
  "nbs.savecount" : 5
}

环境变量:(环境变量设置的配置项将覆盖配置文件里的设定值)

agent_enabled  # 启用探针选项, 取值: true/false; 缺省值: true
audit_mode  # 审计模式, 审计模式日志开启选项, 取值: true/false; 缺省值: false
agent_log_level  # 日志级别设置, 取值: debug/info/warning/error; 缺省值: info
agent_log_file  # 日志文件路径
license_key  # 授权序列码
collectors  # collector服务器地址,多个地址以逗号分隔
agent_init_delay  # 探针延时初始化时间,整数,单位秒, 缺省值1.  说明: 如果探针初始化过早,可能在应用开始listen之前初始化, 这种情况下探针抓不到应用listen的端口. 增加初始化延时以解决此问题.
TINGYUN_GO_APP_NAME  # 应用名称

Documentation

Overview

Package tingyun3 听云性能采集探针(sdk)

Index

Constants

View Source
const (
	ComponentDefault    = 0
	ComponentDefaultDB  = 32
	ComponentMysql      = 33
	ComponentPostgreSQL = 34
	ComponentMSSQL      = 35
	ComponentSQLite     = 36
	ComponentMongo      = 48
	ComponentMemCache   = 49
	ComponentRedis      = 50
	ComponentMQC        = 56
	ComponentMQP        = 57
	ComponentExternal   = 64
)

* 组件类型定义

View Source
const (
	LevelOff      = log.LevelOff
	LevelCritical = log.LevelCritical
	LevelError    = log.LevelError
	LevelWarning  = log.LevelWarning
	LevelInfo     = log.LevelInfo
	LevelVerbos   = log.LevelVerbos
	LevelDebug    = log.LevelDebug
	LevelMask     = log.LevelMask
	Audit         = log.Audit
)

* 日志级别/审计模式控制

View Source
const TINGYUN_GO_AGENT_VERSION = "v0.6.7"

Variables

This section is empty.

Functions

func ConfigRead

func ConfigRead(name string) (interface{}, bool)

ConfigRead : 读配置项

func GetCallerName

func GetCallerName(layer int) string

GetCallerName : 取layer层调用栈函数名

func GetCallerPC

func GetCallerPC(layer int) (l int, pc uintptr)

GetCallerPC return caller pc

func GetGID

func GetGID() int64

GetGID return goroutine id

func HttpClientDo

func HttpClientDo(ptr uintptr, req *http.Request) (*http.Response, error)

func LocalClear added in v0.6.0

func LocalClear()

Clear Routine Local Storage

func LocalDelete

func LocalDelete(id int) interface{}

LocalDelete : 从协程局部存储器中删除key为 id的对象,并返回这个对象

func LocalGet

func LocalGet(id int) interface{}

LocalGet : 从协程局部存储器中取出key为 id的对象,没有则返回nil

func LocalSet

func LocalSet(id int, object interface{})

LocalSet : 以id为key, 将对象object写入协程局部存储器

func Log

func Log() *log.Logger

Log : 返回日志对象接口

func Register

func Register(p uintptr)

Register : native method

func ServerMuxHandle

func ServerMuxHandle(ptr uintptr, pattern string, handler http.Handler)

func ServerServe

func ServerServe(srv *http.Server, l net.Listener) error

func SetAction

func SetAction(action *Action)

SetAction : 辅助功能函数: 将事务存到协程局部存储器

func SetComponent

func SetComponent(c *Component)

SetComponent : 辅助功能函数: 将组件存到协程局部存储器

func WrapHttpClientDo

func WrapHttpClientDo(ptr uintptr, req *http.Request) (*http.Response, error)

func WrapServerMuxHandle

func WrapServerMuxHandle(ptr uintptr, pattern string, handler http.Handler)

func WrapServerServe

func WrapServerServe(srv *http.Server, l net.Listener) error

func WraphttpNotFound added in v0.2.0

func WraphttpNotFound(w http.ResponseWriter, r *http.Request)

Types

type Action

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

Action : 事务对象

func CreateAction

func CreateAction(name string, method string) (*Action, error)

CreateAction : 在方法method中调用并 创建一个名为 name的事务,

func GetAction

func GetAction() *Action

GetAction : 辅助功能函数: 将存储到协程局部存储器的Action对象取出

func (*Action) AddCustomParam

func (a *Action) AddCustomParam(k string, v string)

AddCustomParam : 添加自定义参数

func (*Action) AddRequestParam

func (a *Action) AddRequestParam(k string, v string)

AddRequestParam : 添加请求参数

func (*Action) AddResponseParam

func (a *Action) AddResponseParam(k string, v string)

AddResponseParam : 添加应答参数

func (*Action) CreateComponent

func (a *Action) CreateComponent(method string) *Component

CreateComponent : 创建函数/方法类型的组件 参数

method : 类名.方法名, 例如 main.user.login

func (*Action) CreateDBComponent

func (a *Action) CreateDBComponent(dbType uint8, host string, dbname string, table string, op string, method string) *Component

CreateDBComponent 创建数据库或NOSQL性能分解组件 参数:

dbType : 组件类型 (ComponentMysql, ComponentPostgreSQL, ComponentMongo, ComponentMemCache, ComponentRedis)
host   : 主机地址,可空
dbname : 数据库名称,可空
table  : 数据库表名
op     : 操作类型, 关系型数据库("SELECT", "INSERT", "UPDATE", "DELETE" ...), NOSQL("GET", "SET" ...)
method : 发起这个数据库调用的类名.方法名, 例如 db.query redis.get

func (*Action) CreateExternalComponent

func (a *Action) CreateExternalComponent(url string, method string) *Component

CreateExternalComponent : 创建Web Service性能分解组件 参数:

url    : 调用Web Service的url,格式: http(s)://host/uri, 例如 http://www.baidu.com/
method : 发起这个Web Service调用的类名.方法名, 例如 http.Get

func (*Action) CreateMQComponent

func (a *Action) CreateMQComponent(vender string, isConsumer bool, host, queue string) *Component

CreateMQComponent : 创建一个消息队列组件

vender : mq类型: kafka/rabbit MQ/ActiveMQ

func (*Action) CreateMongoComponent

func (a *Action) CreateMongoComponent(host, database, collection, op, method string) *Component

CreateMongoComponent 创建 Mongo 组件

func (*Action) CreateRedisComponent

func (a *Action) CreateRedisComponent(host, cmd, key, method string) *Component

CreateRedisComponent : 创建一个Redis数据库访问组件

func (*Action) CreateSQLComponent

func (a *Action) CreateSQLComponent(dbType uint8, host string, dbname string, sql string, method string) *Component

CreateSQLComponent : 以 SQL语句创建一个数据库组件

func (*Action) Finish

func (a *Action) Finish()

Finish : 事务结束时调用 HTTP请求时长 = Finish时刻 - CreateAction时刻

func (*Action) GetMethod added in v0.3.0

func (a *Action) GetMethod() string

func (*Action) GetName

func (a *Action) GetName() string

GetName : 取事务名字

func (*Action) GetTxData

func (a *Action) GetTxData() string

GetTxData : 跨应用追踪接口,用于被调用端,获取当前事务的执行性能信息,通过http头或者自定义协议传回调用端

返回值: 事务的性能数据

func (*Action) GetURL

func (a *Action) GetURL() string

GetURL : 取事务的 URL

func (*Action) HasError

func (a *Action) HasError() bool

HasError : 是否发生过错误或异常

func (*Action) Ignore

func (a *Action) Ignore()

Ignore : 忽略本次事务的性能数据

func (*Action) OnEnd

func (a *Action) OnEnd(cb func())

OnEnd : 注册一个在事务结束时执行的回调函数

func (*Action) SetError

func (a *Action) SetError(e interface{})

SetError : 事务发生错误或异常时调用,记录事务的运行时错误信息

func (*Action) SetHTTPMethod

func (a *Action) SetHTTPMethod(httpMethod string)

SetHTTPMethod : 设置 HTTP请求方法名

func (*Action) SetHTTPStatus

func (a *Action) SetHTTPStatus(code uint16, skip int) int

SetHTTPStatus : 内部使用: 添加 http状态, skip为跳过的调用栈

func (*Action) SetName

func (a *Action) SetName(name string, method string)

SetName : 设置HTTP请求的友好名称 参数:

instance   : 分类, 例如 loginController
method : 方法, 例如 POST

func (*Action) SetStatusCode

func (a *Action) SetStatusCode(code uint16) int

SetStatusCode : 正常返回0 无效的Action 返回1 如果状态码是被忽略的错误,返回2 错误的状态码,返回3

func (*Action) SetTrackID

func (a *Action) SetTrackID(id string)

SetTrackID : 跨应用追踪接口,用于被调用端,保存调用端传递过来的跨应用追踪id

参数: 跨应用追踪id

func (*Action) SetURL

func (a *Action) SetURL(name string)

SetURL : 设置事务的url

func (*Action) Slow

func (a *Action) Slow() bool

Slow : 检测本次事务是否为慢请求 返回值: 当HTTP请求性能超出阈值时为true, 否则为false

type Component

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

Component : 构成事务的组件过程

func GetComponent

func GetComponent() *Component

GetComponent : 辅助功能函数: 将存储到协程局部存储器的组件对象取出

func (*Component) AppendSQL

func (c *Component) AppendSQL(sql string)

AppendSQL : 用于数据库组件,通过此接口将sql查询语句保存到数据库组件,在报表慢事务追踪列表展示

参数: sql语句

func (*Component) CreateComponent

func (c *Component) CreateComponent(method string) *Component

CreateComponent : 在函数/方法中调用其他函数/方法时,如果认为有必要,调用此方法测量子过程性能

func (*Component) CreateTrackID

func (c *Component) CreateTrackID() string

CreateTrackID : 跨应用追踪接口,用于调用端,生成一个跨应用追踪id,通过http头或者私有协议发送到被调用端

返回值: 字符串,一个包含授权id,应用id,实例id,事务id等信息的追踪id

func (*Component) End

func (c *Component) End(skip int)

End : 内部使用, skip为跳过的调用栈数

func (*Component) Finish

func (c *Component) Finish()

Finish : 停止组件计时 性能分解组件时长 = Finish时刻 - CreateComponent时刻 当时长超出堆栈阈值时,记录当前组件的代码堆栈

func (*Component) FixBegin

func (c *Component) FixBegin(begin time.Time)

FixBegin : 校正事务开始时间

func (*Component) GetAction

func (c *Component) GetAction() *Action

GetAction : 取对应的事务对象

func (*Component) SetError

func (c *Component) SetError(e interface{}, errType string, skipStack int)

SetError : 组件错误捕获

func (*Component) SetMethod added in v0.6.7

func (c *Component) SetMethod(method string)

func (*Component) SetTxData

func (c *Component) SetTxData(txData string)

SetTxData : 跨应用追踪接口,用于调用端,将被调用端返回的事务性能数据保存到外部调用组件

参数: 被调用端返回的事务的性能数据

type RoutineLocal

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

RoutineLocal : 事务线程局部存储对象

type Unit

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

Unit is The GoRoutine LocalStorage Unit

Directories

Path Synopsis
frameworks
gin
libs
list
Package list : a list
Package list : a list
map
pool
Package pool 无锁消息池,多读多写, 用于goroutine 间收发消息
Package pool 无锁消息池,多读多写, 用于goroutine 间收发消息
nosql
utils
cache_config
配置信息缓存的性能优化版本,无锁访问, array存储
配置信息缓存的性能优化版本,无锁访问, array存储
config
无锁模式的配置信息读写
无锁模式的配置信息读写
httprequest
Post请求异步封装
Post请求异步封装
logger
日志功能模块。
日志功能模块。
service
类线程封装
类线程封装
zip
zip封装
zip封装

Jump to

Keyboard shortcuts

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