5.2. 将 trace 和 metrics 发送到 OpenTelemetry Collector
使用或不进行 sidecar 注入功能,可以将 trace 和 metrics 发送到 OpenTelemetry Collector。
您可以将遥测数据发送到带有 sidecar 注入的 OpenTelemetry Collector 实例。
Red Hat build of OpenTelemetry Operator 允许 sidecar 注入部署工作负载,并自动配置您的检测向 OpenTelemetry Collector 发送遥测数据。
先决条件
- 安装了 Red Hat OpenShift distributed tracing Platform (Tempo),并部署了 TempoStack 实例。
您可以通过 Web 控制台或 OpenShift CLI (
oc)访问集群:-
以集群管理员身份使用
cluster-admin角色登录到 web 控制台。 -
集群管理员具有
cluster-admin角色的活跃 OpenShift CLI (oc) 会话。 -
对于 Red Hat OpenShift Dedicated,您必须有一个具有
dedicated-admin角色的帐户。
-
以集群管理员身份使用
流程
为 OpenTelemetry Collector 实例创建项目。
apiVersion: project.openshift.io/v1 kind: Project metadata: name: observability创建一个服务帐户。
apiVersion: v1 kind: ServiceAccount metadata: name: otel-collector-sidecar namespace: observability为
k8sattributes和resourcedetection处理器的服务帐户授予权限。apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: otel-collector rules: - apiGroups: ["", "config.openshift.io"] resources: ["pods", "namespaces", "infrastructures", "infrastructures/status"] verbs: ["get", "watch", "list"] --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: otel-collector subjects: - kind: ServiceAccount name: otel-collector-sidecar namespace: observability roleRef: kind: ClusterRole name: otel-collector apiGroup: rbac.authorization.k8s.io将 OpenTelemetry Collector 部署为 sidecar。
apiVersion: opentelemetry.io/v1alpha1 kind: OpenTelemetryCollector metadata: name: otel namespace: observability spec: serviceAccount: otel-collector-sidecar mode: sidecar config: | serviceAccount: otel-collector-sidecar receivers: otlp: protocols: grpc: http: processors: batch: memory_limiter: check_interval: 1s limit_percentage: 50 spike_limit_percentage: 30 resourcedetection: detectors: [openshift] timeout: 2s exporters: otlp: endpoint: "tempo-<example>-gateway:8090"1 tls: insecure: true service: pipelines: traces: receivers: [jaeger] processors: [memory_limiter, resourcedetection, batch] exporters: [otlp]- 1
- 这指向使用 Tempo Operator 部署的
<example>TempoStack 实例的网关。
-
使用
otel-collector-sidecar服务帐户创建部署。 -
在您的
Deployment对象中添加sidecar.opentelemetry.io/inject: "true"注解。这将注入所有需要的环境变量,将工作负载中的数据发送到 OpenTelemetry Collector 实例。
您可以在不进行 sidecar 注入的情况下将遥测数据发送到 OpenTelemetry Collector 实例,这涉及手动设置几个环境变量。
先决条件
- 安装了 Red Hat OpenShift distributed tracing Platform (Tempo),并部署了 TempoStack 实例。
您可以通过 Web 控制台或 OpenShift CLI (
oc)访问集群:-
以集群管理员身份使用
cluster-admin角色登录到 web 控制台。 -
集群管理员具有
cluster-admin角色的活跃 OpenShift CLI (oc) 会话。 -
对于 Red Hat OpenShift Dedicated,您必须有一个具有
dedicated-admin角色的帐户。
-
以集群管理员身份使用
流程
为 OpenTelemetry Collector 实例创建项目。
apiVersion: project.openshift.io/v1 kind: Project metadata: name: observability创建一个服务帐户。
apiVersion: v1 kind: ServiceAccount metadata: name: otel-collector-deployment namespace: observability为
k8sattributes和resourcedetection处理器的服务帐户授予权限。apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: otel-collector rules: - apiGroups: ["", "config.openshift.io"] resources: ["pods", "namespaces", "infrastructures", "infrastructures/status"] verbs: ["get", "watch", "list"] --- apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: otel-collector subjects: - kind: ServiceAccount name: otel-collector namespace: observability roleRef: kind: ClusterRole name: otel-collector apiGroup: rbac.authorization.k8s.io使用 OpenTelemetryCollector 自定义资源部署
OpenTelemetry Collector实例。apiVersion: opentelemetry.io/v1alpha1 kind: OpenTelemetryCollector metadata: name: otel namespace: observability 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-<example>-distributor:4317"1 tls: insecure: true service: pipelines: traces: receivers: [jaeger, opencensus, otlp, zipkin] processors: [memory_limiter, k8sattributes, resourcedetection, batch] exporters: [otlp]- 1
- 这指向使用 Tempo Operator 部署的
<example>TempoStack 实例的网关。
使用您的检测应用程序设置容器中的环境变量。
Expand Name 描述 默认值 OTEL_SERVICE_NAME设置
service.name资源属性的值。""OTEL_EXPORTER_OTLP_ENDPOINT带有可选指定端口号的任何信号类型的基本端点 URL。
https://localhost:4317OTEL_EXPORTER_OTLP_CERTIFICATEgRPC 客户端的 TLS 凭证的证书文件的路径。
https://localhost:4317OTEL_TRACES_SAMPLER用于 trace 的 sampler。
parentbased_always_onOTEL_EXPORTER_OTLP_PROTOCOLOTLP 导出器的传输协议。
grpcOTEL_EXPORTER_OTLP_TIMEOUTOTLP 导出器等待每个批处理导出的最大时间间隔。
10sOTEL_EXPORTER_OTLP_INSECURE为 gRPC 请求禁用客户端传输安全性。HTTPS 模式会覆盖它。
False