Traefik Tracing 概览
Tracing
可视化请求流
tracing 系统允许开发人员可视化其基础架构中的调用流。
Traefik 使用 OpenTelemetry,这是为分布式 tracing 设计的开放标准。
配置示例
要启用 tracing:
YAML
yaml
tracing: {}TOML
toml
[tracing]CLI
bash
--tracing=trueHelm Chart Values
yaml
tracing:
otlp:
enabled: true配置选项
| 字段 | 描述 | 默认值 | 必填 |
|---|---|---|---|
tracing.addInternals | 启用内部资源的 tracing。 | false | 否 |
tracing.serviceName | service 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.endpoint | HTTP 端点(格式 <scheme>://<host>:<port><path>)。 | "https://localhost:4318/v1/tracing" | 是 |
tracing.otlp.http.headers | 其它请求头。 | 否 | |
tracing.otlp.http.tls.ca | CA 证书路径。 | "" | 否 |
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.endpoint | gRPC 端点(格式 <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.namek8s.pod.uidk8s.pod.name请注意,这种自动检测可能会失败,例如当 Traefik pod 以 host network 模式运行时。在这种情况下,你应使用该选项或环境变量提供属性。