Skip to content

Traefik Tracing 概览

Tracing

可视化请求流

tracing 系统允许开发人员可视化其基础架构中的调用流。

Traefik 使用 OpenTelemetry,这是为分布式 tracing 设计的开放标准。

配置示例

要启用 tracing:

YAML

yaml
tracing: {}

TOML

toml
[tracing]

CLI

bash
--tracing=true

Helm Chart Values

yaml
  tracing:
    otlp:
        enabled: true

配置选项

字段描述默认值必填
tracing.addInternals启用内部资源的 tracing。false
tracing.serviceNameservice name resource 属性。"traefik"
tracing.resourceAttributes其它 resource 属性。[]
tracing.sampleRate要追踪的请求比例,介于 0.0 和 1.0 之间。由于 Traefik 支持基于父级的采样比率,根 spans(即由 Traefik 发起的 spans)根据此速率进行采样,而子 spans 继承其父级的采样决定(即来自传入请求的 tracing context)。1.0
tracing.capturedRequestHeaders要添加为属性的请求头列表。适用于 client 和 server kind spans。[]
tracing.capturedResponseHeaders要添加为属性的响应头列表。适用于 client 和 server kind spans。[]false
tracing.safeQueryParams默认情况下,所有查询参数都被隐藏。定义不隐藏的查询参数列表。[]
tracing.otlp.http指示导出器使用 HTTP 发送 tracing。null/false
tracing.otlp.http.endpointHTTP 端点(格式 <scheme>://<host>:<port><path>)。"https://localhost:4318/v1/tracing"
tracing.otlp.http.headers其它请求头。
tracing.otlp.http.tls.caCA 证书路径。""
tracing.otlp.http.tls.cert公共证书路径。""
tracing.otlp.http.tls.key私钥路径。""
tracing.otlp.http.tls.insecureSkipVerify接受任何证书。false
tracing.otlp.grpc指示导出器使用 gRPC 发送 tracing。false
tracing.otlp.grpc.endpointgRPC 端点(格式 <host>:<port>)。"localhost:4317"
tracing.otlp.grpc.headers其它请求头。[]
tracing.otlp.grpc.insecure允许使用不安全协议。false
tracing.otlp.grpc.tls.*gRPC TLS 配置。

sampleRate

sampleRate 选项使用 ParentBased(TraceIDRatioBased) 策略控制 trace 采样。

采样策略行为

  • Root spans(源自 Traefik 的 trace):使用基于 trace ID 比率的采样根据配置的 sampleRate 进行采样。
  • Child spans(具有现有 trace context 的请求):从父 span 继承采样决定,无论本地 sampleRate 如何。

这确保了跨分布式 trace 的一致采样决定:一旦 trace 被采样,该 trace 中的所有 spans 都将被采样,提供完整的端到端可见性。

resourceAttributes

resourceAttributes 选项允许设置与 traces 一起发送的 resource 属性。Traefik 也支持 OTEL_RESOURCE_ATTRIBUTES 环境变量来设置 resource 属性。

Kubernetes Resource Attributes Detection

此外,在 Kubernetes 集群中运行时,Traefik 会自动发现以下 Kubernetes resource attributes

  • k8s.namespace.name
  • k8s.pod.uid
  • k8s.pod.name

请注意,这种自动检测可能会失败,例如当 Traefik pod 以 host network 模式运行时。在这种情况下,你应使用该选项或环境变量提供属性。

基于 MIT 协议发布