文档:https://godoc.org/github.com/uber/jaeger-client-go/config
type Configuration
配置并创建Jaeger跟踪程序
type Configuration struct {// 服务名称ServiceName string `yaml:"serviceName"`// 禁用FromEnv()加载变量Disabled bool `yaml:"disabled"`// RPCMetrics can be provided by FromEnv() via the environment variable named JAEGER_RPC_METRICSRPCMetrics bool `yaml:"rpc_metrics"`// Tags can be provided by FromEnv() via the environment variable named JAEGER_TAGSTags []opentracing.Tag `yaml:"tags"`Sampler *SamplerConfig `yaml:"sampler"`Reporter *ReporterConfig `yaml:"reporter"`Headers *jaeger.HeadersConfig `yaml:"headers"`BaggageRestrictions *BaggageRestrictionsConfig `yaml:"baggage_restrictions"`Throttler *ThrottlerConfig `yaml:"throttler"`}
func FromEnv() (Configuration, error) 使用环境变量,初始化Configuration
func (c Configuration) FromEnv() (*Configuration, error) 使用环境变量,覆盖现有的Configuration
func (c Configuration) NewTracer(options …Option) (opentracing.Tracer, io.Closer, error)
- NewTracer使用给定的选项返回基于当前配置的新跟踪程序
- 注意,使用完后一定要close用于刷新缓冲区,否则会造成数据丢失
type BaggageRestrictionsConfig
Baggage是存储在SpanContext中的一个键值对(SpanContext)集合。它会在一条追踪链路上的所有span内全局传输,消耗大,暂时用不到,不做了解
type BaggageRestrictionsConfig struct {// DenyBaggageOnInitializationFailure controls the startup failure mode of the baggage restriction// manager. If true, the manager will not allow any baggage to be written until baggage restrictions have// been retrieved from jaeger-agent. If false, the manager wil allow any baggage to be written until baggage// restrictions have been retrieved from jaeger-agent.DenyBaggageOnInitializationFailure bool `yaml:"denyBaggageOnInitializationFailure"`// HostPort is the hostPort of jaeger-agent's baggage restrictions serverHostPort string `yaml:"hostPort"`// RefreshInterval controls how often the baggage restriction manager will poll// jaeger-agent for the most recent baggage restrictions.RefreshInterval time.Duration `yaml:"refreshInterval"`}
type Option
func MaxTagValueLength(maxTagValueLength int) Option 限制标签最大长度
func Logger(logger jaeger.Logger) Option 用于记录报告器信息,参考下面
func Tag(key string, value interface{}) Option 提供一个跟踪级别的tag
func Reporter(reporter jaeger.Reporter) Option 显示提供reporter信息,将会覆盖已配置的信息
func Sampler(sampler jaeger.Sampler) Option 显示提供sampler信息,将会覆盖已配置的信息
type ReporterConfig
报告者信息配置
type ReporterConfig struct {// QueueSize控制在开始删除新的span之前,报告器可以在内存中保留多少spanQueueSize int `yaml:"queueSize"`// BufferFlushInterval控制强制刷新缓冲区的频率,即使缓冲区还没有满。// 它通常没什么用,因为它只对流量非常低的服务有用BufferFlushInterval time.Duration// 当logspan为true时,启用与主报告器并行运行的LoggingReporter并记录所有提交的spanLogSpans bool `yaml:"logSpans"`// jaeger-agent连接地址LocalAgentHostPort string `yaml:"localAgentHostPort"`//当为true时,将禁用udp连接助手,该助手会定期重新解析代理的主机名,并在发生更改时重新连接// 此选项仅在指定LocalAgentHostPort时应用DisableAttemptReconnecting bool `yaml:"disableAttemptReconnecting"`// AttemptReconnectInterval控制代理客户端重新解析提供的主机名的频率// 来检测地址的变化。此选项仅适用于DisableAttemptReconnecting为false的情况。AttemptReconnectInterval time.Duration// jaeger-collector的url,直接向jaeger-collector发信息CollectorEndpoint string `yaml:"collectorEndpoint"`// User指示reporter在向jaeger-collector发送跨越时包含一个用于基本http身份验证的用户User string `yaml:"user"`// Password指示reporter在发送span时包含一个用于基本http身份验证的密码Password string `yaml:"password"`// HTTPHeaders指示报告器在报告跨度时将这些头添加到http请求中.HTTPHeaders map[string]string `yaml:"http_headers"`}
func (rc ReporterConfig) NewReporter(serviceName string,metrics jaeger.Metrics,logger jaeger.Logger) (jaeger.Reporter, error)
type SamplerConfig
采样信息配置
type SamplerConfig struct {// 指定采样器的类型: const, probabilistic, rateLimiting, or remote.Type string `yaml:"type"`// 采样的具体策略// Valid values for Param field are:// - for "const" sampler, 0标识不采,1标识一直采// - for "probabilistic" sampler, 可能性在0-1之间,就是0%-100%// - for "rateLimiting" sampler, 每秒采样的次数// - for "remote" sampler, 同probabilisticParam float64 `yaml:"param"`// 通过url来获取采样策略SamplingServerURL string `yaml:"samplingServerURL"`// 多久更新一次采样策略SamplingRefreshInterval time.Duration `yaml:"samplingRefreshInterval"`// 待了解MaxOperations int `yaml:"maxOperations"`// 待了解OperationNameLateBinding bool `yaml:"operationNameLateBinding"`// 待了解Options []jaeger.SamplerOption}
func (sc SamplerConfig) NewSampler( serviceName string, metrics jaeger.Metrics) (jaeger.Sampler, error)
