10.6. 对工具进行故障排除
要排除工具,请查找以下问题:
- 在工作负载中检测注入的问题
- 检测库生成数据的问题
10.6.1. 对工作负载注入的故障排除
要排除检测注入的问题,您可以执行以下操作:
-
检查是否创建了
Instrumentation
对象 - 检查 init-container 是否已启动
- 检查资源是否以正确顺序部署
- 搜索 Operator 日志中的错误
- 仔细检查 pod 注解
流程
运行以下命令验证
Instrumentation
对象是否已成功创建:$ oc get instrumentation -n <workload_project> 1
- 1
- 创建检测的命名空间。
运行以下命令,以验证
opentelemetry-auto-instrumentation
init-container 是否已成功启动,这是检测注入工作负载的先决条件:$ oc get events -n <workload_project> 1
- 1
- 为工作负载注入检测的命名空间。
输出示例
... Created container opentelemetry-auto-instrumentation ... Started container opentelemetry-auto-instrumentation
验证资源是否已正确部署,以便自动检测正常工作。正确的顺序是在应用程序前部署部署自定义资源(CR)的正确顺序。
有关
Instrumentation
CR 的详情,请参考"配置工具"部分。注意当 pod 启动时,Red Hat build of OpenTelemetry Operator 会检查
Instrumentation
CR 中的注解,其中包含注入自动检测的说明。通常,Operator 会将 init-container 添加到应用程序的 pod 中,该 pod 会将自动检测和环境变量注入应用程序的容器中。如果在部署应用程序时 Operator 无法使用Instrumentation
CR,Operator 无法注入自动检测。修复部署顺序需要以下步骤:
- 更新检测设置。
- 删除检测对象。
- 重新部署应用。
运行以下命令检查 Operator 日志中的检测错误:
$ oc logs -l app.kubernetes.io/name=opentelemetry-operator --container manager -n openshift-opentelemetry-operator --follow
对特定编程语言的检测的 pod 注解进行故障排除。请参阅"配置检测"中的所需的注解字段和值。
验证您要检测的应用程序 pod 是否使用正确的注解标记,并且应用了适当的自动检测设置。
Example
instrumentation.opentelemetry.io/inject-python="true"
获取检测 Python 应用程序的 pod 注解的命令示例
$ oc get pods -n <workload_project> -o jsonpath='{range .items[?(@.metadata.annotations["instrumentation.opentelemetry.io/inject-python"]=="true")]}{.metadata.name}{"\n"}{end}'
- 验证应用于检测对象的注解是否正确,适用于您检测的编程语言。
如果同一命名空间中有多个检测,请在注解中指定
Instrumentation
对象的名称。Example
instrumentation.opentelemetry.io/inject-nodejs: "<instrumentation_object>"
如果
Instrumentation
对象位于不同的命名空间中,请在注解中指定命名空间。Example
instrumentation.opentelemetry.io/inject-nodejs: "<other_namespace>/<instrumentation_object>"
-
验证
OpenTelemetryCollector
自定义资源是否在spec.template.metadata.annotations
下指定 auto-instrumentation 注解。如果 auto-instrumentation 注解位于spec.metadata.annotations
中,请将其移到spec.template.metadata.annotations
中。
10.6.2. 通过检测库生成遥测数据故障排除
您可以通过检查端点、在应用程序日志中查找错误,并验证 Collector 收到遥测数据,从而通过检测库对遥测数据进行故障排除。
流程
验证检测是否将数据传送到正确的端点:
$ oc get instrumentation <instrumentation_name> -n <workload_project> -o jsonpath='{.spec.endpoint}'
Instrumentation
对象的默认端点http://localhost:4317
仅适用于部署为应用程序 pod 中的 sidecar 的 Collector 实例。如果您使用不正确的端点,请通过编辑Instrumentation
对象并重新部署应用程序来纠正该端点。检查应用程序日志中可能表明检测已出现故障的错误消息:
$ oc logs <application_pod> -n <workload_project>
- 如果应用程序日志包含表明检测可能会出现故障的错误消息,请在本地安装 OpenTelemetry SDK 和库。然后,在本地运行应用程序并进行故障排除,以便在没有 OpenShift Container Platform 的情况下检测库和应用程序间的问题。
- 使用 Debug Exporter 验证遥测数据是否到达目的地 OpenTelemetry Collector 实例。如需更多信息,请参阅"Debug Exporter"。