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

OpenTelemetry Trace未输出:Ruby测试无控制台错误但Jaeger无数据

Ruby OpenTelemetry 无法在Jaeger中看到Trace数据的排查方案

问题详情

我编写了一段用于测试OpenTelemetry的Ruby代码:

require 'uri'
require 'net/http'
require 'opentelemetry/sdk'
require 'opentelemetry/instrumentation/all'
require 'opentelemetry/exporter/otlp'
require "opentelemetry-api"

OpenTelemetry::SDK.configure do |c|
  c.service_name = 'test'
  c.use_all
end

uri = URI('https://google.ch')
res = Net::HTTP.get_response(uri)
puts res.body

运行代码后输出如下:

I, [2022-12-15T15:57:44.881172 #5506]  INFO -- : Instrumentation: OpenTelemetry::Instrumentation::Net::HTTP was successfully installed with the following options {:untraced_hosts=>[]}
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="https://www.google.ch/">here</A>.
</BODY></HTML>

但在Jaeger中无法看到任何Trace数据。

已设置环境变量:

export OTEL_EXPORTER_OTLP_ENDPOINT=http://0.0.0.0:4318

Jaeger通过以下命令启动:

docker run --name jaeger \
-e COLLECTOR_OTLP_ENABLED=true \
-p 16686:16686 \
-p 4317:4317 \
-p 4318:4318 \
--platform=linux/amd64 \
jaegertracing/all-in-one:1.6

可能的问题点及修复方案

1. 环境变量端点配置错误

0.0.0.0是服务监听地址,不是客户端访问地址。如果Ruby代码和Jaeger在同一台机器,需将端点改为localhost或宿主机实际IP:

export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318

2. 未显式配置OTLP导出器

Ruby OpenTelemetry SDK默认不会自动启用OTLP导出器,需在代码中显式添加配置:

OpenTelemetry::SDK.configure do |c|
  c.service_name = 'test'
  c.use_all
  # 配置批量导出处理器和OTLP导出器
  c.add_span_processor(
    OpenTelemetry::SDK::Trace::Export::BatchSpanProcessor.new(
      OpenTelemetry::Exporter::OTLP::Exporter.new(endpoint: ENV['OTEL_EXPORTER_OTLP_ENDPOINT'])
    )
  )
end

3. Jaeger版本过旧

使用的jaegertracing/all-in-one:1.6版本过于老旧,存在OTLP协议兼容性问题。建议升级到最新稳定版:

docker stop jaeger && docker rm jaeger
docker run --name jaeger \
-e COLLECTOR_OTLP_ENABLED=true \
-p 16686:16686 \
-p 4317:4317 \
-p 4318:4318 \
--platform=linux/amd64 \
jaegertracing/all-in-one:latest

4. 程序退出时未等待导出完成

Ruby程序退出可能导致批量导出器未完成数据发送,需在代码末尾添加显式关闭逻辑:

# 在puts res.body之后添加
OpenTelemetry.tracer_provider.shutdown

5. 网络连通性检查

确认Ruby程序所在环境能访问Jaeger的4318端口,可通过curl测试:

curl http://localhost:4318/v1/traces -v

返回405 Method Not Allowed说明端口可达;若连接超时/拒绝,需检查防火墙或Docker端口映射配置。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.08 05:40:43