trace 数据接入

监控 Agent 已经集成了 jaeger agent 的功能,你可以在程序中直接通过监控 Agent 上报 trace 数据, 开只需简单修改配置. 服务开启后, Agent 会在本机的localhost上监听UDP端口6831


启用 Agent trace 功能

监控服务器中安装监控 agent并开启 trace 功能, 修改配置文件 /usr/local/monitor-agent/conf/monitor-agent.conf:

        # 开启trace功能
        enable = true
		# 配置 jaeger colletor 地址
        collector = [ "" ]

关于 jaeger 相关资料可以参考:

抽样策略 (Sampling)


jaeger 有4中采样策略可供选择,建议在 2、3 中进行选择。

  • Constant (sampler.type=const) sampler always makes the same decision for all traces. It either samples all traces (sampler.param=1) or none of them (sampler.param=0).
  • Probabilistic (sampler.type=probabilistic) sampler makes a random sampling decision with the probability of sampling equal to the value of sampler.param property. For example, with sampler.param=0.1 approximately 1 in 10 traces will be sampled.
  • Rate Limiting (sampler.type=ratelimiting) sampler uses a leaky bucket rate limiter to ensure that traces are sampled with a certain constant rate. For example, when sampler.param=2.0 it will sample requests with the rate of 2 traces per second.
  • Remote (sampler.type=remote, which is also the default) sampler consults Jaeger agent for the appropriate sampling strategy to use in the current service. This allows controlling the sampling strategies in the services from a central configuration in Jaeger backend, or even dynamically (see Adaptive Sampling).

程序上报 trace 数据例子

package main

import (

        opentracing ""

        jaegerClientConfig ""

func main() {
		cfg := jaegerClientConfig.Configuration{
				Sampler: &jaegerClientConfig.SamplerConfig{
						Type:  "const",
						Param: 1,
				Reporter: &jaegerClientConfig.ReporterConfig{
						LogSpans:            true,
						BufferFlushInterval: 1 * time.Second,
						LocalAgentHostPort:  "localhost:6831",
		tracer, closer, _ := cfg.New(

		tracer2(testTracer1(tracer)) // working
		// testTracer()

        select {}