第 5 章 使用红帽构建的 OpenTelemetry
您可以设置并使用红帽构建的 OpenTelemetry 将 trace 发送到 OpenTelemetry Collector 或 TempoStack。
5.1. 使用 OpenTelemetry Collector 将 trace 转发到 TempoStack
要将转发追踪配置为 TempoStack,您可以部署和配置 OpenTelemetry Collector。您可以使用指定的处理器、接收器和导出器在部署模式中部署 OpenTelemetry Collector。有关其他模式,请参阅附加资源中的 OpenTelemetry Collector 文档链接。
先决条件
- 已安装红帽构建的 OpenTelemetry Operator。
- 已安装 Tempo Operator。
- 在集群中部署了 TempoStack。
流程
为 OpenTelemetry Collector 创建服务帐户。
ServiceAccount 示例
apiVersion: v1 kind: ServiceAccount metadata: name: otel-collector-deployment
为服务帐户创建集群角色。
ClusterRole 示例
apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: otel-collector rules: 1 2 - apiGroups: ["", "config.openshift.io"] resources: ["pods", "namespaces", "infrastructures", "infrastructures/status"] verbs: ["get", "watch", "list"]
将集群角色绑定到服务帐户。
ClusterRoleBinding 示例
apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: otel-collector subjects: - kind: ServiceAccount name: otel-collector-deployment namespace: otel-collector-example roleRef: kind: ClusterRole name: otel-collector apiGroup: rbac.authorization.k8s.io
创建 YAML 文件以定义
OpenTelemetryCollector
自定义资源(CR)。OpenTelemetryCollector 示例
apiVersion: opentelemetry.io/v1alpha1 kind: OpenTelemetryCollector metadata: name: otel spec: mode: deployment serviceAccount: otel-collector-deployment config: | receivers: jaeger: protocols: grpc: thrift_binary: thrift_compact: thrift_http: opencensus: otlp: protocols: grpc: http: zipkin: processors: batch: k8sattributes: memory_limiter: check_interval: 1s limit_percentage: 50 spike_limit_percentage: 30 resourcedetection: detectors: [openshift] exporters: otlp: endpoint: "tempo-simplest-distributor:4317" 1 tls: insecure: true service: pipelines: traces: receivers: [jaeger, opencensus, otlp, zipkin] 2 processors: [memory_limiter, k8sattributes, resourcedetection, batch] exporters: [otlp]
提示
您可以将 tracegen
部署为测试:
apiVersion: batch/v1 kind: Job metadata: name: tracegen spec: template: spec: containers: - name: tracegen image: ghcr.io/open-telemetry/opentelemetry-collector-contrib/tracegen:latest command: - "./tracegen" args: - -otlp-endpoint=otel-collector:4317 - -otlp-insecure - -duration=30s - -workers=1 restartPolicy: Never backoffLimit: 4