mod_trace

模块简介

mod_trace根据自定义的条件,为请求开启分布式跟踪。

基础配置

配置描述

模块配置文件: conf/mod_trace/mod_trace.conf

基础配置项

配置项 描述
Basic.DataPath String
规则配置文件路径
Basic.ServiceName String
服务名
Basic.TraceAgent String
设置trace组件,可选值:jaeger和zipkin
Log.OpenDebug Boolean
是否启用模块调试日志开关

Zipkin配置项

配置项 描述
Zipkin.HTTPEndpoint String
设置接收trace信息的接口
Zipkin.SameSpan String
客户端与服务端是否使用相同的span
Zipkin.ID128Bit String
是否使用128位span ID
Zipkin.SampleRate Float
设置请求抽样比例

Jaeger配置项

配置项 描述
Jaeger.SamplingServerURL String
设置抽样服务地址
Jaeger.SamplingType String
设置抽样类型,可选值:const, probabilistic, rateLimiting, remote
Jaeger.SamplingParam Float
设置抽样参数
Jaeger.LocalAgentHostPort String
设置接收span信息的jaeger-agent地址
Jaeger.Propagation String
设置透传格式,可选值:jaeger或b3
Jaeger.Gen128Bit Boolean
是否使用128位span ID
Jaeger.TraceContextHeaderName String
设置上下文中header名称
Jaeger.CollectorEndpoint String
设置jaeger-collector地址
Jaeger.CollectorUser String
设置jaeger-collector认证用户名
Jaeger.CollectorPassword String
设置jaeger-collector认证密码

Elastic配置项

配置项 描述
Elastic.ServerURL String
设置Elastic APM server
Elastic.SecretToken String
设置Elastic APM server认证token

配置示例

基于Zipkin示例

  1. [Basic]
  2. DataPath = mod_trace/trace_rule.data
  3. ServiceName = bfe
  4. # Which trace agent to use (zipkin, jaeger, elastic)
  5. TraceAgent = zipkin
  6. [Log]
  7. OpenDebug = false
  8. [Zipkin]
  9. # Zipkin, only useful when the TraceAgent is zipkin
  10. # HTTP Endpoint to report traces to
  11. HTTPEndpoint = http://127.0.0.1:9411/api/v2/spans
  12. # Use Zipkin SameSpan RPC style traces
  13. SameSpan = false
  14. # Use Zipkin 128 bit root span IDs
  15. ID128Bit = true
  16. # The rate between 0.0001 and 1.0 of requests to trace
  17. SampleRate = 1.0

基于Jaeger示例

  1. [Basic]
  2. DataPath = mod_trace/trace_rule.data
  3. ServiceName = bfe
  4. # Which trace agent to use (zipkin, jaeger, elastic)
  5. TraceAgent = jaeger
  6. [Log]
  7. OpenDebug = false
  8. [Jaeger]
  9. # Jaeger, only useful when the TraceAgent is jaeger
  10. # SamplingServerURL is the address of jaeger-agent's HTTP sampling server
  11. SamplingServerURL = http://127.0.0.1:5778/sampling
  12. # Type specifies the type of the sampler: const, probabilistic, rateLimiting, or remote
  13. SamplingType = const
  14. # Param is a value passed to the sampler.
  15. # Valid values for Param field are:
  16. # - for "const" sampler, 0 or 1 for always false/true respectively
  17. # - for "probabilistic" sampler, a probability between 0 and 1
  18. # - for "rateLimiting" sampler, the number of spans per second
  19. # - for "remote" sampler, param is the same as for "probabilistic"
  20. # and indicates the initial sampling rate before the actual one
  21. # is received from the mothership.
  22. SamplingParam = 1.0
  23. # LocalAgentHostPort instructs reporter to send spans to jaeger-agent at this address
  24. LocalAgentHostPort = 127.0.0.1:6831
  25. # Which propagation format to use (jaeger/b3)
  26. Propagation = jaeger
  27. # Use Jaeger 128 bit root span IDs
  28. Gen128Bit = true
  29. # TraceContextHeaderName is the http header name used to propagate tracing context.
  30. TraceContextHeaderName = uber-trace-id
  31. # Instructs reporter to send spans to jaeger-collector at this URL
  32. CollectorEndpoint = ""
  33. # CollectorUser for basic http authentication when sending spans to jaeger-collector
  34. CollectorUser = ""
  35. # CollectorPassword for basic http authentication when sending spans to jaeger-collector
  36. CollectorPassword = ""

基于Elastic示例

  1. [Basic]
  2. DataPath = mod_trace/trace_rule.data
  3. ServiceName = bfe
  4. # Which trace agent to use (zipkin, jaeger, elastic)
  5. TraceAgent = elastic
  6. [Log]
  7. OpenDebug = false
  8. [Elastic]
  9. # Elastic, only useful when TraceAgent is elastic
  10. # Set the URL of the Elastic APM server
  11. ServerURL = http://127.0.0.1:8200
  12. # Set the token used to connect to Elastic APM Server
  13. SecretToken = ""

规则配置

配置描述

规则配置文件: conf/mod_trace/trace_rule.data

配置项 描述
Version String
配置文件版本
Config Object
各产品线的规则列表
Config[k] String
产品线名称
Config[v] Object
产品线的规则列表
Config[v][] Object
产品线的规则
Config[v][].Cond String
规则的匹配条件, 语法详见Condition
Config[v][].Enable Boolean
是否开启trace

配置示例

  1. {
  2. "Version": "20200218210000",
  3. "Config": {
  4. "example_product": [
  5. {
  6. "Cond": "req_host_in(\"example.org\")",
  7. "Enable": true
  8. }
  9. ]
  10. }
  11. }