将追踪、日志和指标发送到 Collector


Red Hat build of OpenTelemetry 3.8

配置应用程序以使用或不使用 sidecar 注入发送遥测数据

Red Hat OpenShift Documentation Team

摘要

本文档论述了如何将应用程序的 trace、日志和指标发送到 OpenTelemetry Collector 或 TempoStack 实例。了解两种部署方法:使用 sidecar 注入进行自动配置,以及不使用 sidecar 的手动配置。包括设置服务帐户、配置 RBAC 权限、在不同模式中部署 Collector 并为遥测数据导出配置环境变量的流程。

您可以设置并使用红帽构建的 OpenTelemetry 将 trace、日志和指标发送到 OpenTelemetry Collector 或 TempoStack 实例。

使用或不进行 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 角色的帐户。

流程

  1. 为 OpenTelemetry Collector 实例创建项目。

    apiVersion: project.openshift.io/v1
    kind: Project
    metadata:
      name: observability
    Copy to Clipboard Toggle word wrap
  2. 创建一个服务帐户。

    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: otel-collector-sidecar
      namespace: observability
    Copy to Clipboard Toggle word wrap
  3. k8sattributesresourcedetection 处理器的服务帐户授予权限。

    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
    Copy to Clipboard Toggle word wrap
  4. 将 OpenTelemetry Collector 部署为 sidecar。

    apiVersion: opentelemetry.io/v1beta1
    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: [otlp]
              processors: [memory_limiter, resourcedetection, batch]
              exporters: [otlp]
    Copy to Clipboard Toggle word wrap
    1
    这指向使用 Tempo Operator 部署的 <example> TempoStack 实例的网关。
  5. 使用 otel-collector-sidecar 服务帐户创建部署。
  6. 在您的 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 角色的帐户。

流程

  1. 为 OpenTelemetry Collector 实例创建项目。

    apiVersion: project.openshift.io/v1
    kind: Project
    metadata:
      name: observability
    Copy to Clipboard Toggle word wrap
  2. 创建一个服务帐户。

    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: otel-collector-deployment
      namespace: observability
    Copy to Clipboard Toggle word wrap
  3. k8sattributesresourcedetection 处理器的服务帐户授予权限。

    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-deployment
      namespace: observability
    roleRef:
      kind: ClusterRole
      name: otel-collector
      apiGroup: rbac.authorization.k8s.io
    Copy to Clipboard Toggle word wrap
  4. 使用 OpenTelemetryCollector 自定义资源部署 OpenTelemetry Collector 实例。

    apiVersion: opentelemetry.io/v1beta1
    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]
    Copy to Clipboard Toggle word wrap
    1
    这指向使用 Tempo Operator 部署的 <example> TempoStack 实例的网关。
  5. 使用您的检测应用程序设置容器中的环境变量。

    Expand
    Name描述默认值

    OTEL_SERVICE_NAME

    设置 service.name 资源属性的值。

    ""

    OTEL_EXPORTER_OTLP_ENDPOINT

    带有可选指定端口号的任何信号类型的基本端点 URL。

    https://localhost:4317

    OTEL_EXPORTER_OTLP_CERTIFICATE

    gRPC 客户端的 TLS 凭证的证书文件的路径。

    https://localhost:4317

    OTEL_TRACES_SAMPLER

    用于 trace 的 sampler。

    parentbased_always_on

    OTEL_EXPORTER_OTLP_PROTOCOL

    OTLP 导出器的传输协议。

    grpc

    OTEL_EXPORTER_OTLP_TIMEOUT

    OTLP 导出器等待每个批处理导出的最大时间间隔。

    10s

    OTEL_EXPORTER_OTLP_INSECURE

    为 gRPC 请求禁用客户端传输安全性。HTTPS 模式会覆盖它。

    False

法律通告

Copyright © 2025 Red Hat, Inc.
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
Java® is a registered trademark of Oracle and/or its affiliates.
XFS® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries.
MySQL® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
Node.js® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.
The OpenStack® Word Mark and OpenStack logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation's permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
All other trademarks are the property of their respective owners.
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2026 Red Hat
返回顶部