链路追踪

全链路追踪

Dubbo-go 支持基于 OpenTelemetry 标准的全链路追踪埋点,同时支持通过以下 exporter 导出到不同的 tracing 后端系统。

使用方式

请注意,仅支持通过 dubbo.NewInstance 方式创建 dubbo 应用时开启 tracing 功能,也就是我们快速开始中提到的 微服务应用模式,对于 轻量 RPC API 暂时不支持开启 tracing。

示例详解

可在此查看 完整示例源码地址

使用 dubbo.WithTracing() 开启 tracing,可以通过多个参数控制 tracing 行为:

  1. package main
  2. import (
  3. "dubbo.apache.org/dubbo-go/v3"
  4. _ "dubbo.apache.org/dubbo-go/v3/imports"
  5. "dubbo.apache.org/dubbo-go/v3/otel/trace"
  6. )
  7. func main() {
  8. instance, err := dubbo.NewInstance(
  9. dubbo.WithTracing(
  10. // add tracing options here
  11. trace.WithEnabled(), // enable tracing feature
  12. trace.WithStdoutExporter(),
  13. trace.WithW3cPropagator(),
  14. trace.WithAlwaysMode(),
  15. trace.WithRatioMode(), // use ratio mode
  16. trace.WithRatio(0.5), // sample ratio, only active when use ratio mode
  17. ),
  18. )
  19. }

如果你在 dubbo.WithTracing() 调用中不指定任何 option 参数,则会使用默认行为:

  1. # default tracing config
  2. enable: false
  3. exporter: stdout
  4. endpoint: ""
  5. propagator: w3c
  6. sample-mode: ratio
  7. sample-ratio: 0.5

TracingOptions详解

  • enable: enable tracing or not
    • trace.WithEnabled() means enable tracing
  • exporter: tracing exporter backends, support stdout, jaeger, zipkin, otlp-http, otlp-grpc
    • trace.WithStdoutExporter()
    • trace.WithJaegerExporter()
    • trace.WithZipkinExporter()
    • trace.WithOtlpHttpExporter()
    • trace.WithOtlpGrpcExporter()
  • endpoint: exporter backend endpoint, for example, jaeger exporter’s endpoint is http://localhost:14268/api/traces
    • trace.WithEndpoint(string)
  • propagator: context propagator type, support w3c, b3, more details you can see here
    • trace.WithW3cPropagator()
    • trace.WithB3Propagator() zipkin exporter default use this
  • sample-mode: sample mode, support ratio, always, never
    • trace.WithAlwaysMode()
    • trace.WithNeverMode()
    • trace.WithRatioMode()
  • sample-ratio: sample ratio, only used when sample-mode is ratio, range between 0 and 1
    • trace.WithRatio(float64)

最后修改 September 13, 2024: Refactor website structure (#2860) (1a4b998f54b)