简体   繁体   English

无法将跟踪导出到 Kubernetes 上的 OpenTelemetry 收集器

[英]Unable to export traces to OpenTelemetry Collector on Kubernetes

I am using the opentelemetry-ruby otlp exporter for auto instrumentation: https://github.com/open-telemetry/opentelemetry-ruby/tree/main/exporter/otlp我正在使用 opentelemetry-ruby otlp 导出器进行自动检测: https ://github.com/open-telemetry/opentelemetry-ruby/tree/main/exporter/otlp

The otel collector was installed as a daemonset: https://github.com/open-telemetry/opentelemetry-helm-charts/tree/main/charts/opentelemetry-collector otel 收集器作为守护进程安装: https ://github.com/open-telemetry/opentelemetry-helm-charts/tree/main/charts/opentelemetry-collector

I am trying to get the OpenTelemetry collector to collect traces from the Rails application.我试图让 OpenTelemetry 收集器从 Rails 应用程序收集跟踪。 Both are running in the same cluster, but in different namespaces.两者都在同一个集群中运行,但在不同的命名空间中。

We have enabled auto-instrumentation in the app, but the rails logs are currently showing these errors:我们在应用程序中启用了自动检测,但 Rails 日志当前显示以下错误:

E, [2022-04-05T22:37:47.838197 #6] ERROR -- : OpenTelemetry error: Unable to export 499 spans

I set the following env variables within the app:我在应用程序中设置了以下环境变量:

OTEL_LOG_LEVEL=debug
OTEL_EXPORTER_OTLP_ENDPOINT=http://0.0.0.0:4318

I can't confirm that the application can communicate with the collector pods on this port.我无法确认应用程序可以与此端口上的收集器 pod 通信。 Curling this address from the rails/ruby app returns "Connection Refused".从 rails/ruby 应用程序中卷曲此地址会返回“拒绝连接”。 However I am able to curl http://<OTEL_POD_IP>:4318 which returns 404 page not found.但是我可以 curl http://<OTEL_POD_IP>:4318返回 404 page not found。

From inside a pod:从 pod 内部:

# curl http://localhost:4318/
curl: (7) Failed to connect to localhost port 4318: Connection refused

# curl http://10.1.0.66:4318/
404 page not found

This helm chart created a daemonset but there is no service running.此 helm 图表创建了一个守护程序集,但没有运行任何服务。 Is there some setting I need to enable to get this to work?我需要启用一些设置才能使其正常工作吗?

I confirmed that otel-collector is running on every node in the cluster and the daemonset has HostPort set to 4318.我确认 otel-collector 正在集群中的每个节点上运行,并且守护程序集的 HostPort 设置为 4318。

The problem is with this setting:问题在于这个设置:

OTEL_EXPORTER_OTLP_ENDPOINT=http://0.0.0.0:4318

Imagine your pod as a stripped out host itself.将您的 pod 想象成一个剥离的主机本身。 Localhost or 0.0.0.0 of your pod, and you don't have a collector deployed in your pod.本地主机或您的 pod 的 0.0.0.0,并且您的 pod 中没有部署收集器。

You need to use the address from your collector.您需要使用收藏家的地址。 I've checked the examples available at the shared repo and for agent-and-standalone and standalone-only you also have a k8s resource of type Service.我检查了共享存储库中可用的示例,对于agent-and-standalonestandalone-only的示例,您还拥有服务类型的 k8s 资源。

With that you can use the full service name (with namespace) to configure your environment variable.有了它,您可以使用完整的服务名称(带有命名空间)来配置您的环境变量。
Also, the Environment variable now is called OTEL_EXPORTER_OTLP_TRACES_ENDPOINT , so you will need something like this:此外,环境变量现在被称为OTEL_EXPORTER_OTLP_TRACES_ENDPOINT ,所以你需要这样的东西:

OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=<service-name>.<namespace>.svc.cluster.local:<service-port>

The correct solution is to use the Kubernetes Downward API to fetch the node IP address, which will allow you to export the traces directly to the daemonset pod within the same node:正确的解决方案是使用Kubernetes Downward API获取节点 IP 地址,这将允许您将跟踪直接导出到同一节点内的 daemonset pod:

  containers:
  - name: my-app
    image: my-image
    env:
    - name: HOST_IP
      valueFrom:
        fieldRef:
          fieldPath: status.hostIP
    - name: OTEL_EXPORTER_OTLP_ENDPOINT
      value: http://$(HOST_IP):4318

Note that using the deployment's service as the endpoint ( <service-name>.<namespace>.svc.cluster.local ) is incorrect, as it effectively bypasses the daemonset and sends the traces directly to the deployment, which makes the daemonset useless.请注意,使用部署的服务作为端点( <service-name>.<namespace>.svc.cluster.local )是不正确的,因为它有效地绕过了守护程序集并将跟踪直接发送到部署,这使得守护程序集无用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM