文档:https://godoc.org/github.com/uber/jaeger-client-go/config

type Configuration

配置并创建Jaeger跟踪程序

  1. type Configuration struct {
  2. // 服务名称
  3. ServiceName string `yaml:"serviceName"`
  4. // 禁用FromEnv()加载变量
  5. Disabled bool `yaml:"disabled"`
  6. // RPCMetrics can be provided by FromEnv() via the environment variable named JAEGER_RPC_METRICS
  7. RPCMetrics bool `yaml:"rpc_metrics"`
  8. // Tags can be provided by FromEnv() via the environment variable named JAEGER_TAGS
  9. Tags []opentracing.Tag `yaml:"tags"`
  10. Sampler *SamplerConfig `yaml:"sampler"`
  11. Reporter *ReporterConfig `yaml:"reporter"`
  12. Headers *jaeger.HeadersConfig `yaml:"headers"`
  13. BaggageRestrictions *BaggageRestrictionsConfig `yaml:"baggage_restrictions"`
  14. Throttler *ThrottlerConfig `yaml:"throttler"`
  15. }

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内全局传输,消耗大,暂时用不到,不做了解

  1. type BaggageRestrictionsConfig struct {
  2. // DenyBaggageOnInitializationFailure controls the startup failure mode of the baggage restriction
  3. // manager. If true, the manager will not allow any baggage to be written until baggage restrictions have
  4. // been retrieved from jaeger-agent. If false, the manager wil allow any baggage to be written until baggage
  5. // restrictions have been retrieved from jaeger-agent.
  6. DenyBaggageOnInitializationFailure bool `yaml:"denyBaggageOnInitializationFailure"`
  7. // HostPort is the hostPort of jaeger-agent's baggage restrictions server
  8. HostPort string `yaml:"hostPort"`
  9. // RefreshInterval controls how often the baggage restriction manager will poll
  10. // jaeger-agent for the most recent baggage restrictions.
  11. RefreshInterval time.Duration `yaml:"refreshInterval"`
  12. }

type Option

func MaxTagValueLength(maxTagValueLength int) Option 限制标签最大长度
func Logger(logger jaeger.Logger) Option 用于记录报告器信息,参考下面
image.png
func Tag(key string, value interface{}) Option 提供一个跟踪级别的tag
func Reporter(reporter jaeger.Reporter) Option 显示提供reporter信息,将会覆盖已配置的信息
func Sampler(sampler jaeger.Sampler) Option 显示提供sampler信息,将会覆盖已配置的信息

type ReporterConfig

报告者信息配置

  1. type ReporterConfig struct {
  2. // QueueSize控制在开始删除新的span之前,报告器可以在内存中保留多少span
  3. QueueSize int `yaml:"queueSize"`
  4. // BufferFlushInterval控制强制刷新缓冲区的频率,即使缓冲区还没有满。
  5. // 它通常没什么用,因为它只对流量非常低的服务有用
  6. BufferFlushInterval time.Duration
  7. // 当logspan为true时,启用与主报告器并行运行的LoggingReporter并记录所有提交的span
  8. LogSpans bool `yaml:"logSpans"`
  9. // jaeger-agent连接地址
  10. LocalAgentHostPort string `yaml:"localAgentHostPort"`
  11. //当为true时,将禁用udp连接助手,该助手会定期重新解析代理的主机名,并在发生更改时重新连接
  12. // 此选项仅在指定LocalAgentHostPort时应用
  13. DisableAttemptReconnecting bool `yaml:"disableAttemptReconnecting"`
  14. // AttemptReconnectInterval控制代理客户端重新解析提供的主机名的频率
  15. // 来检测地址的变化。此选项仅适用于DisableAttemptReconnecting为false的情况。
  16. AttemptReconnectInterval time.Duration
  17. // jaeger-collector的url,直接向jaeger-collector发信息
  18. CollectorEndpoint string `yaml:"collectorEndpoint"`
  19. // User指示reporter在向jaeger-collector发送跨越时包含一个用于基本http身份验证的用户
  20. User string `yaml:"user"`
  21. // Password指示reporter在发送span时包含一个用于基本http身份验证的密码
  22. Password string `yaml:"password"`
  23. // HTTPHeaders指示报告器在报告跨度时将这些头添加到http请求中.
  24. HTTPHeaders map[string]string `yaml:"http_headers"`
  25. }

func (rc ReporterConfig) NewReporter(serviceName string,metrics jaeger.Metrics,logger jaeger.Logger) (jaeger.Reporter, error)

type SamplerConfig

采样信息配置

  1. type SamplerConfig struct {
  2. // 指定采样器的类型: const, probabilistic, rateLimiting, or remote.
  3. Type string `yaml:"type"`
  4. // 采样的具体策略
  5. // Valid values for Param field are:
  6. // - for "const" sampler, 0标识不采,1标识一直采
  7. // - for "probabilistic" sampler, 可能性在0-1之间,就是0%-100%
  8. // - for "rateLimiting" sampler, 每秒采样的次数
  9. // - for "remote" sampler, 同probabilistic
  10. Param float64 `yaml:"param"`
  11. // 通过url来获取采样策略
  12. SamplingServerURL string `yaml:"samplingServerURL"`
  13. // 多久更新一次采样策略
  14. SamplingRefreshInterval time.Duration `yaml:"samplingRefreshInterval"`
  15. // 待了解
  16. MaxOperations int `yaml:"maxOperations"`
  17. // 待了解
  18. OperationNameLateBinding bool `yaml:"operationNameLateBinding"`
  19. // 待了解
  20. Options []jaeger.SamplerOption
  21. }

func (sc SamplerConfig) NewSampler( serviceName string, metrics jaeger.Metrics) (jaeger.Sampler, error)