第 5 章 将追踪、日志和指标发送到 OpenTelemetry 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,并部署了 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 实例。
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2025 Red Hat