You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

通过HAProxy转发至Elastic APM Server时OpenTelemetry上报404错误求助

问题分析与解决

核心问题根源

错误提示的HTTP 404本质是请求路径不匹配:

  • 直接连接APM Server时用的是otlp exporter,结合环境变量OTEL_EXPORTER_OTLP_PROTOCOL=http/json,请求会发往Elastic APM Server适配的私有端点(/intake/v2/otel),因此能正常收集Trace。
  • 使用otlphttp exporter时,会发送标准OTLP HTTP路径/v1/traces,而Elastic APM Server 7.12.1不支持这个标准路径——不管是否经过HAProxy,都会返回404。你之前调整的HAProxy Header配置并非问题根源。

解决方案

方案1:改用otlp exporter连接HAProxy(推荐)

保持和正常工作配置一致的exporter类型,仅修改endpoint为HAProxy地址,利用现有环境变量的协议配置适配APM Server:

# /etc/otelcol/config.yaml 修改后
...
exporters:
  otlp:
    endpoint: "http://haproxy-apm-lb:8080"
    tls:
      insecure: true
    headers:
      Content-Type: "application/json"

  logging:
    verbosity: detailed

service:
  pipelines:
    traces:
      receivers: [otlp]
      processors: [batch]
      exporters: [logging,otlp]   
...

方案2:通过HAProxy路径重写适配otlphttp exporter

如果必须使用otlphttp exporter,需要在HAProxy中添加路径重写规则,将标准OTLP路径/v1/traces转换为APM Server支持的端点/intake/v2/otel:

# /etc/haproxy/haproxy.cfg 修改后
...
backend http_main
        mode http
        option httpchk GET /
        http-request add-header Content-Type application/json
        # 添加路径重写规则
        http-request set-path /intake/v2/otel if { path_beg /v1/traces }
        http-check expect status 200
        server elastic-apm-server-001         10.10.10.11:8080 check port 8080
        server elastic-apm-server-002         10.10.10.12:8080 check port 8080
...

修改后可通过curl验证重写是否生效:

curl -X POST http://haproxy-apm-lb:8080/v1/traces -H "Content-Type: application/json" -d '{}'

若返回非404状态码,说明重写配置生效。


补充说明

Elastic APM Server对标准OTLP HTTP端点(/v1/traces)的原生支持是在8.x版本后逐步完善的,7.12.1版本仅兼容otlp exporter的请求格式,或需要通过路径重写适配标准OTLP HTTP请求。

内容的提问来源于stack exchange,提问作者EliotK

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 09:54:56