Collector 配置不对,日志和链路会凭空消失。本文给出 OpenTelemetry Collector 接入炬鲸 OBSERVE 的完整配置,覆盖尾采样、批处理与最常见的三类报错。
直接让每个服务把数据推给平台,简单但脆弱:服务要感知采集端地址,网络抖动会丢数据,采样策略改一次要改所有服务。加一层 OpenTelemetry Collector 做中转,服务只连本机或内网 Collector,由它统一负责采样、批处理、重试和转发,职责更清晰。
receivers:
otlp:
protocols:
grpc:
endpoint: 0.0.0.0:4317
processors:
batch:
send_batch_size: 512
timeout: 5s
memory_limiter:
limit_mib: 512
spike_limit_mib: 128
tail_sampling:
decision_wait: 10s
policies:
- name: errors-and-slow
type: and
and:
and_sub_policy:
- name: keep-errors
type: status_code
status_code: { status_codes: [ERROR] }
- name: keep-slow
type: latency
latency: { threshold_ms: 500 }
exporters:
otlphttp:
endpoint: https://ob.example.com/v1/traces
headers:
Authorization: 'Bearer <token>'
service:
pipelines:
traces:
receivers: [otlp]
processors: [memory_limiter, batch, tail_sampling]
exporters: [otlphttp]
context deadline exceeded:Collector 到平台的网络超时。检查 endpoint 是否可达、是否有代理挡路,先用 curl -v 测一次。401 unauthorized:Token 错误或过期。在控制台重新生成,别把 Token 写进代码仓库。启动 Collector 后,用一个最小 demo 服务发一条 trace,回到控制台按 trace id 检索。能看到完整的调用链、span 属性和耗时,就说明链路通了。生产环境建议至少跑两个 Collector 实例挂在负载均衡后面,服务侧配好故障转移,同时把 Collector 本身也纳入监控——它出问题,等于所有服务的可观测都断了。