配置 Collector


Red Hat build of OpenTelemetry 3.8

使用接收器、处理器、导出器、连接器和扩展设置遥测数据管道

Red Hat OpenShift Documentation Team

摘要

本文档论述了如何使用自定义资源定义配置 OpenTelemetry Collector。了解将接收器配置为最接近的遥测数据、处理器转换和过滤数据、导出器将数据发送到监控后端、连接器来链接管道,以及添加身份验证等功能的扩展。包括部署模式、配置选项和 RBAC 设置。

第 1 章 配置 Collector

红帽构建的 OpenTelemetry Operator 使用自定义资源定义(CRD)文件来定义创建和部署分布式追踪平台 (Tempo) 资源时要使用的架构和配置设置。您可以安装默认配置或修改该文件。

1.1. 部署模式

OpenTelemetryCollector 自定义资源允许您为 OpenTelemetry Collector 指定以下部署模式之一:

Deployment
默认。
StatefulSet
如果您需要运行有状态工作负载,例如使用 Collector 的 File Storage Extension 或 Tail Sampling Processor 时,请使用 StatefulSet 部署模式。
DaemonSet
如果您需要从每个节点中提取遥测数据,例如使用 Collector 的 Filelog Receiver 来读取容器日志,请使用 DaemonSet 部署模式。
Sidecar

如果您需要访问容器内的日志文件,请将 Collector 注入 sidecar,并使用 Collector 的 Filelog Receiver 和共享卷,如 emptyDir

如果您需要将应用程序配置为通过 localhost 发送遥测数据,请将 Collector 注入 sidecar,并设置 Collector 通过加密和经过身份验证的连接将遥测数据转发到外部服务。当作为 sidecar 注入时,Collector 会与应用程序在同一 pod 中运行。

注意

如果选择 sidecar 部署模式,那么除了在 OpenTelemetryCollector 自定义资源 CR 中设置 spec.mode: sidecar 字段外,还必须将 sidecar.opentelemetry.io/inject 注解设置为 pod 注解或命名空间注解。如果在 pod 和命名空间上设置了此注解,如果 pod 注解被设置为 falseOpenTelemetryCollector CR 名称,则 pod 注解会优先使用。

作为 pod 注解,sidecar.opentelemetry.io/inject 注解支持几个值:

apiVersion: v1
kind: Pod
metadata:
  ...
  annotations:
    sidecar.opentelemetry.io/inject: "<supported_value>" 
1

...
Copy to Clipboard Toggle word wrap
1
支持的值:
false
不注入 Collector。如果缺少注解,这是默认设置。
true
使用同一命名空间中的 OpenTelemetryCollector CR 配置注入 Collector。
<collector_name>
使用同一命名空间中的 <collector_name> OpenTelemetryCollector CR 配置注入 Collector。
<namespace>/<collector_name>
使用 <namespace> 命名空间中的 <collector_name> OpenTelemetryCollector CR 配置注入 Collector。

1.2. OpenTelemetry Collector 配置选项

OpenTelemetry Collector 由访问遥测数据的一组组件组成:

  • Receivers
  • Processors
  • Exporters
  • 连接器
  • 扩展

您可以在自定义资源 YAML 文件中定义多个组件实例。配置后,必须通过 YAML 文件的 spec.config.service 部分中定义的管道启用这些组件。作为最佳实践,仅启用您需要的组件。

OpenTelemetry Collector 自定义资源文件示例

apiVersion: opentelemetry.io/v1beta1
kind: OpenTelemetryCollector
metadata:
  name: cluster-collector
  namespace: tracing-system
spec:
  mode: deployment
  observability:
    metrics:
      enableMetrics: true
  config:
    receivers:
      otlp:
        protocols:
          grpc: {}
          http: {}
    processors: {}
    exporters:
      otlp:
        endpoint: otel-collector-headless.tracing-system.svc:4317
        tls:
          ca_file: "/var/run/secrets/kubernetes.io/serviceaccount/service-ca.crt"
      prometheus:
        endpoint: 0.0.0.0:8889
        resource_to_telemetry_conversion:
          enabled: true # by default resource attributes are dropped
    service: 
1

      pipelines:
        traces:
          receivers: [otlp]
          processors: []
          exporters: [otlp]
        metrics:
          receivers: [otlp]
          processors: []
          exporters: [prometheus]
Copy to Clipboard Toggle word wrap

1
如果一个组件被配置但没有在 service 部分中定义,则组件不会被启用。
Expand
表 1.1. Operator 用来定义 OpenTelemetry Collector 的参数
参数描述default
receivers:
Copy to Clipboard Toggle word wrap

接收器用于控制数据如何进入 Collector。默认情况下,不会配置接收器。必须至少有一个启用的接收器才能使配置被视为有效。接收器通过添加到管道中来启用。

otlp, jaeger, prometheus, zipkin, kafka, opencensus

None

processors:
Copy to Clipboard Toggle word wrap

处理器在导出前会处理接收的数据。默认情况下,不启用处理器。

batch, memory_limiter, resourcedetection, attributes, span, k8sattributes, filter, routing

None

exporters:
Copy to Clipboard Toggle word wrap

导出器将数据发送到一个或多个后端或目的地。默认情况下,不会配置导出器。必须至少启用了一个 exporter 时,配置才被视为有效。将导出器添加到管道中即可启用。导出器可能会与其默认设置一起使用,但很多需要配置至少指定目标和安全设置。

otlp, otlphttp, debug, prometheus, kafka

None

connectors:
Copy to Clipboard Toggle word wrap

连接器通过将数据作为管道导出器来加入管道对,并将数据作为 Start-of-pipeline 接收器发送。连接器可用于总结、复制或路由消耗的数据。

spanmetrics

None

extensions:
Copy to Clipboard Toggle word wrap

不涉及处理遥测数据的任务的可选组件。

bearertokenauth, oauth2client, pprof, health_check, memory_ballast, zpages

None

service:
  pipelines:
Copy to Clipboard Toggle word wrap

组件通过将组件添加到 services.pipeline 下的管道中来启用。

  
service:
  pipelines:
    traces:
      receivers:
Copy to Clipboard Toggle word wrap

您可以通过在 service.pipelines.traces 下添加用于追踪的接收器。

 

service:
  pipelines:
    traces:
      processors:
Copy to Clipboard Toggle word wrap

您可以通过在 service.pipelines.traces 下添加处理器来启用追踪的处理器。

 

service:
  pipelines:
    traces:
      exporters:
Copy to Clipboard Toggle word wrap

您可以通过在 service.pipelines.traces 下添加用于追踪的导出器。

 

None

service:
  pipelines:
    metrics:
      receivers:
Copy to Clipboard Toggle word wrap

您可以通过在 service.pipelines.metrics 下添加指标来启用指标接收器。

 

None

service:
  pipelines:
    metrics:
      processors:
Copy to Clipboard Toggle word wrap

您可以通过在 service.pipelines.metrics 下添加 services.pipelines.metrics 来为 metircs 启用处理器。

 

None

service:
  pipelines:
    metrics:
      exporters:
Copy to Clipboard Toggle word wrap

您可以通过在 service.pipelines.metrics 下添加指标启用导出器。

 

None

1.3. 配置集信号

Profile 信号是一个新兴的遥测数据格式,用于观察代码执行和资源消耗。

重要

Profile 信号只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

Profile 信号允许您将代码低到特定功能。通过这种性能分析,您可以精确识别性能瓶颈,并将资源效率降低到特定的代码行。通过将此类高风险配置集数据与 trace、metrics 和 logs 进行比较,它可以在生产环境中启用全面的性能分析和目标代码优化。

分析可以针对应用程序或操作系统:

  • 使用性能分析来观察应用,帮助开发人员验证代码性能、防止回归和监控资源消耗,如内存和 CPU 使用量,从而识别并改进低效的代码。
  • 使用性能分析观察操作系统可以深入了解基础架构、系统调用、内核操作和 I/O 等待时间,这有助于优化基础架构以提高效率和节约成本。

带有启用的 Profile 信号的 OpenTelemetry Collector 自定义资源

apiVersion: opentelemetry.io/v1beta1
kind: OpenTelemetryCollector
metadata:
name: otel-profiles-collector
  namespace: otel-profile
spec:
 args:
   feature-gates: service.profilesSupport 
1

  config:
    receivers:
      otlp: 
2

        protocols:
          grpc:
           endpoint: '0.0.0.0:4317'
          http:
           endpoint: '0.0.0.0:4318'
    exporters:
       otlp/pyroscope:
           endpoint: "pyroscope.pyroscope-monitoring.svc.cluster.local:4317" 
3

    service:
      pipelines: 
4

         profiles:
           receivers: [otlp]
           exporters: [otlp/pyroscope]
# ...
Copy to Clipboard Toggle word wrap

1
通过设置 feature-gates 字段来启用配置集,如下所示。
2
配置 OTLP Receiver,将 OpenTelemetry Collector 设置为通过 OTLP 接收配置集数据。
3
配置将配置文件导出到的位置,如存储。
4
定义性能分析管道,包括将接收的配置集数据转发到与 OTLP 兼容的性能分析后端,如 Grafana Pyroscope。

1.4. 自动创建所需的 RBAC 资源

有些 Collector 组件需要配置 RBAC 资源。

流程

  • opentelemetry-operator-controller-manage 服务帐户中添加以下权限,以便红帽构建的 OpenTelemetry Operator 可以自动创建它们:

    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRole
    metadata:
      name: generate-processors-rbac
    rules:
    - apiGroups:
      - rbac.authorization.k8s.io
      resources:
      - clusterrolebindings
      - clusterroles
      verbs:
      - create
      - delete
      - get
      - list
      - patch
      - update
      - watch
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRoleBinding
    metadata:
      name: generate-processors-rbac
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: ClusterRole
      name: generate-processors-rbac
    subjects:
    - kind: ServiceAccount
      name: opentelemetry-operator-controller-manager
      namespace: openshift-opentelemetry-operator
    Copy to Clipboard Toggle word wrap

1.5. 目标分配器

目标分配器是 OpenTelemetry Operator 的一个可选组件,它会在部署的 OpenTelemetry Collector 实例间分片提取目标。目标分配器与 Prometheus PodMonitorServiceMonitor 自定义资源 (CR) 集成。启用目标分配器时,OpenTelemetry Operator 会将 http_sd_config 字段添加到连接到目标分配器服务的启用的 prometheus 接收器。

重要

目标分配器只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

带有启用的 Target Allocator 的 OpenTelemetryCollector CR 示例

apiVersion: opentelemetry.io/v1beta1
kind: OpenTelemetryCollector
metadata:
  name: otel
  namespace: observability
spec:
  mode: statefulset 
1

  targetAllocator:
    enabled: true 
2

    serviceAccount: 
3

    prometheusCR:
      enabled: true 
4

      scrapeInterval: 10s
      serviceMonitorSelector: 
5

        name: app1
      podMonitorSelector: 
6

        name: app2
  config:
    receivers:
      prometheus: 
7

        config:
          scrape_configs: []
    processors:
    exporters:
      debug: {}
    service:
      pipelines:
        metrics:
          receivers: [prometheus]
          processors: []
          exporters: [debug]
# ...
Copy to Clipboard Toggle word wrap

1
启用 Target Allocator 时,部署模式必须设置为 statefulset
2
启用目标分配器。默认值为 false
3
Target Allocator 部署的服务帐户名称。服务帐户需要具有 RBAC 才能从集群中获取 ServiceMonitorPodMonitor 自定义资源和其他对象,以便在提取的指标上正确设置标签。默认服务名称为 <collector_name>-targetallocator
4
启用与 Prometheus PodMonitorServiceMonitor 自定义资源集成。
5
Prometheus ServiceMonitor 自定义资源的标签选择器。当留空时,请启用所有服务监视器。
6
Prometheus PodMonitor 自定义资源的标签选择器。留空时,启用所有 pod 监视器。
7
Prometheus 接收器带有 minimal, empty scrape_config: [] 配置选项。

Target Allocator 部署使用 Kubernetes API 从集群中获取相关对象,因此它需要自定义 RBAC 配置。

目标 Allocator 服务帐户的 RBAC 配置

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: otel-targetallocator
rules:
  - apiGroups: [""]
    resources:
      - services
      - pods
      - namespaces
    verbs: ["get", "list", "watch"]
  - apiGroups: ["monitoring.coreos.com"]
    resources:
      - servicemonitors
      - podmonitors
      - scrapeconfigs
      - probes
    verbs: ["get", "list", "watch"]
  - apiGroups: ["discovery.k8s.io"]
    resources:
      - endpointslices
    verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: otel-targetallocator
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: otel-targetallocator
subjects:
  - kind: ServiceAccount
    name: otel-targetallocator 
1

    namespace: observability 
2

# ...
Copy to Clipboard Toggle word wrap

1
Target Allocator 服务帐户的名称。
2
Target Allocator 服务帐户的命名空间。

第 2 章 Receivers

接收器将数据放入 Collector 中。接收器可以基于推送或拉取 (pull)。通常,接收器接受指定格式的数据,将其转换为内部格式,并将其传递给适用管道中定义的处理器和导出器。默认情况下,不会配置接收器。必须配置一个或多个接收器。接收器可以支持一个或多个数据源。

目前,红帽构建的 OpenTelemetry 提供了以下正式发行(GA)和技术预览接收器:

2.1. OTLP Receiver

使用 OpenTelemetry Protocol (OTLP) 的 OTLP Receiver ingests traces, metrics, 和日志。

启用了 OTLP Receiver 的 OpenTelemetry Collector 自定义资源

# ...
  config:
    receivers:
      otlp:
        protocols:
          grpc:
            endpoint: 0.0.0.0:4317 
1

            tls: 
2

              ca_file: ca.pem
              cert_file: cert.pem
              key_file: key.pem
              client_ca_file: client.pem 
3

              reload_interval: 1h 
4

          http:
            endpoint: 0.0.0.0:4318 
5

            tls: {} 
6


    service:
      pipelines:
        traces:
          receivers: [otlp]
        metrics:
          receivers: [otlp]
# ...
Copy to Clipboard Toggle word wrap

1
OTLP gRPC 端点。如果省略,则使用默认的 0.0.0.0:4317
2
服务器端 TLS 配置。定义 TLS 证书的路径。如果省略,则禁用 TLS。
3
服务器验证客户端证书的 TLS 证书的路径。这会将 TLSConfig 中的 ClientCAsClientAuth 的值设置为 RequireAndVerifyClientCert。如需更多信息,请参阅 Golang TLS 软件包的配置
4
指定重新载入证书的时间间隔。如果没有设置值,则证书永远不会重新加载。reload_interval 字段接受包含有效时间单位的字符串,如 nsusmssmh
5
OTLP HTTP 端点。默认值为 0.0.0.0:4318
6
服务器端 TLS 配置。如需更多信息,请参阅 grpc 协议配置部分。

2.2. Jaeger Receiver

Jaeger Receiver ingests trace 使用 Jaeger 格式。

启用了 Jaeger Receiver 的 OpenTelemetry Collector 自定义资源

# ...
  config:
    receivers:
      jaeger:
        protocols:
          grpc:
            endpoint: 0.0.0.0:14250 
1

          thrift_http:
            endpoint: 0.0.0.0:14268 
2

          thrift_compact:
            endpoint: 0.0.0.0:6831 
3

          thrift_binary:
            endpoint: 0.0.0.0:6832 
4

          tls: {} 
5


    service:
      pipelines:
        traces:
          receivers: [jaeger]
# ...
Copy to Clipboard Toggle word wrap

1
Jaeger gRPC 端点。如果省略,则使用默认的 0.0.0.0:14250
2
Jaeger Thrift HTTP 端点。如果省略,则使用默认的 0.0.0.0:14268
3
Jaeger Thrift Compact 端点。如果省略,则使用默认的 0.0.0.0:6831
4
Jaeger Thrift Binary 端点。如果省略,则使用默认的 0.0.0.0:6832
5
服务器端 TLS 配置。详情请查看 OTLP Receiver 配置部分。

2.3. 主机指标接收器

OTLP 格式的 Host Metrics Receiver ingests metrics。

启用了 Host Metrics Receiver 的 OpenTelemetry Collector 自定义资源

apiVersion: v1
kind: ServiceAccount
metadata:
  name: otel-hostfs-daemonset
  namespace: <namespace>
# ...
---
apiVersion: security.openshift.io/v1
kind: SecurityContextConstraints
allowHostDirVolumePlugin: true
allowHostIPC: false
allowHostNetwork: false
allowHostPID: true
allowHostPorts: false
allowPrivilegeEscalation: true
allowPrivilegedContainer: true
allowedCapabilities: null
defaultAddCapabilities:
- SYS_ADMIN
fsGroup:
  type: RunAsAny
groups: []
metadata:
  name: otel-hostmetrics
readOnlyRootFilesystem: true
runAsUser:
  type: RunAsAny
seLinuxContext:
  type: RunAsAny
supplementalGroups:
  type: RunAsAny
users:
- system:serviceaccount:<namespace>:otel-hostfs-daemonset
volumes:
- configMap
- emptyDir
- hostPath
- projected
# ...
---
apiVersion: opentelemetry.io/v1beta1
kind: OpenTelemetryCollector
metadata:
  name: otel
  namespace: <namespace>
spec:
  serviceAccount: otel-hostfs-daemonset
  mode: daemonset
  volumeMounts:
    - mountPath: /hostfs
      name: host
      readOnly: true
  volumes:
    - hostPath:
        path: /
      name: host
  config:
    receivers:
      hostmetrics:
        collection_interval: 10s 
1

        initial_delay: 1s 
2

        root_path: / 
3

        scrapers: 
4

          cpu: {}
          memory: {}
          disk: {}
    service:
      pipelines:
        metrics:
          receivers: [hostmetrics]
# ...
Copy to Clipboard Toggle word wrap

1
设置主机指标集合的时间间隔。如果没有指定,则默认值为 1m
2
为主机指标集合设置初始的时间延迟。如果没有指定,则默认值为 1s
3
配置 root_path,以便 Host Metrics Receive 知道 root 文件系统的位置。如果运行多个 Host Metrics Receiver 实例,需要为每个实例设置相同的 root_path 值。
4
列出启用的 host metrics scraper。可用的 scraper 为 cpu, disk, load, filesystem, memory, network, paging, processes, 和 process

2.4. Kubernetes Objects Receiver

Kubernetes Objects Receiver 拉取或监视要从 Kubernetes API 服务器收集的对象。此接收器主要监视 Kubernetes 事件,但可以收集任何类型的 Kubernetes 对象。此接收器会收集整个集群的遥测数据,因此只需要一个接收器实例就可以收集所有数据。

重要

Kubernetes Objects Receiver 只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

启用了 Kubernetes Objects Receiver 的 OpenTelemetry Collector 自定义资源

apiVersion: v1
kind: ServiceAccount
metadata:
  name: otel-k8sobj
  namespace: <namespace>
# ...
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: otel-k8sobj
  namespace: <namespace>
rules:
- apiGroups:
  - ""
  resources:
  - events
  - pods
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - "events.k8s.io"
  resources:
  - events
  verbs:
  - watch
  - list
# ...
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: otel-k8sobj
subjects:
  - kind: ServiceAccount
    name: otel-k8sobj
    namespace: <namespace>
roleRef:
  kind: ClusterRole
  name: otel-k8sobj
  apiGroup: rbac.authorization.k8s.io
# ...
---
apiVersion: opentelemetry.io/v1beta1
kind: OpenTelemetryCollector
metadata:
  name: otel-k8s-obj
  namespace: <namespace>
spec:
  serviceAccount: otel-k8sobj
  mode: deployment
  config:
    receivers:
      k8sobjects:
        auth_type: serviceAccount
        objects:
          - name: pods 
1

            mode: pull 
2

            interval: 30s 
3

            label_selector: 
4

            field_selector: 
5

            namespaces: [<namespace>,...] 
6

          - name: events
            mode: watch
    exporters:
      debug:
    service:
      pipelines:
        logs:
          receivers: [k8sobjects]
          exporters: [debug]
# ...
Copy to Clipboard Toggle word wrap

1
此接收器的资源名称:例如 pods, deployments, 或 events.
2
此接收器使用的观察模式:pullwatch
3
仅适用于 pull 模式。拉取对象的请求间隔。如果没有指定,则默认值为 1h
4
定义目标的标签选择器。
5
用于过滤目标的字段选择器。
6
要从中收集事件的命名空间列表。如果没有指定,则默认值为 all

2.5. kubelet Stats Receiver

Kubelet Stats Receiver 从 kubelet 的 API 服务器中提取与节点、Pod、容器和卷相关的指标。然后,这些指标通过 metrics-processing 管道进行额外的分析。

启用了 Kubelet Stats Receiver 的 OpenTelemetry Collector 自定义资源

# ...
  config:
    receivers:
      kubeletstats:
        collection_interval: 20s
        auth_type: "serviceAccount"
        endpoint: "https://${env:K8S_NODE_NAME}:10250"
        insecure_skip_verify: true
    service:
      pipelines:
        metrics:
          receivers: [kubeletstats]
  env:
    - name: K8S_NODE_NAME 
1

      valueFrom:
        fieldRef:
          fieldPath: spec.nodeName
# ...
Copy to Clipboard Toggle word wrap

1
设置 K8S_NODE_NAME 以向 API 进行身份验证。

对于用于运行 OpenTelemetry Collector 的服务帐户,Kubelet Stats Receiver 需要额外权限。

服务帐户所需的权限

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: otel-collector
rules:
  - apiGroups: ['']
    resources: ['nodes/stats']
    verbs: ['get', 'watch', 'list']
  - apiGroups: [""]
    resources: ["nodes/proxy"] 
1

    verbs: ["get"]
# ...
Copy to Clipboard Toggle word wrap

1
使用 extra_metadata_labelsrequest_utilizationlimit_utilization 指标时所需的权限。

2.6. Prometheus Receiver

Prometheus Receiver 提取指标端点。

启用了 Prometheus Receiver 的 OpenTelemetry Collector 自定义资源

# ...
  config:
    receivers:
        prometheus:
          config:
            scrape_configs: 
1

              - job_name: 'my-app'  
2

                scrape_interval: 5s 
3

                static_configs:
                  - targets: ['my-app.example.svc.cluster.local:8888'] 
4

    service:
      pipelines:
        metrics:
          receivers: [prometheus]
# ...
Copy to Clipboard Toggle word wrap

1
使用 Prometheus 格式提取配置。
2
Prometheus 作业名称。
3
提取指标数据的时间间隔。接受时间单位。默认值为 1m
4
公开指标的目标。本例从 example 项目中的 my-app 应用程序中提取指标。

2.7. OTLP JSON File Receiver

OTLP JSON 文件 Receiver 从包含 ProtoJSON 格式的数据的文件中提取管道信息,并符合 OpenTelemetry 协议规格。接收器会监视指定的目录,以了解创建或修改的文件要处理的更改。

重要

OTLP JSON 文件接收器只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

OpenTelemetry Collector 自定义资源带有启用的 OTLP JSON File Receiver

# ...
  config:
    otlpjsonfile:
      include:
        - "/var/log/*.log" 
1

      exclude:
        - "/var/log/test.log" 
2

# ...
Copy to Clipboard Toggle word wrap

1
要监视的文件路径 glob 模式列表。
2
要忽略的文件路径 glob 模式列表。

2.8. Zipkin Receiver

Zipkin Receiver ingests traces 使用 Zipkin v1 和 v2 格式。

启用了 Zipkin Receiver 的 OpenTelemetry Collector 自定义资源

# ...
  config:
    receivers:
      zipkin:
        endpoint: 0.0.0.0:9411 
1

        tls: {} 
2

    service:
      pipelines:
        traces:
          receivers: [zipkin]
# ...
Copy to Clipboard Toggle word wrap

1
Zipkin HTTP 端点。如果省略,则使用默认的 0.0.0.0:9411
2
服务器端 TLS 配置。详情请查看 OTLP Receiver 配置部分。

2.9. Kafka Receiver

Kafka 接收器以 OTLP 格式接收 Kafka 中的 trace、metrics 和日志。

重要

Kafka Receiver 只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

启用了 Kafka Receiver 的 OpenTelemetry Collector 自定义资源

# ...
  config:
    receivers:
      kafka:
        brokers: ["localhost:9092"] 
1

        protocol_version: 2.0.0 
2

        topic: otlp_spans 
3

        auth:
          plain_text: 
4

            username: example
            password: example
          tls: 
5

            ca_file: ca.pem
            cert_file: cert.pem
            key_file: key.pem
            insecure: false 
6

            server_name_override: kafka.example.corp 
7

    service:
      pipelines:
        traces:
          receivers: [kafka]
# ...
Copy to Clipboard Toggle word wrap

1
Kafka 代理列表。默认值为 localhost:9092
2
Kafka 协议版本。例如,2.0.0。这个为必填字段。
3
要从中读取的 Kafka 主题的名称。默认值为 otlp_spans
4
纯文本形式的身份验证配置。如果省略,则禁用纯文本形式的身份验证。
5
客户端 TLS 配置。定义 TLS 证书的路径。如果省略,则禁用 TLS 身份验证。
6
禁用验证服务器的证书链和主机名。默认值为 false
7
ServerName 表示客户端请求的服务器名称,以支持虚拟主机。

2.10. Kubernetes Cluster Receiver

Kubernetes Cluster Receiver 从 Kubernetes API 服务器收集集群指标和实体事件。它使用 Kubernetes API 接收有关更新的信息。对此接收器的身份验证只支持使用服务账户。

重要

Kubernetes Cluster Receiver 只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

启用了 Kubernetes Cluster Receiver 的 OpenTelemetry Collector 自定义资源

# ...
  config:
    receivers:
      k8s_cluster:
        distribution: openshift
        collection_interval: 10s
    exporters:
      debug: {}
    service:
      pipelines:
        metrics:
          receivers: [k8s_cluster]
          exporters: [debug]
        logs/entity_events:
          receivers: [k8s_cluster]
          exporters: [debug]
# ...
Copy to Clipboard Toggle word wrap

此接收器需要配置服务帐户、集群角色的 RBAC 规则,以及将 RBAC 与服务帐户绑定的集群角色绑定。

ServiceAccount 对象

apiVersion: v1
kind: ServiceAccount
metadata:
  labels:
    app: otelcontribcol
  name: otelcontribcol
# ...
Copy to Clipboard Toggle word wrap

ClusterRole 对象的 RBAC 规则

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: otelcontribcol
  labels:
    app: otelcontribcol
rules:
- apiGroups:
  - quota.openshift.io
  resources:
  - clusterresourcequotas
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - ""
  resources:
  - events
  - namespaces
  - namespaces/status
  - nodes
  - nodes/spec
  - pods
  - pods/status
  - replicationcontrollers
  - replicationcontrollers/status
  - resourcequotas
  - services
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - apps
  resources:
  - daemonsets
  - deployments
  - replicasets
  - statefulsets
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - extensions
  resources:
  - daemonsets
  - deployments
  - replicasets
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - batch
  resources:
  - jobs
  - cronjobs
  verbs:
  - get
  - list
  - watch
- apiGroups:
    - autoscaling
  resources:
    - horizontalpodautoscalers
  verbs:
    - get
    - list
    - watch
# ...
Copy to Clipboard Toggle word wrap

ClusterRoleBinding 对象

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: otelcontribcol
  labels:
    app: otelcontribcol
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: otelcontribcol
subjects:
- kind: ServiceAccount
  name: otelcontribcol
  namespace: default
# ...
Copy to Clipboard Toggle word wrap

2.11. OpenCensus Receiver

OpenCensus Receiver 与 OpenCensus 项目向后兼容性,以便更轻松地迁移检测代码库。它以 OpenCensus 格式通过 gRPC 或 HTTP 和 JSON 接收指标和追踪。

警告

OpenCensus Receiver 已被弃用,可能在以后的版本中删除。

启用了 OpenCensus Receiver 的 OpenTelemetry Collector 自定义资源

# ...
  config:
    receivers:
      opencensus:
        endpoint: 0.0.0.0:9411 
1

        tls: 
2

        cors_allowed_origins: 
3

          - https://*.<example>.com
    service:
      pipelines:
        traces:
          receivers: [opencensus]
# ...
Copy to Clipboard Toggle word wrap

1
OpenCensus 端点。如果省略,则默认为 0.0.0.0:55678
2
服务器端 TLS 配置。详情请查看 OTLP Receiver 配置部分。
3
您还可以使用 HTTP JSON 端点选择性地配置 CORS,这通过在此字段中指定允许的 CORS 来源列表来启用。cors_allowed_origins 下接受带有 * 的通配符。要匹配任何源,请只输入 *

2.12. Filelog Receiver

Filelog Receiver tail 并解析来自文件的日志。

重要

Filelog Receiver 只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

带有启用的 Filelog Receiver 的 OpenTelemetry Collector 自定义资源,它 tails 一个文本文件

# ...
  config:
    receivers:
      filelog:
        include: [ /simple.log ] 
1

        operators: 
2

          - type: regex_parser
            regex: '^(?P<time>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) (?P<sev>[A-Z]*) (?P<msg>.*)$'
            timestamp:
              parse_from: attributes.time
              layout: '%Y-%m-%d %H:%M:%S'
            severity:
              parse_from: attributes.sev
# ...
Copy to Clipboard Toggle word wrap

1
与要读取的文件路径匹配的文件 glob 模式列表。
2
一个 operator 数组。每个 Operator 执行一个简单的任务,如解析时间戳或 JSON。要处理日志成为所需的格式,请将 Operator 串联在一起。

您可以通过以下两种方式之一从 pod 文件系统收集日志:

  • 在与应用程序 pod 一起运行的 sidecar 容器中配置接收器。
  • 将接收器部署为主机上具有适当权限访问 Kubernetes 日志的 DaemonSet。

要从应用程序容器收集日志,您可以使用带有 sidecar 注入的接收器。红帽构建的 OpenTelemetry Operator 允许将 OpenTelemetry Collector 作为 sidecar 容器注入应用程序 pod。当应用程序将日志写入容器文件系统中的文件时,这种方法很有用。然后,此接收器可以跟踪日志文件并应用操作器来解析日志。

要在 sidecar 模式中使用此接收器从应用程序容器收集日志,您必须在 OpenTelemetryCollector 自定义资源中配置卷挂载。应用程序容器和 sidecar Collector 必须挂载相同的共享卷,如 emptyDir。在应用的 Pod 规格中定义卷。请参见以下示例:

OpenTelemetry Collector 自定义资源使用在 sidecar 模式中配置的 Filelog Receiver

apiVersion: opentelemetry.io/v1beta1
kind: OpenTelemetryCollector
metadata:
  name: filelog
  namespace: otel-logging
spec:
  mode: sidecar
  volumeMounts: 
1

  - name: logs
    mountPath: /var/log/app
  config:
    receivers:
      filelog:
        include: 
2

        - /var/log/app/*.log
        operators:
        - type: regex_parser
          regex: '^(?P<timestamp>\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}) \[(?P<level>\w+)\] (?P<message>.*)$'
          timestamp:
            parse_from: attributes.timestamp
            layout: '%Y-%m-%d %H:%M:%S'
    processors: {}
    exporters:
      debug:
        verbosity: detailed
    service:
      pipelines:
        logs:
          receivers: [filelog]
          processors: []
          exporters: [debug]
Copy to Clipboard Toggle word wrap

1
定义 sidecar Collector 用于访问目标日志文件的卷挂载。此卷必须与应用部署中定义的卷名称匹配。
2
指定用于匹配要尾部日志文件的文件通配模式。此接收器会监视这些路径是否有新日志条目。

2.13. Journald Receiver

Journald Receiver 解析来自 systemd journal 的 journald 事件,并将它们作为日志发送。

重要

Journald Receiver 只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

启用了 Journald Receiver 的 OpenTelemetry Collector 自定义资源

apiVersion: v1
kind: Namespace
metadata:
  name: otel-journald
  labels:
    security.openshift.io/scc.podSecurityLabelSync: "false"
    pod-security.kubernetes.io/enforce: "privileged"
    pod-security.kubernetes.io/audit: "privileged"
    pod-security.kubernetes.io/warn: "privileged"
# ...
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: privileged-sa
  namespace: otel-journald
# ...
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: otel-journald-binding
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: system:openshift:scc:privileged
subjects:
- kind: ServiceAccount
  name: privileged-sa
  namespace: otel-journald
# ...
---
apiVersion: opentelemetry.io/v1beta1
kind: OpenTelemetryCollector
metadata:
  name: otel-journald-logs
  namespace: otel-journald
spec:
  mode: daemonset
  serviceAccount: privileged-sa
  securityContext:
    allowPrivilegeEscalation: false
    capabilities:
      drop:
      - CHOWN
      - DAC_OVERRIDE
      - FOWNER
      - FSETID
      - KILL
      - NET_BIND_SERVICE
      - SETGID
      - SETPCAP
      - SETUID
    readOnlyRootFilesystem: true
    seLinuxOptions:
      type: spc_t
    seccompProfile:
      type: RuntimeDefault
  config:
    receivers:
      journald:
        files: /var/log/journal/*/*
        priority: info 
1

        units: 
2

          - kubelet
          - crio
          - init.scope
          - dnsmasq
        all: true 
3

        retry_on_failure:
          enabled: true 
4

          initial_interval: 1s 
5

          max_interval: 30s 
6

          max_elapsed_time: 5m 
7

    processors:
    exporters:
      debug: {}
    service:
      pipelines:
        logs:
          receivers: [journald]
          exporters: [debug]
  volumeMounts:
  - name: journal-logs
    mountPath: /var/log/journal/
    readOnly: true
  volumes:
  - name: journal-logs
    hostPath:
      path: /var/log/journal
  tolerations:
  - key: node-role.kubernetes.io/master
    operator: Exists
    effect: NoSchedule
# ...
Copy to Clipboard Toggle word wrap

1
按消息优先级或优先级范围过滤输出。默认值为 info
2
列出要从中读取条目的单元。如果为空,则从所有单元读取条目。
3
包含非常长的日志,以及带有不可打印字符的日志。默认值为 false
4
如果设置为 true,则接收器会暂停读取文件,并在遇到下游组件错误时尝试重新发送当前的批处理日志。默认值为 false
5
在第一次失败后进行重现尝试需要等待的时间间隔。默认值为 1s。单位是 mssmh
6
重试 backoff 间隔的上限。当达到这个值时,连续重试尝试之间的时间间隔会恒定保持这个值。默认值为 30s。支持的单位是 mssmh
7
尝试将日志批处理发送到下游消费者的最大时间间隔,包括重试尝试。达到这个值时,数据将被丢弃。如果设置的值是 0,重试永远不会停止。默认值为 5m。支持的单位是 mssmh

2.14. Kubernetes Events Receiver

Kubernetes Events Receiver 从 Kubernetes API 服务器收集事件。收集的事件被转换为日志。

重要

Kubernetes Events Receiver 只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

Kubernetes Events Receiver 所需的 OpenShift Container Platform 权限

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: otel-collector
  labels:
    app: otel-collector
rules:
- apiGroups:
  - ""
  resources:
  - events
  - namespaces
  - namespaces/status
  - nodes
  - nodes/spec
  - pods
  - pods/status
  - replicationcontrollers
  - replicationcontrollers/status
  - resourcequotas
  - services
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - apps
  resources:
  - daemonsets
  - deployments
  - replicasets
  - statefulsets
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - extensions
  resources:
  - daemonsets
  - deployments
  - replicasets
  verbs:
  - get
  - list
  - watch
- apiGroups:
  - batch
  resources:
  - jobs
  - cronjobs
  verbs:
  - get
  - list
  - watch
- apiGroups:
    - autoscaling
  resources:
    - horizontalpodautoscalers
  verbs:
    - get
    - list
    - watch
# ...
Copy to Clipboard Toggle word wrap

启用了 Kubernetes Event Receiver 的 OpenTelemetry Collector 自定义资源

# ...
  serviceAccount: otel-collector 
1

  config:
    receivers:
      k8s_events:
        namespaces: [project1, project2] 
2

    service:
      pipelines:
        logs:
          receivers: [k8s_events]
# ...
Copy to Clipboard Toggle word wrap

1
具有所需 ClusterRole otel-collector RBAC 的 Collector 的服务帐户。
2
要从中收集事件的命名空间列表。默认值为空,这意味着收集所有命名空间。

2.15. Prometheus Remote Write Receiver

Prometheus Remote Write Receiver 使用 Remote Write 协议从 Prometheus 接收指标,并将其转换为 OpenTelemetry 格式。此接收器只支持 Prometheus Remote Write v2 协议。

重要

Prometheus Remote Write Receiver 只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

OpenTelemetry Collector 自定义资源带有启用的 Prometheus Remote Write Receiver

# ...
  config:
    receivers:
      prometheusremotewrite:
        endpoint: 0.0.0.0:9090 
1

    # ...
    service:
      pipelines:
        metrics:
          receivers: [prometheusremotewrite]
# ...
Copy to Clipboard Toggle word wrap

1
接收器侦听 Prometheus Remote Write 请求的端点。

以下是将此接收器与 Prometheus 搭配使用的先决条件:

  • Prometheus 在启用了元数据 WAL 记录功能标记的情况下启动。
  • Prometheus Remote Write v2 协议在 Prometheus 远程写入配置中被启用。
  • 使用功能标记在 Prometheus 中启用了原生直方图。
  • Prometheus 被配置为将经典直方图转换为原生直方图。

有关启用这些 Prometheus 功能的更多信息,请参阅 Prometheus 文档。

第 3 章 Processors

处理器处理接收和导出的数据。处理器是可选的。默认情况下,不启用处理器。每个数据源都必须启用处理器。不是所有处理器都支持所有数据源。根据数据源,可能会启用多个处理器。请注意,处理器的顺序很重要。

目前,红帽构建的 OpenTelemetry 提供了以下正式发行(GA)和技术预览处理器:

3.1. Batch Processor

Batch Processor 会批处理跟踪和指标,以减少传输遥测信息所需的传出连接数量。

使用 Batch Processor 时 OpenTelemetry Collector 自定义资源示例

# ...
  config:
    processors:
      batch:
        timeout: 5s
        send_batch_max_size: 10000
    service:
      pipelines:
        traces:
          processors: [batch]
        metrics:
          processors: [batch]
# ...
Copy to Clipboard Toggle word wrap

Expand
表 3.1. Batch Processor 使用的参数
参数描述default

timeout

将批处理发送到特定的持续时间,无论批处理大小如何。

200ms

send_batch_size

在指定数量的 span 或 metrics 后发送遥测数据的批处理。

8192

send_batch_max_size

批处理的最大允许大小。必须等于或大于 send_batch_size

0

metadata_keys

激活后,会为在 client.Metadata 中找到的每个唯一值集创建一个批处理器实例。

[]

metadata_cardinality_limit

在填充 metadata_keys 时,此配置限制了在进程期间处理的不同元数据键值组合的数量。

1000

3.2. Memory Limiter Processor

Memory Limiter Processor 定期检查 Collector 的内存用量,并在达到软内存限制时暂停数据处理。这个处理器支持 trace、metrics 和 logs。前面的组件(通常是接收器)应该重试发送同一数据,并可能对传入的数据应用回溯。当内存用量超过硬限制时,Memory Limiter Processor 会强制运行垃圾回收操作。

使用 Memory Limiter Processor 时 OpenTelemetry Collector 自定义资源示例

# ...
  config:
    processors:
      memory_limiter:
        check_interval: 1s
        limit_mib: 4000
        spike_limit_mib: 800
    service:
      pipelines:
        traces:
          processors: [batch]
        metrics:
          processors: [batch]
# ...
Copy to Clipboard Toggle word wrap

Expand
表 3.2. Memory Limiter Processor 使用的参数
参数描述default

check_interval

内存用量测量之间的时间。最佳值为 1s。对于 spiky 流量模式,您可以减少 check_interval 或增加 spike_limit_mib

0s

limit_mib

硬限制,即堆上分配的最大内存量(以 MiB 为单位)。通常,OpenTelemetry Collector 的内存用量大约比这个值高 50 MiB。

0

spike_limit_mib

spike 限制,这是 MiB 中内存使用率最大激增。最佳值为 limit_mib 的 20%。要计算软限制,请从 limit_mib 中减去 spike_limit_mib

limit_mib 的 20%

limit_percentage

limit_mib 相同,但以总可用内存的百分比表示。limit_mib 设置优先于此设置。

0

spike_limit_percentage

spike_limit_mib 相同,但以总可用内存的百分比表示。旨在与 limit_percentage 设置一起使用。

0

3.3. Resource Detection Processor

Resource Detection Processor 识别主机资源详情与 OpenTelemetry 的资源语义标准保持一致。使用检测到的信息,此处理器可以在遥测数据中添加或替换资源值。这个处理器支持 trace 和 metrics。您可以将这个处理器与多个检测器一起使用,如 Docket 元数据检测器或 OTEL_RESOURCE_ATTRIBUTES 环境变量检测器。

重要

Resource Detection Processor 只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

Resource Detection Processor 所需的 OpenShift Container Platform 权限

kind: ClusterRole
metadata:
  name: otel-collector
rules:
- apiGroups: ["config.openshift.io"]
  resources: ["infrastructures", "infrastructures/status"]
  verbs: ["get", "watch", "list"]
# ...
Copy to Clipboard Toggle word wrap

使用 Resource Detection Processor 的 OpenTelemetry Collector

# ...
  config:
    processors:
      resourcedetection:
        detectors: [openshift]
        override: true
    service:
      pipelines:
        traces:
          processors: [resourcedetection]
        metrics:
          processors: [resourcedetection]
# ...
Copy to Clipboard Toggle word wrap

OpenTelemetry Collector 使用带有环境变量检测器的资源检测器

# ...
  config:
    processors:
      resourcedetection/env:
        detectors: [env] 
1

        timeout: 2s
        override: false
# ...
Copy to Clipboard Toggle word wrap

1
指定要使用的检测器。在本例中,指定了环境检测器。

3.4. Attributes Processor

Attributes Processor 可以修改 span, log, 或 metric 的属性。您可以配置此处理器来过滤和匹配输入数据,并为特定操作包含或排除此类数据。

处理器对操作列表进行操作,按配置中指定的顺序执行它们。支持以下操作:

insert
当指定的键尚不存在时,将新属性插入到输入数据中。
Update(更新)
如果密钥已存在,更新输入数据中的属性。
Upsert
合并 insert 和 update 操作:如果键尚不存在,则插入新属性。如果密钥已存在,则更新 属性。
删除
从输入数据中删除属性。
Hash
将现有属性值哈希为 SHA1。
extract
通过使用输入键的正则表达式规则将值提取到规则中定义的目标键。如果目标键已存在,它将被像使用现有属性作为源的 Span 处理器 to_attributes 设置一样覆盖。
Convert
将现有属性转换为指定类型。

OpenTelemetry Collector 使用 ttributes Processor

# ...
  config:
    processors:
      attributes/example:
        actions:
          - key: db.table
            action: delete
          - key: redacted_span
            value: true
            action: upsert
          - key: copy_key
            from_attribute: key_original
            action: update
          - key: account_id
            value: 2245
            action: insert
          - key: account_password
            action: delete
          - key: account_email
            action: hash
          - key: http.status_code
            action: convert
            converted_type: int
# ...
Copy to Clipboard Toggle word wrap

3.5. Resource Processor

Resource Processor 应用对资源属性的更改。这个处理器支持 trace、metrics 和 logs。

使用 Resource Processor 的 OpenTelemetry 收集器

# ...
  config:
    processors:
      attributes:
      - key: cloud.availability_zone
        value: "zone-1"
        action: upsert
      - key: k8s.cluster.name
        from_attribute: k8s-cluster
        action: insert
      - key: redundant-attribute
        action: delete
# ...
Copy to Clipboard Toggle word wrap

属性代表应用到资源属性的操作,如删除属性、插入属性或 upsert 属性。

3.6. Span Processor

Span Processor 根据其属性修改 span 名称,或者从 span 名称中提取 span 属性。此处理器也可以更改 span 状态,并包含或排除 span。这个处理器支持 trace。

span rename 需要使用 from_attributes 配置为新名称指定属性。

重要

Span Processor 只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

OpenTelemetry Collector 使用 Span Processor 重命名 span

# ...
  config:
    processors:
      span:
        name:
          from_attributes: [<key1>, <key2>, ...] 
1

          separator: <value> 
2

# ...
Copy to Clipboard Toggle word wrap

1
定义组成新 span 名称的密钥。
2
可选分隔符。

您可以使用处理器从 span 名称中提取属性。

OpenTelemetry Collector 使用 Span Processor 从范围名称中提取属性

# ...
  config:
    processors:
      span/to_attributes:
        name:
          to_attributes:
            rules:
              - ^\/api\/v1\/document\/(?P<documentId>.*)\/update$ 
1

# ...
Copy to Clipboard Toggle word wrap

1
此规则定义如何执行提取。您可以定义更多规则:例如,如果正则表达式与名称匹配,则会创建一个 documentID 属性。在本例中,如果输入 span 名称是 /api/v1/document/12345678/update,则会产生 /api/v1/document/{documentId}/update 输出 span 名称,并且新的 "documentId"="12345678" 属性被添加到 span 中。

您可以修改 span 状态。

OpenTelemetry Collector 使用 Span Processor 进行状态更改

# ...
  config:
    processors:
      span/set_status:
        status:
          code: Error
          description: "<error_description>"
# ...
Copy to Clipboard Toggle word wrap

3.7. Kubernetes Attributes Processor

Kubernetes Attributes Processor 使用 Kubernetes 元数据启用 span、metrics 和 log 资源属性的自动配置。这个处理器支持 trace、metrics 和 logs。此处理器自动识别 Kubernetes 资源,从它们中提取元数据,并将此提取的元数据作为资源属性合并到相关的 span、metrics 和 logs 中。它使用 Kubernetes API 来发现在集群内运行的所有 pod,维护其 IP 地址、pod UID 和其他相关元数据的记录。

Kubernetes Attributes Processor 所需的最小 OpenShift Container Platform 权限

kind: ClusterRole
metadata:
  name: otel-collector
rules:
  - apiGroups: ['']
    resources: ['pods', 'namespaces']
    verbs: ['get', 'watch', 'list']
  - apiGroups: ['apps']
    resources: ['replicasets']
    verbs: ['get', 'watch', 'list']
# ...
Copy to Clipboard Toggle word wrap

OpenTelemetry Collector 使用 Kubernetes Attributes Processor

# ...
  config:
    processors:
         k8sattributes:
             filter:
                 node_from_env_var: KUBE_NODE_NAME
# ...
Copy to Clipboard Toggle word wrap

3.8. Filter Processor

Filter Processor 利用 OpenTelemetry Transformation Language 来建立丢弃遥测数据的条件。如果满足这些条件,遥测数据将被丢弃。您可以使用逻辑 OR 运算符对多个条件进行组合。这个处理器支持 trace、metrics 和 logs。

重要

Filter Processor 只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

OpenTelemetry Collector 自定义资源带有启用的 Filter Processor

# ...
  config:
    processors:
      filter/ottl:
        error_mode: ignore 
1

        traces:
          span:
          - 'attributes["container.name"] == "app_container_1"' 
2

          - 'resource.attributes["host.name"] == "localhost"' 
3

# ...
Copy to Clipboard Toggle word wrap

1
定义错误模式。当设置为 ignore 时,请忽略条件返回的错误。当设置为 propagate 时,会返回管道错误。错误会导致有效负载从 Collector 丢弃。
2
过滤具有 container.name == app_container_1 属性的 span。
3
过滤具有 host.name == localhost 资源属性的 span。

3.9. Cumulative-to-Delta Processor

Cumulative-to-Delta Processor 将 monotonic、cumulative-sum 和 histogram 指标转换为 monotonic delta 指标。

您可以使用 include:exclude: 字段过滤指标,并指定 strictregexp 进行名称匹配。

由于此处理器通过存储指标先前的值来计算 delta,所以您必须设置指标源,以将指标数据发送到单个有状态收集器实例,而不是部署多个 Collector。

这个处理器不会转换非单调和以及指数直方图。

重要

Cumulative-to-Delta Processor 只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

带有启用了 Cumulative-to-Delta Processor 的 OpenTelemetry Collector 自定义资源示例

# ...
mode: sidecar 
1

config:
  processors:
    cumulativetodelta:
      include: 
2

        match_type: strict 
3

        metrics: 
4

        - <metric_1_name>
        - <metric_2_name>
      exclude: 
5

        match_type: regexp
        metrics:
        - "<regular_expression_for_metric_names>"
# ...
Copy to Clipboard Toggle word wrap

1
要将 Collector 的生命周期绑定到指标源,您可以将 Collector 作为 sidecar 运行,来向发送累积时序指标的应用程序运行。
2
可选:您可以通过在此片段中明确定义您要转换的指标来限制处理器转换的指标数据。如果省略此字段,处理器会转换所有指标,但 exclude 字段中列出的指标除外。
3
定义 metrics 字段提供的值(使用 strict 参数作为一个完全准确匹配;使用 regex 参数作为一个正则表达式)。
4
列出您要转换的指标的名称。处理器对正则表达式进行完全准确匹配或一般匹配。如果指标与 includeexclude 过滤都匹配,则 exclude 过滤具有更高的优先权。
5
可选:您可以通过在此处明确定义,从转换中排除某些指标。

3.10. Group-by-Attributes Processor

Group-by-Attributes Processor 组所有 span、logging 记录和指标数据点,通过将其重新分配给与这些属性匹配的资源。

重要

Group-by-Attributes Processor 只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

至少配置此处理器涉及指定要将 span、日志记录或指标数据点分组在一起的属性键数组,如下例所示:

使用 Group-by-Attributes Processor 时 OpenTelemetry Collector 自定义资源的示例

# ...
  config:
    processors:
      groupbyattrs:
        keys: 
1

          - <key1> 
2

          - <key2>
# ...
Copy to Clipboard Toggle word wrap

1
指定要分组的属性键。
2
如果处理的范围、日志记录或指标数据点至少包含指定的属性键,则会将其重新分配给共享相同属性值的资源;如果没有这样的资源,则会创建一个新资源。如果处理的范围、日志记录或指标数据点中没有指定的属性键,则它与其当前资源关联。整合同一资源的多个实例。

3.11. Transform Processor

Transform Processor 启用根据指定的规则修改遥测数据,并在 OpenTelemetry Transformation Language (OTTL) 中修改遥测数据。对于每个信号类型,处理器处理与特定 OTTL 上下文类型关联的一系列条件和语句,然后按照配置中指定的在传入遥测数据上执行它们。每个条件和语句都可以使用各种功能访问和修改遥测数据,允许条件指示是否要执行的函数。

所有语句都是在 OTTL 中编写的。您可以为不同的信号、跟踪、指标和日志配置多个上下文语句。context 类型的值指定在解释关联的语句时,处理器必须使用哪个 OTTL 上下文。

重要

Transform 处理器只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

配置概述

# ...
config:
    processors:
      transform:
        error_mode: ignore 
1

        <trace|metric|log>_statements: 
2

          - context: <string> 
3

            conditions:  
4

              - <string>
              - <string>
            statements: 
5

              - <string>
              - <string>
              - <string>
          - context: <string>
            statements:
              - <string>
              - <string>
              - <string>
# ...
Copy to Clipboard Toggle word wrap

1
可选:请参阅下表 "Values for the optional error_mode 字段"。
2
表示要转换的信号。
3
请参见下表" context 字段的值"。
4
可选:执行转换的条件。

使用 Transform Processor 时 OpenTelemetry Collector 自定义资源示例

# ...
  config:
    transform:
      error_mode: ignore
      trace_statements: 
1

        - context: resource
          statements:
            - keep_keys(attributes, ["service.name", "service.namespace", "cloud.region", "process.command_line"]) 
2

            - replace_pattern(attributes["process.command_line"], "password\\=[^\\s]*(\\s?)", "password=***") 
3

            - limit(attributes, 100, [])
            - truncate_all(attributes, 4096)
        - context: span 
4

          statements:
            - set(status.code, 1) where attributes["http.path"] == "/health"
            - set(name, attributes["http.route"])
            - replace_match(attributes["http.target"], "/user/*/list/*", "/user/{userId}/list/{listId}")
            - limit(attributes, 100, [])
            - truncate_all(attributes, 4096)
# ...
Copy to Clipboard Toggle word wrap

1
转换 trace 信号。
2
在资源中保留密钥。
3
使用星号替换 password 字段中的属性和字符串字符。
4
在 span 级别执行转换。
Expand
表 3.3. context 字段的值
信号声明有效上下文

trace_statements

resource, scope, span, spanevent

metric_statements

resource, scope, metric, datapoint

log_statements

resource, scope, log

Expand
表 3.4. 可选 error_mode 字段的值
描述

ignore

忽略并记录声明返回的错误,然后继续到下一个语句。

silent

忽略并不记录声明返回的错误,然后继续到下一个语句。

propagate

返回错误管道并丢弃有效负载。隐式默认值。

3.12. Tail Sampling Processor

当所有 span 都完成后,Tail Sampling 处理器会根据用户定义的策略抽样 trace。通过基于尾部的抽样,您可以过滤感兴趣的追踪,并降低数据生成和存储成本。

重要

Tail Sampling 处理器只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

此处理器将 span 组合成新的批处理,并剥离原始上下文。

提示
  • 在管道中,将依赖上下文的任何处理器下游放在管道中:例如,在 Kubernetes Attributes Processor 后。
  • 如果扩展 Collector,请确保一个 Collector 实例接收同一 trace 的所有范围,以便此处理器根据指定的抽样策略做出正确的抽样决策。您可以通过设置 Collector 的两层来实现此目的:使用 Load Balancing Exporter 的 Collector 的第一层,以及使用 Tail Sampling Processor 的 Collector 的第二个层。

使用 Tail Sampling Processor 时 OpenTelemetry Collector 自定义资源的示例

# ...
config:
  processors:
    tail_sampling: 
1

      decision_wait: 30s 
2

      num_traces: 50000 
3

      expected_new_traces_per_sec: 10 
4

      policies: 
5

        [
          {
            <definition_of_policy_1>
          },
          {
            <definition_of_policy_2>
          },
          {
            <definition_of_policy_3>
          },
        ]
# ...
Copy to Clipboard Toggle word wrap

1
处理器名称。
2
可选:在处理器对每个 trace 做出抽样决定前,决策延迟时间从第一个范围的时间段内计算。默认值为 30s
3
可选:保存在内存中的追踪数量。默认值为 50000
4
可选:预期每秒新 trace 数量,这有助于分配数据结构。默认为 0。
5
用于追踪评估的策略定义。处理器会根据所有指定的策略评估每个追踪,然后示例或丢弃 trace。

您可以从以下列表中选择和组合策略:

  • 以下策略抽样所有 trace:

    # ...
          policies:
            [
              {
                name: <always_sample_policy>,
                type: always_sample,
              },
            ]
    # ...
    Copy to Clipboard Toggle word wrap
  • 以下策略只对位于指定范围内的持续时间进行追踪:

    # ...
          policies:
            [
              {
                name: <latency_policy>,
                type: latency,
                latency: {threshold_ms: 5000, upper_threshold_ms: 10000} 
    1
    
              },
            ]
    # ...
    Copy to Clipboard Toggle word wrap
    1
    提供的 500010000 值只是一个示例。您可以通过查看最早的开始时间值和最新结束时间值来估算所需的延迟值。如果省略 upper_threshold_ms 字段,则此策略会抽样超过指定 threshold_ms 值的所有延迟。
  • 以下策略示例根据数字值与 resource 和 record 属性匹配:

    # ...
          policies:
            [
              {
                name: <numeric_attribute_policy>,
                type: numeric_attribute,
                numeric_attribute: {key: <key1>, min_value: 50, max_value: 100} 
    1
    
              },
            ]
    # ...
    Copy to Clipboard Toggle word wrap
    1
    提供的 50100 值只是示例。
  • 以下策略示例仅对 trace 的百分比进行抽样:

    # ...
          policies:
            [
              {
                name: <probabilistic_policy>,
                type: probabilistic,
                probabilistic: {sampling_percentage: 10} 
    1
    
              },
            ]
    # ...
    Copy to Clipboard Toggle word wrap
    1
    提供的 10 值是一个示例。
  • 以下策略示例根据状态代码对 trace 进行抽样: OKERRORUNSET

    # ...
          policies:
            [
              {
                name: <status_code_policy>,
                type: status_code,
                status_code: {status_codes: [ERROR, UNSET]}
              },
            ]
    # ...
    Copy to Clipboard Toggle word wrap
  • 以下策略示例根据字符串值与 resource 和 record 属性匹配:

    # ...
          policies:
            [
              {
                name: <string_attribute_policy>,
                type: string_attribute,
                string_attribute: {key: <key2>, values: [<value1>, <val>*], enabled_regex_matching: true, cache_max_size: 10} 
    1
    
              },
            ]
    # ...
    Copy to Clipboard Toggle word wrap
    1
    此策略定义支持完全匹配和常规表达式值。cache_max_size 字段中提供的 10 值是一个示例。
  • 以下策略示例根据每秒 span 率进行追踪:

    # ...
          policies:
            [
              {
                name: <rate_limiting_policy>,
                type: rate_limiting,
                rate_limiting: {spans_per_second: 35} 
    1
    
              },
            ]
    # ...
    Copy to Clipboard Toggle word wrap
    1
    提供的 35 值是一个示例。
  • 以下策略示例根据最小和最大 span 数量对 trace 进行抽样:

    # ...
          policies:
            [
              {
                name: <span_count_policy>,
                type: span_count,
                span_count: {min_spans: 2, max_spans: 20} 
    1
    
              },
            ]
    # ...
    Copy to Clipboard Toggle word wrap
    1
    如果 trace 中的所有 span 的总和超出范围阈值,则 trace 不会被抽样。提供的 220 值只是一个示例。
  • 以下通过 TraceState 值的 trace 匹配:

    # ...
          policies:
            [
              {
                name: <trace_state_policy>,
                type: trace_state,
                trace_state: { key: <key3>, values: [<value1>, <value2>] }
              },
            ]
    # ...
    Copy to Clipboard Toggle word wrap
  • 以下策略示例根据布尔值属性(资源和记录)进行跟踪:

    # ...
          policies:
            [
              {
                name: <bool_attribute_policy>,
                type: boolean_attribute,
                boolean_attribute: {key: <key4>, value: true}
              },
            ]
    # ...
    Copy to Clipboard Toggle word wrap
  • 以下策略示例由给定布尔值 OTTL 条件为 span 或 span 事件进行追踪:

    # ...
          policies:
            [
              {
                name: <ottl_policy>,
                type: ottl_condition,
                ottl_condition: {
                  error_mode: ignore,
                  span: [
                    "attributes[\"<test_attr_key_1>\"] == \"<test_attr_value_1>\"",
                    "attributes[\"<test_attr_key_2>\"] != \"<test_attr_value_1>\"",
                  ],
                  spanevent: [
                    "name != \"<test_span_event_name>\"",
                    "attributes[\"<test_event_attr_key_2>\"] != \"<test_event_attr_value_1>\"",
                  ]
                }
              },
            ]
    # ...
    Copy to Clipboard Toggle word wrap
  • 以下是一个 AND 策略,它基于多个策略的组合对 trace 进行抽样:

    # ...
          policies:
            [
              {
                name: <and_policy>,
                type: and,
                and: {
                  and_sub_policy:
                  [
                    {
                      name: <and_policy_1>,
                      type: numeric_attribute,
                      numeric_attribute: { key: <key1>, min_value: 50, max_value: 100 } 
    1
    
                    },
                    {
                      name: <and_policy_2>,
                      type: string_attribute,
                      string_attribute: { key: <key2>, values: [ <value1>, <value2> ] }
                    },
                  ]
                }
              },
            ]
    # ...
    Copy to Clipboard Toggle word wrap
    1
    提供的 50100 值只是示例。
  • 以下是一个 DROP 策略,它根据多个策略的组合从抽样中丢弃 trace:

    # ...
          policies:
            [
              {
                name: <drop_policy>,
                type: drop,
                drop: {
                  drop_sub_policy:
                  [
                    {
                      name: <drop_policy_1>,
                      type: string_attribute,
                      string_attribute: {key: url.path, values: [\/health, \/metrics], enabled_regex_matching: true}
                    }
                  ]
                }
              },
            ]
    # ...
    Copy to Clipboard Toggle word wrap
  • 以下策略示例根据前面的抽样器的组合,以及每个 sampler 的排序和速率分配的组合对 trace 进行抽样:

    # ...
          policies:
            [
              {
                name: <composite_policy>,
                type: composite,
                composite:
                  {
                    max_total_spans_per_second: 100, 
    1
    
                    policy_order: [<composite_policy_1>, <composite_policy_2>, <composite_policy_3>],
                    composite_sub_policy:
                      [
                        {
                          name: <composite_policy_1>,
                          type: numeric_attribute,
                          numeric_attribute: {key: <key1>, min_value: 50}
                        },
                        {
                          name: <composite_policy_2>,
                          type: string_attribute,
                          string_attribute: {key: <key2>, values: [<value1>, <value2>]}
                        },
                        {
                          name: <composite_policy_3>,
                          type: always_sample
                        }
                      ],
                      rate_allocation:
                      [
                        {
                          policy: <composite_policy_1>,
                          percent: 50 
    2
    
                        },
                        {
                          policy: <composite_policy_2>,
                          percent: 25
                        }
                      ]
                  }
              },
            ]
    # ...
    Copy to Clipboard Toggle word wrap
    1 2
    根据应用策略的顺序分配 span 的百分比。例如,如果您在 max_total_spans_per_second 字段中设置了 100 值,您可以在 rate_allocation 部分中设置以下值:policy: <composite_policy_1> 部分中的 50 百分比值代表每秒分配 50 个 span;policy: <composite_policy_2> 部分中的 25 百分比值代表每秒分配 25 个 span。要填充剩余的容量,您可以在 name: <composite_policy_3> 部分的 type 字段中设置 always_sample 值。

3.13. Probabilistic Sampling Processor

如果您处理大量遥测数据,并希望通过降低处理的数据量来降低成本,您可以使用 Probabilistic Sampling Processor 作为 Tail Sampling Processor 的替代选择。

重要

Probabilistic Sampling Processor 只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

处理器在无状态和每个请求中抽样指定百分比的 trace 范围或日志记录。

处理器将有关已用的有效抽样概率的信息添加到遥测数据中:

  • 在 trace span 中,处理器在 W3C Trace Context tracestate 字段中对阈值和可选的随机性信息进行编码。
  • 在日志记录中,处理器将阈值和随机信息编码为属性。

以下是用于抽样追踪的 Probabilistic Sampling Processor 的 OpenTelemetryCollector 自定义资源配置示例:

# ...
  config:
    processors:
      probabilistic_sampler: 
1

        sampling_percentage: 15.3 
2

        mode: "proportional" 
3

        hash_seed: 22 
4

        sampling_precision: 14 
5

        fail_closed: true 
6

# ...
service:
  pipelines:
    traces:
      processors: [probabilistic_sampler]
# ...
Copy to Clipboard Toggle word wrap
1
对于追踪管道,随机性的来源是 span 跟踪 ID 的散列值。
2
必需。接受 32 位浮点百分比值,在其中对 span 进行抽样。
3
可选。接受抽样逻辑模式支持的字符串值:默认的 hash_seedproportional,或 equalizinghash_seed 模式将 Fowler-Noll-Vo (FNV)哈希功能应用到 trace ID,并将散列值用于抽样百分比值。您还可以使用 hash_seed 模式,以及 trace ID 以外的遥测单元。proportional 模式对总范围数量有严格的、基于概率的比例进行抽样,并基于 OpenTelemetry 和 World Wide Web Consortium 规格。equalizing 模式可用于将抽样概率降低到整个管道中的最小值,或者在 Collector 部署中应用统一的抽样可能性,其中 client SDK 具有混合抽样配置。
4
可选。接受 32 位未签名的整数,该整数用于计算哈希算法。如果没有配置此字段,则默认的 seed 值为 0。如果使用多个 Collector 实例层,您必须将同一层的所有收集器配置为相同的 seed 值。
5
可选。决定用于编码抽样阈值的十六进制数。接受整数值。支持的值 1-14。如果阈值 4 包含超过 16 个重要位(使用 56 位 proportional 模式)时,默认值 4 会导致对阈值进行舍入。如果您选择 proportional 模式,请为前面的 samplers 应用保留精度的目的使用更大的值。
6
可选。拒绝 span,带有抽样错误。接受一个布尔值。默认值为 true

以下是用于抽样日志记录的 Probabilistic Sampling Processor 的 OpenTelemetryCollector 自定义资源配置示例:

# ...
  config:
    processors:
      probabilistic_sampler/logs:
        sampling_percentage: 15.3 
1

        mode: "hash_seed" 
2

        hash_seed: 22 
3

        sampling_precision: 4 
4

        attribute_source: "record" 
5

        from_attribute: "<log_record_attribute_name>" 
6

        fail_closed: true 
7

# ...
service:
  pipelines:
    logs:
      processors: [ probabilistic_sampler/logs ]
# ...
Copy to Clipboard Toggle word wrap
1
必需。接受 32 位浮点百分比值,在其中对 span 进行抽样。
2
可选。接受抽样逻辑模式支持的字符串值:默认的 hash_seedequalizing, 或 proportionalhash_seed 模式将 Fowler-Noll-Vo (FNV)哈希功能应用到 trace ID 或指定的日志记录属性,然后根据抽样百分比值来权衡散列值。您也可以将 hash_seed 模式与遥测 ID 的其他单元一起使用,例如,使用 service.instance.id 资源属性从 pod 中收集日志记录。equalizing 模式可用于将抽样概率降低到整个管道中的最小值,或者在 Collector 部署中应用统一的抽样可能性,其中 client SDK 具有混合抽样配置。proportional 模式对总范围数量有严格的、基于概率的比例进行抽样,并基于 OpenTelemetry 和 World Wide Web Consortium 规格。
3
可选。接受 32 位未签名的整数,该整数用于计算哈希算法。如果没有配置此字段,则默认的 seed 值为 0。如果使用多个 Collector 实例层,您必须将同一层的所有收集器配置为相同的 seed 值。
4
可选。决定用于编码抽样阈值的十六进制数。接受整数值。支持的值 1-14。如果阈值 4 包含超过 16 个重要位(使用 56 位 proportional 模式)时,默认值 4 会导致对阈值进行舍入。如果您选择 proportional 模式,请为前面的 samplers 应用保留精度的目的使用更大的值。
5
可选。定义 from_attribute 中查找日志记录属性的位置。日志记录属性用作随机性的来源。接受默认的 traceID 值或 record 值。
6
可选。用于计算抽样哈希的日志记录属性的名称,如唯一的日志记录 ID。接受字符串值。默认值为 ""。只有在需要在缺少 trace ID 或 trace ID 抽样被禁用或将 attribute_source 字段设置为 record 值时,才需要指定日志记录属性作为随机性时才使用这个选项。
7
可选。拒绝 span,带有抽样错误。接受一个布尔值。默认值为 true

第 4 章 Exporters

导出器将数据发送到一个或多个后端或目的地。导出器可以基于推送或拉取 (pull)。默认情况下,不会配置导出器。必须配置一个或多个导出器。导出器可以支持一个或多个数据源。导出器可能会与其默认设置一起使用,但许多导出器需要配置来至少指定目标和安全设置。

目前,红帽构建的 OpenTelemetry 提供了以下正式发行(GA)和技术预览导出器:

4.1. OTLP Exporter

OTLP gRPC Exporter 使用 OpenTelemetry 协议 (OTLP) 导出追踪和指标。

OpenTelemetry Collector 自定义资源带有启用的 OTLP Exporter

# ...
  config:
    exporters:
      otlp:
        endpoint: tempo-ingester:4317 
1

        tls: 
2

          ca_file: ca.pem
          cert_file: cert.pem
          key_file: key.pem
          insecure: false 
3

          insecure_skip_verify: false # 
4

          reload_interval: 1h 
5

          server_name_override: <name> 
6

        headers: 
7

          X-Scope-OrgID: "dev"
    service:
      pipelines:
        traces:
          exporters: [otlp]
        metrics:
          exporters: [otlp]
# ...
Copy to Clipboard Toggle word wrap

1
OTLP gRPC 端点。如果使用 https:// 方案,则启用客户端传输安全性并覆盖 tls 中的 不安全 设置。
2
客户端 TLS 配置。定义 TLS 证书的路径。
3
当设置为 true 时禁用客户端传输安全性。默认值为 false
4
当设置为 true 时跳过验证证书。默认值为 false
5
指定重新载入证书的时间间隔。如果没有设置值,则证书永远不会重新加载。reload_interval 接受包含有效时间单位的字符串,如 ns, usµs, ms, s, m, h
6
覆盖请求中的颁发机构的虚拟主机名,如授权标头字段。您可以使用此选项进行测试。
7
为建立的连接期间执行的每个请求发送标头。

4.2. OTLP HTTP Exporter

OTLP HTTP Exporter 使用 OpenTelemetry 协议 (OTLP) 导出追踪和指标。

OpenTelemetry Collector 自定义资源带有启用的 OTLP Exporter

# ...
  config:
    exporters:
      otlphttp:
        endpoint: http://tempo-ingester:4318 
1

        tls: 
2

        headers: 
3

          X-Scope-OrgID: "dev"
        disable_keep_alives: false 
4


    service:
      pipelines:
        traces:
          exporters: [otlphttp]
        metrics:
          exporters: [otlphttp]
# ...
Copy to Clipboard Toggle word wrap

1
OTLP HTTP 端点。如果使用 https:// 方案,则启用客户端传输安全性并覆盖 tls 中的 不安全 设置。
2
客户端 TLS 配置。定义 TLS 证书的路径。
3
标头会在每个 HTTP 请求中发送。
4
如果为 true,禁用 HTTP keep-alives。它将只对单个 HTTP 请求使用到服务器的连接。

4.3. Debug Exporter

Debug Exporter 将 trace 和 metrics 打印到标准输出。

OpenTelemetry Collector 自定义资源带有启用的 Debug Exporter

# ...
  config:
    exporters:
      debug:
        verbosity: detailed 
1

        sampling_initial: 5 
2

        sampling_thereafter: 200 
3

        use_internal_logger: true 
4

    service:
      pipelines:
        traces:
          exporters: [debug]
        metrics:
          exporters: [debug]
# ...
Copy to Clipboard Toggle word wrap

1
debug 导出的详细程度为:detailednormalbasic。当设置为 detailed 时,管道数据会被详细记录。默认为 normal
2
每秒日志记录的初始消息数。默认值为每秒 2 个消息。
3
在初始消息数后的抽样率,sampling_initial 中的值已被记录。默认禁用,默认值为 1。使用大于 1 的值启用抽样。如需更多信息,请参阅 Go Project 网站上 zapcore 软件包中的 sampler 函数页。
4
当设置为 true 时,为导出器启用 Collector 内部日志记录器的输出。

4.4. Load Balancing Exporter

Load Balancing Exporter 根据 routing_key 配置,一致性地导出 span、metrics 和 logs。

重要

Load Balancing Exporter 只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

OpenTelemetry Collector 自定义资源带有启用的 Load Balancing Exporter

# ...
  config:
    exporters:
      loadbalancing:
        routing_key: "service" 
1

        protocol:
          otlp: 
2

            timeout: 1s
        resolver: 
3

          static: 
4

            hostnames:
            - backend-1:4317
            - backend-2:4317
          dns: 
5

            hostname: otelcol-headless.observability.svc.cluster.local
          k8s: 
6

            service: lb-svc.kube-public
            ports:
              - 15317
              - 16317
# ...
Copy to Clipboard Toggle word wrap

1
routing_key: service 将相同服务名称的 span 导出到同一个 Collector 实例,以提供准确的聚合数据。routing_key: traceID 根据 traceID 导出 span。隐式默认为基于 traceID 的路由。
2
OTLP 是唯一支持的负载均衡协议。支持 OTLP 导出器的所有选项。
3
您只能配置一个解析器。
4
静态解析器在列出的端点之间发布负载。
5
您只能将 DNS 解析器与 Kubernetes 无头(headless)服务一起使用。
6
建议使用 Kubernetes 解析器。

4.5. Prometheus Exporter

Prometheus Exporter 以 Prometheus 或 OpenMetrics 格式导出指标。

重要

Prometheus Exporter 只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

OpenTelemetry Collector 自定义资源带有启用的 Prometheus Exporter

# ...
  config:
    exporters:
      prometheus:
        endpoint: 0.0.0.0:8889 
1

        tls: 
2

          ca_file: ca.pem
          cert_file: cert.pem
          key_file: key.pem
        namespace: prefix 
3

        const_labels: 
4

          label1: value1
        enable_open_metrics: true 
5

        resource_to_telemetry_conversion: 
6

          enabled: true
        metric_expiration: 180m 
7

        add_metric_suffixes: false 
8

    service:
      pipelines:
        metrics:
          exporters: [prometheus]
# ...
Copy to Clipboard Toggle word wrap

1
公开指标的网络端点。Red Hat build of OpenTelemetry Operator 会自动公开 endpoint 字段中指定的端口,到 <instance_name>-collector 服务。
2
服务器端 TLS 配置。定义 TLS 证书的路径。
3
如果设置,在提供的值下导出指标。
4
每个导出的指标应用的键值对标签。
5
如果为 true,则使用 OpenMetrics 格式导出指标。Exemplars 仅以 OpenMetrics 格式导出,仅适用于直方和 monotonic 摘要指标,如 counter。默认禁用此选项。
6
如果 enabledtrue,所有资源属性都会转换为指标标签。默认禁用此选项。
7
定义在没有更新的情况下公开指标的时间。默认值为 5m
8
添加指标类型和单元后缀。如果启用了 Jaeger 控制台中的 monitor 选项卡,则必须禁用。默认值是 true
注意

OpenTelemetryCollector 自定义资源 (CR) 中的 spec.observability.metrics.enableMetrics 字段设置为 true 时,OpenTelemetryCollector CR 会自动创建一个 Prometheus ServiceMonitorPodMonitor CR,以便 Prometheus 提取您的指标。

4.6. Prometheus Remote Write Exporter

Prometheus Remote Write Exporter 将指标导出到兼容后端。

重要

Prometheus Remote Write Exporter 只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

OpenTelemetry Collector 自定义资源带有启用的 Prometheus Remote Write Exporter

# ...
  config:
    exporters:
      prometheusremotewrite:
        endpoint: "https://my-prometheus:7900/api/v1/push" 
1

        tls: 
2

          ca_file: ca.pem
          cert_file: cert.pem
          key_file: key.pem
        target_info: true 
3

        export_created_metric: true 
4

        max_batch_size_bytes: 3000000 
5

    service:
      pipelines:
        metrics:
          exporters: [prometheusremotewrite]
# ...
Copy to Clipboard Toggle word wrap

1
用于发送指标的端点。
2
服务器端 TLS 配置。定义 TLS 证书的路径。
3
当设置为 true 时,为每个资源指标创建一个 target_info 指标。
4
当设置为 true 时,为 Summary、Histogram 和 Monotonic Sum 指标点导出 _created 的指标。
5
发送到远程写入端点的示例批处理的最大大小。超过这个值会导致批处理分割。默认值为 3000000,它大约为 2.861MB。
警告
  • 此导出器会丢弃 non-cumulative monotonic, histogram, 和 summary OTLP 指标。
  • 您需要在远程 Prometheus 实例上启用 --web.enable-remote-write-receiver 功能标记。如果没有它,则使用此导出器将指标推送到实例会失败。

4.7. Kafka Exporter

Kafka Exporter 将日志、指标和追踪导出到 Kafka。此导出器使用同步制作者,用于阻止且不批处理消息。它必须与批处理和排队重试处理器一起使用,以获得更高的吞吐量和弹性。

OpenTelemetry Collector 自定义资源带有启用的 Kafka Exporter

# ...
  config:
    exporters:
      kafka:
        brokers: ["localhost:9092"] 
1

        protocol_version: 2.0.0 
2

        topic: otlp_spans 
3

        auth:
          plain_text: 
4

            username: example
            password: example
          tls: 
5

            ca_file: ca.pem
            cert_file: cert.pem
            key_file: key.pem
            insecure: false 
6

            server_name_override: kafka.example.corp 
7

    service:
      pipelines:
        traces:
          exporters: [kafka]
# ...
Copy to Clipboard Toggle word wrap

1
Kafka 代理列表。默认值为 localhost:9092
2
Kafka 协议版本。例如,2.0.0。这个为必填字段。
3
要从中读取的 Kafka 主题的名称。以下是默认设置:otlp_spans(用于 traces), otlp_metrics(用于 metrics), otlp_logs(用于 logs)。
4
纯文本形式的身份验证配置。如果省略,则禁用纯文本形式的身份验证。
5
客户端 TLS 配置。定义 TLS 证书的路径。如果省略,则禁用 TLS 身份验证。
6
禁用验证服务器的证书链和主机名。默认值为 false
7
ServerName 表示客户端请求的服务器名称,以支持虚拟主机。

4.8. AWS CloudWatch Logs Exporter

AWS CloudWatch Logs Exporter 将日志数据发送到 Amazon CloudWatch Logs 服务,并使用 AWS SDK 为 Go 和默认凭证供应商链签名请求。

重要

AWS CloudWatch Logs Exporter 只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

OpenTelemetry Collector 自定义资源带有启用的 AWS CloudWatch Logs Exporter

# ...
  config:
    exporters:
      awscloudwatchlogs:
        log_group_name: "<group_name_of_amazon_cloudwatch_logs>" 
1

        log_stream_name: "<log_stream_of_amazon_cloudwatch_logs>" 
2

        region: <aws_region_of_log_stream> 
3

        endpoint: <protocol><service_endpoint_of_amazon_cloudwatch_logs> 
4

        log_retention: <supported_value_in_days> 
5

        role_arn: "<iam_role>" 
6

# ...
Copy to Clipboard Toggle word wrap

1
必需。如果日志组尚不存在,则会自动创建它。
2
必需。如果日志流尚不存在,则会自动创建它。
3
可选。如果 AWS 区域还没有在默认凭证链中设置,您必须指定它。
4
可选。您可以覆盖将请求转发到的默认 Amazon CloudWatch Logs 服务端点。您必须包含协议,如 https://,作为端点值的一部分。有关区域服务端点列表,请参阅 Amazon CloudWatch Logs 端点和配额 (AWS General Reference)。
5
可选。使用这个参数,您可以为新的 Amazon CloudWatch 日志组设置日志保留策略。如果省略此参数或设置为 0,则日志默认不会过期。支持的保留值(以天为单位)是 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, 2192, 2557, 2922, 3288, 或 3653
6
可选。AWS Identity and Access Management (IAM)角色,将日志片段上传到其他帐户。

4.9. AWS EMF Exporter

AWS EMF Exporter 将以下 OpenTelemetry 指标数据点转换为 AWS CloudWatch 嵌入式指标格式(EMF):

  • Int64DataPoints
  • DoubleDataPoints
  • SummaryDataPoints

然后,使用 PutLogEvents API 直接发送到 Amazon CloudWatch Logs 服务。

使用此导出器的一个好处是,可以在 Amazon CloudWatch 控制台中查看日志和指标,地址为 https://console.aws.amazon.com/cloudwatch/

重要

AWS EMF Exporter 只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

OpenTelemetry Collector 自定义资源带有启用的 AWS EMF Exporter

# ...
  config:
    exporters:
      awsemf:
        log_group_name: "<group_name_of_amazon_cloudwatch_logs>" 
1

        log_stream_name: "<log_stream_of_amazon_cloudwatch_logs>" 
2

        resource_to_telemetry_conversion: 
3

          enabled: true
        region: <region> 
4

        endpoint: <protocol><endpoint> 
5

        log_retention: <supported_value_in_days> 
6

        namespace: <custom_namespace> 
7

        role_arn: "<iam_role>" 
8

# ...
Copy to Clipboard Toggle word wrap

1
log_group_name 参数允许您自定义日志组名称,并支持默认的 /metrics/default 值或以下占位符:

/aws/metrics/{ClusterName} 占位符用于搜索指标数据中的 ClusterNameaws.ecs.cluster.name 资源属性,并将其替换为实际集群名称。

{NodeName} 占位符用于搜索 NodeNamek8s.node.name 资源属性。

{TaskId} 占位符用于搜索 TaskIdaws.ecs.task.id 资源属性。

如果在资源属性映射中没有找到 resource 属性,则占位符将替换为 undefined 值。

2
您可以使用 log_stream_name 参数自定义日志流名称,或者设置默认的 otel-stream 值或以下占位符:

{ClusterName} 占位符用于搜索 ClusterNameaws.ecs.cluster.name 资源属性。

{ContainerInstanceId} 占位符用于搜索 ContainerInstanceIdaws.ecs.container.instance.id 资源属性。此资源属性仅对 AWS ECS EC2 启动类型有效。

{NodeName} 占位符用于搜索 NodeNamek8s.node.name 资源属性。

{TaskDefinitionFamily} 占位符用于搜索 TaskDefinitionFamilyaws.ecs.task.family 资源属性。

{TaskId} 占位符用于搜索指标数据中的 TaskIdaws.ecs.task.id 资源属性,并将其替换为实际任务 ID。

如果在资源属性映射中没有找到 resource 属性,则占位符将替换为 undefined 值。

3
可选。将资源属性转换为遥测属性,如指标标签。默认禁用此选项。
4
日志流的 AWS 区域。如果默认凭证供应商链中尚未设置区域,您必须指定区域。
5
可选。您可以覆盖将请求转发到的默认 Amazon CloudWatch Logs 服务端点。您必须包含协议,如 https://,作为端点值的一部分。有关区域服务端点列表,请参阅 Amazon CloudWatch Logs 端点和配额 (AWS General Reference)。
6
可选。使用这个参数,您可以为新的 Amazon CloudWatch 日志组设置日志保留策略。如果省略此参数或设置为 0,则日志默认不会过期。支持的保留值(以天为单位)是 1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, 2192, 2557, 2922, 3288, 或 3653
7
可选。Amazon CloudWatch 指标的自定义命名空间。
8
可选。AWS Identity and Access Management (IAM)角色,将指标片段上传到其他帐户。

4.10. AWS X-Ray Exporter

AWS X-Ray Exporter 将 OpenTelemetry span 转换为 AWS X-Ray Segment 文档,然后将它们直接发送到 AWS X-Ray 服务。AWS X-Ray Exporter 使用 PutTraceSegments API,并使用 AWS SDK 为 Go 和默认凭证供应商链签名请求。

重要

AWS X-Ray Exporter 只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

OpenTelemetry Collector 自定义资源带有启用的 AWS X-Ray Exporter

# ...
  config:
    exporters:
      awsxray:
        region: "<region>" 
1

        endpoint: <protocol><endpoint> 
2

        resource_arn: "<aws_resource_arn>" 
3

        role_arn: "<iam_role>" 
4

        indexed_attributes: [ "<indexed_attr_0>", "<indexed_attr_1>" ] 
5

        aws_log_groups: ["<group1>", "<group2>"] 
6

        request_timeout_seconds: 120 
7

# ...
Copy to Clipboard Toggle word wrap

1
发送到 AWS X-Ray 服务的 X-Ray 片段的目标区域。例如,eu-west-1
2
可选。您可以覆盖将请求转发到的默认 Amazon CloudWatch Logs 服务端点。您必须包含协议,如 https://,作为端点值的一部分。有关区域服务端点列表,请参阅 Amazon CloudWatch Logs 端点和配额 (AWS General Reference)。
3
运行 Collector 的 AWS 资源的 Amazon 资源名称 (ARN)。
4
AWS Identity and Access Management (IAM) 角色,将 X-Ray 片段上传到其他帐户。
5
要转换为 X-Ray 注解的属性名称列表。
6
Amazon CloudWatch Logs 的日志组名称列表。
7
请求超时前的持续时间(以秒为单位)。如果省略,则默认值为 30

4.11. File Exporter

文件 Exporter 将遥测数据写入持久性存储中的文件,并支持轮转、压缩和写入多个文件等文件操作。使用这个导出器,您还可以使用 resource 属性来控制文件命名。唯一必需的设置是 path,用于指定 persistent-volume 文件系统中遥测文件的目的地路径。

重要

File Exporter 只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

OpenTelemetry Collector 自定义资源带有启用的文件导出器

# ...
  config: |
    exporters:
      file:
        path: /data/metrics.json 
1

        rotation: 
2

          max_megabytes: 10 
3

          max_days: 3 
4

          max_backups: 3 
5

          localtime: true 
6

        format: proto 
7

        compression: zstd 
8

        flush_interval: 5 
9

# ...
Copy to Clipboard Toggle word wrap

1
要写入数据的文件系统路径。没有默认值。
2
文件轮转是此导出器的可选功能。默认情况下,遥测数据导出到单个文件。添加 rotation 设置以启用文件轮转。
3
max_megabytes 设置是文件被允许访问的最大大小,直到它被轮转为止。默认值为 100
4
max_days 设置用于保留文件的天数,从文件名中的时间戳计数。没有默认值。
5
max_backups 设置用于保留几个较旧的文件。默认值为 100
6
localtime 设置指定时间戳的本地时间格式,该格式会在文件轮转时附加到任何扩展名前面的文件名中。默认为协调的通用时间 (UTC)。
7
在将遥测数据写入文件之前,对遥测数据进行编码的格式。默认格式为 json。还支持 proto 格式。
8
文件压缩是可选的,默认情况下不设置。此设置定义导出到文件的数据的压缩算法。目前,只支持 zstd 压缩算法。没有默认值。
9
刷新间隔。没有单位的值被设置为纳秒。当通过 rotation 设置启用文件轮转时,会忽略此设置。

4.12. Google Cloud Exporter

Google Cloud Exporter 将遥测数据发送到 Google Cloud Operations Suite。使用 Google Cloud Exporter,您可以将指标导出到 Google Cloud Monitoring,登录到 Google Cloud Logging,并将 trace 导出到 Google Cloud Trace。

重要

Google Cloud Exporter 只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

OpenTelemetry Collector 自定义资源带有启用的 Google Cloud Exporter

# ...
  env:
    - name: GOOGLE_APPLICATION_CREDENTIALS
      value: /var/secrets/google/key.json 
1

  volumeMounts:
    - name: google-application-credentials
      mountPath: /var/secrets/google
      readOnly: true
  volumes:
    - name: google-application-credentials
      secret:
        secretName: google-application-credentials
  config:
    exporters:
      googlecloud:
        project: 
2

# ...
Copy to Clipboard Toggle word wrap

1
GOOGLE_APPLICATION_CREDENTIALS 环境变量,指向身份验证 key.json 文件。key.json 文件作为 secret 卷挂载到 OpenTelemetry Collector。
2
可选。项目标识符。如果没有指定,则项目会自动从凭证决定。

默认情况下,导出器将遥测数据发送到导出器配置的 project 字段中指定的项目。您可以使用 gcp.project.id 资源属性在每个指标上设置覆盖。例如,如果指标具有标签项目,您可以使用 Group-by-Attributes Processor 将它提升到资源标签,然后使用 Resource Processor 将属性从 项目 重命名为 gcp.project.id

第 5 章 连接器

连接器连接两个管道。它在一个管道的末尾将数据视为导出器,并在另一个管道开始时将数据作为接收器发送。它可以消耗和发送相同或不同数据类型的数据。它可以生成并发送数据以汇总已消耗的数据,或者可以完全复制或路由数据。

目前,红帽构建的 OpenTelemetry 提供了以下正式发行(GA)和技术预览连接器:

5.1. 计数连接器

Count Connector 计算 trace span、trace span 事件、指标、指标数据点和导出器管道中的日志记录。

重要

Count Connector 只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

以下是默认指标名称:

  • trace.span.count
  • trace.span.event.count
  • metric.count
  • metric.datapoint.count
  • log.record.count

您还可以公开自定义指标名称。

带有启用 Count Connector 的 OpenTelemetry Collector 自定义资源 (CR)

# ...
  config:
    receivers:
      otlp:
        protocols:
          grpc:
            endpoint: 0.0.0.0:4317
    exporters:
      prometheus:
        endpoint: 0.0.0.0:8889
    connectors:
      count: {}
    service:
      pipelines: 
1

        traces/in:
          receivers: [otlp]
          exporters: [count] 
2

        metrics/out:
          receivers: [count] 
3

          exporters: [prometheus]
# ...
Copy to Clipboard Toggle word wrap

1
务必要将 Count Connector 正确配置为管道中的导出器或接收器,并将生成的指标导出到正确的导出器。
2
Count Connector 配置为作为导出器接收 span。
3
Count Connector 配置为将生成的指标作为接收器发出。
提示

如果 Count Connector 没有生成预期的指标,您可以检查 OpenTelemetry Collector 是否收到预期的 span、指标和日志,以及是否按预期通过 Count Connector 的遥测数据流。您还可以使用 Debug Exporter 检查传入的遥测数据。

Count Connector 可以根据定义的条件计算遥测数据,并在配置时将这些数据公开为指标,如 spans, spanevents, metrics, datapoints, 或 logs。请参阅下个示例。

Count Connector 的 OpenTelemetry Collector CR 示例,按条件计算 span

# ...
  config:
    connectors:
      count:
        spans: 
1

          <custom_metric_name>: 
2

            description: "<custom_metric_description>"
            conditions:
              - 'attributes["env"] == "dev"'
              - 'name == "devevent"'
# ...
Copy to Clipboard Toggle word wrap

1
在本例中,公开的指标计数超过指定条件。
2
您可以指定一个自定义指标名称,如 cluster.prod.event.count
提示

正确写入条件,并遵循与属性匹配或遥测字段条件所需的语法。不正确的定义条件是最有可能的错误源。

使用 spans, spanevents, metrics, datapoints, 或 logs 等字段配置时,Count Connector 可以根据定义的属性计算遥测数据。请参阅下个示例。属性键被注入到遥测数据。您必须为缺少属性的 default_value 字段定义一个值。

Count Connector 的 OpenTelemetry Collector CR 示例,按属性计算日志

# ...
  config:
    connectors:
      count:
        logs: 
1

          <custom_metric_name>: 
2

            description: "<custom_metric_description>"
            attributes:
              - key: env
                default_value: unknown 
3

# ...
Copy to Clipboard Toggle word wrap

1
指定日志的属性。
2
您可以指定一个自定义指标名称,如 my.log.count
3
在未设置属性时定义一个默认值。

5.2. Routing Connector

Routing Connector 根据资源属性及其路由条件将日志、指标和追踪路由到指定的管道,它们被写为 OpenTelemetry Transformation Language (OTTL) 语句。

重要

Routing Connector 只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

带有启用路由连接器的 OpenTelemetry Collector 自定义资源

# ...
  config:
    connectors:
      routing:
        table: 
1

          - statement: route() where attributes["X-Tenant"] == "dev" 
2

            pipelines: [traces/dev] 
3

          - statement: route() where attributes["X-Tenant"] == "prod"
            pipelines: [traces/prod]
        default_pipelines: [traces/dev] 
4

        error_mode: ignore 
5

        match_once: false 
6

    service:
      pipelines:
        traces/in:
          receivers: [otlp]
          exporters: [routing]
        traces/dev:
          receivers: [routing]
          exporters: [otlp/dev]
        traces/prod:
          receivers: [routing]
          exporters: [otlp/prod]
# ...
Copy to Clipboard Toggle word wrap

1
连接器路由表。
2
写入 OTTL 语句的路由条件。
3
用于路由匹配的遥测数据的目的地管道。
4
用于路由不满足路由条件的遥测数据的目的地管道。
5
错误处理模式 :propagate 值用于记录错误并丢弃有效负载。ignore 值用于忽略条件,并尝试与下一个值匹配。silent 值与 ignore 相同,但不记录错误。默认为 propagate
6
当设置为 true 时,有效负载仅路由到满足路由条件的第一个管道。默认值为 false

5.3. Forward Connector

Forward Connector 会合并同一类型的两个管道。

重要

Forward Connector 只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

启用了 Forward Connector 的 OpenTelemetry Collector 自定义资源

# ...
  config:
    receivers:
      otlp:
        protocols:
          grpc:
      jaeger:
        protocols:
          grpc:
    processors:
      batch:
    exporters:
      otlp:
        endpoint: tempo-simplest-distributor:4317
        tls:
          insecure: true
    connectors:
      forward: {}
    service:
      pipelines:
        traces/regiona:
          receivers: [otlp]
          processors: []
          exporters: [forward]
        traces/regionb:
          receivers: [jaeger]
          processors: []
          exporters: [forward]
        traces:
          receivers: [forward]
          processors: [batch]
          exporters: [otlp]
# ...
Copy to Clipboard Toggle word wrap

5.4. Spanmetrics Connector

Spanmetrics Connector 聚合了来自 span 数据的 Request, Error, 和 Duration (R.E.D) OpenTelemetry 指标。

启用了 Spanmetrics Connector 的 OpenTelemetry Collector 自定义资源

# ...
  config:
    connectors:
      spanmetrics:
        metrics_flush_interval: 15s 
1

    service:
      pipelines:
        traces:
          exporters: [spanmetrics]
        metrics:
          receivers: [spanmetrics]
# ...
Copy to Clipboard Toggle word wrap

1
定义生成的指标的清除间隔。默认值为 15s

第 6 章 扩展

扩展为 Collector 添加功能。例如,身份验证可以自动添加到接收器和导出器中。

目前,红帽构建的 OpenTelemetry 提供了以下正式发行(GA)和技术预览扩展:

6.1. BearerTokenAuth Extension

BearerTokenAuth Extension 是基于 HTTP 和 gRPC 协议的接收器和导出器的验证器。您可以使用 OpenTelemetry Collector 自定义资源为接收器和 exporter 端的 BearerTokenAuth Extension 配置客户端身份验证和服务器身份验证。此扩展支持 trace、metrics 和 logs。

OpenTelemetry Collector 自定义资源,为 BearerTokenAuth Extension 配置了客户端和服务器身份验证

# ...
  config:
    extensions:
      bearertokenauth:
        scheme: "Bearer" 
1

        token: "<token>" 
2

        filename: "<token_file>" 
3


    receivers:
      otlp:
        protocols:
          http:
            auth:
              authenticator: bearertokenauth 
4

    exporters:
      otlp:
        auth:
          authenticator: bearertokenauth 
5


    service:
      extensions: [bearertokenauth]
      pipelines:
        traces:
          receivers: [otlp]
          exporters: [otlp]
# ...
Copy to Clipboard Toggle word wrap

1
您可以配置 BearerTokenAuth Extension 来发送自定义 scheme。默认值为 Bearer
2
您可以将 BearerTokenAuth Extension 令牌添加为元数据,以标识消息。
3
包含随每个消息传输的授权令牌的文件路径。
4
您可以将验证器配置分配给 OTLP Receiver。
5
您可以将验证器配置分配给 OTLP Exporter。

6.2. OAuth2Client Extension

OAuth2Client Extension 是导出器的验证器,它基于 HTTP 和 gRPC 协议。OAuth2Client Extension 的客户端身份验证在 OpenTelemetry Collector 自定义资源中的单独部分中配置。此扩展支持 trace、metrics 和 logs。

重要

OAuth2Client 扩展只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

OpenTelemetry Collector 自定义资源,为 OAuth2Client Extension 配置了客户端身份验证

# ...
  config:
    extensions:
      oauth2client:
        client_id: <client_id> 
1

        client_secret: <client_secret> 
2

        endpoint_params: 
3

          audience: <audience>
        token_url: https://example.com/oauth2/default/v1/token 
4

        scopes: ["api.metrics"] 
5

        # tls settings for the token client
        tls: 
6

          insecure: true 
7

          ca_file: /var/lib/mycert.pem 
8

          cert_file: <cert_file> 
9

          key_file: <key_file> 
10

        timeout: 2s 
11


    receivers:
      otlp:
        protocols:
          http: {}

    exporters:
      otlp:
        auth:
          authenticator: oauth2client 
12


    service:
      extensions: [oauth2client]
      pipelines:
        traces:
          receivers: [otlp]
          exporters: [otlp]
# ...
Copy to Clipboard Toggle word wrap

1
客户端标识符,由身份提供程序提供。
2
用于向身份提供程序验证客户端的机密密钥。
3
其他元数据,采用键值对格式,在身份验证过程中传输。例如,audience 指定访问令牌的预期受众,指示令牌的接收者。
4
OAuth2 令牌端点的 URL,Collector 请求访问令牌。
5
范围定义客户端请求的特定权限或访问级别。
6
令牌客户端的传输层安全性 (TLS) 设置,用于在请求令牌时建立安全连接。
7
当设置为 true 时,将 Collector 配置为使用不安全或非验证的 TLS 连接来调用配置的令牌端点。
8
用于在 TLS 握手过程中验证服务器证书的证书颁发机构 (CA) 文件的路径。
9
如果需要,客户端必须用来向 OAuth2 服务器验证自己的客户端证书文件的路径。
10
身份验证所需的客户端私钥文件的路径。
11
为令牌客户端的请求设置超时。
12
您可以将验证器配置分配给 OTLP 导出器。

6.3. File Storage Extension

File Storage Extension 支持 trace、metrics 和 logs。此扩展可保留本地文件系统的状态。此扩展会保留基于 HTTP 和 gRPC 协议的 OpenTelemetry 协议 (OTLP) 导出器的发送队列。此扩展需要对目录的读和写访问权限。此扩展可以使用默认目录,但默认目录必须已存在。

重要

File Storage Extension 只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

OpenTelemetry Collector 自定义资源带有配置的文件存储扩展,它会保留 OTLP 发送队列

# ...
  config:
    extensions:
      file_storage/all_settings:
        directory: /var/lib/otelcol/mydir 
1

        timeout: 1s 
2

        compaction:
          on_start: true 
3

          directory: /tmp/ 
4

          max_transaction_size: 65_536 
5

        fsync: false 
6


    exporters:
      otlp:
        sending_queue:
          storage: file_storage/all_settings 
7


    service:
      extensions: [file_storage/all_settings] 
8

      pipelines:
        traces:
          receivers: [otlp]
          exporters: [otlp]
# ...
Copy to Clipboard Toggle word wrap

1
指定存储遥测数据的目录。
2
指定打开存储文件的超时时间间隔。
3
在 Collector 启动时启动压缩。如果没有指定,则默认为 false
4
指定紧凑器存储遥测数据的目录。
5
定义压缩事务的最大大小。设置为零将忽略事务大小。如果省略,则默认为 65536 字节。
6
设置后,强制数据库在每次写入操作后调用 fsync。这有助于,在数据库进程被中断时确保数据库的完整性,但这会以牺牲性能为代价。
7
缓冲本地文件系统中的 OTLP Exporter 数据。
8
启动由 Collector 扩展的文件存储。

6.4. OIDC Auth Extension

OIDC Auth Extension 使用 OpenID Connect (OIDC) 协议向接收器验证传入的请求。它针对签发者验证授权标头中的 ID 令牌,并更新传入请求的身份验证上下文。

重要

OIDC Auth Extension 只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

OpenTelemetry Collector 自定义资源带有配置的 OIDC Auth Extension

# ...
  config:
    extensions:
      oidc:
        attribute: authorization 
1

        issuer_url: https://example.com/auth/realms/opentelemetry 
2

        issuer_ca_path: /var/run/tls/issuer.pem 
3

        audience: otel-collector 
4

        username_claim: email 
5

    receivers:
      otlp:
        protocols:
          grpc:
            auth:
              authenticator: oidc
    exporters:
      debug: {}
    service:
      extensions: [oidc]
      pipelines:
        traces:
          receivers: [otlp]
          exporters: [debug]
# ...
Copy to Clipboard Toggle word wrap

1
包含 ID 令牌的标头名称。默认名称是 authorization
2
OIDC 供应商的基本 URL。
3
可选:签发者 CA 证书的路径。
4
令牌的受众。
5
包含用户名的声明名称。默认名为 sub

6.5. Jaeger Remote Sampling Extension

Jaeger Remote Sampling Extension 在 Jaeger 的远程抽样 API 后启用服务抽样策略。您可以配置此扩展,将请求代理到后备远程抽样服务器,如 Jaeger 收集器关闭管道或从本地文件系统到静态 JSON 文件。

重要

Jaeger Remote Sampling Extension 只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

OpenTelemetry Collector 自定义资源带有配置的 Jaeger Remote Sampling Extension

# ...
  config:
    extensions:
      jaegerremotesampling:
        source:
          reload_interval: 30s 
1

          remote:
            endpoint: jaeger-collector:14250 
2

          file: /etc/otelcol/sampling_strategies.json 
3


    receivers:
      otlp:
        protocols:
          http: {}

    exporters:
      debug: {}

    service:
      extensions: [jaegerremotesampling]
      pipelines:
        traces:
          receivers: [otlp]
          exporters: [debug]
# ...
Copy to Clipboard Toggle word wrap

1
抽样配置更新的时间间隔。
2
用于访问 Jaeger 远程抽样策略供应商的端点。
3
JSON 格式包含抽样策略配置的本地文件的路径。

Jaeger Remote Sampling 策略文件示例

{
  "service_strategies": [
    {
      "service": "foo",
      "type": "probabilistic",
      "param": 0.8,
      "operation_strategies": [
        {
          "operation": "op1",
          "type": "probabilistic",
          "param": 0.2
        },
        {
          "operation": "op2",
          "type": "probabilistic",
          "param": 0.4
        }
      ]
    },
    {
      "service": "bar",
      "type": "ratelimiting",
      "param": 5
    }
  ],
  "default_strategy": {
    "type": "probabilistic",
    "param": 0.5,
    "operation_strategies": [
      {
        "operation": "/health",
        "type": "probabilistic",
        "param": 0.0
      },
      {
        "operation": "/metrics",
        "type": "probabilistic",
        "param": 0.0
      }
    ]
  }
}
Copy to Clipboard Toggle word wrap

6.6. Performance Profiler Extension

Performance Profiler Extension 启用 Go net/http/pprof 端点。开发人员使用此扩展来收集性能配置集并调查服务的问题。

重要

Performance Profiler 扩展只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

OpenTelemetry Collector 自定义资源带有配置的 Performance Profiler Extension

# ...
  config:
    extensions:
      pprof:
        endpoint: localhost:1777 
1

        block_profile_fraction: 0 
2

        mutex_profile_fraction: 0 
3

        save_to_file: test.pprof 
4


    receivers:
      otlp:
        protocols:
          http: {}

    exporters:
      debug: {}

    service:
      extensions: [pprof]
      pipelines:
        traces:
          receivers: [otlp]
          exporters: [debug]
# ...
Copy to Clipboard Toggle word wrap

1
此扩展侦听的端点。使用 localhost: 使其仅在本地可用; ":" 使其在所有网络接口上可用。默认值为 localhost:1777
2
设置要配置集的一小部分阻塞事件。要禁用性能分析,请将其设置为 0 或负整数。请参阅 runtime 软件包 的文档。默认值为 0
3
设置要配置集的几部分 mutex 争用事件。要禁用性能分析,请将其设置为 0 或负整数。请参阅 runtime 软件包的文档。默认值为 0
4
要保存 CPU 配置集的文件的名称。分析会在 Collector 启动时启动。在 Collector 终止时,配置集被保存到 文件中。

6.7. Health Check Extension

Health Check Extension 提供了一个 HTTP URL,用于检查 OpenTelemetry Collector 的状态。您可以将此扩展用作 OpenShift 上的存活度和就绪度探测。

重要

健康检查扩展只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

OpenTelemetry Collector 自定义资源带有配置的 Health Check Extension

# ...
  config:
    extensions:
      health_check:
        endpoint: "0.0.0.0:13133" 
1

        tls: 
2

          ca_file: "/path/to/ca.crt"
          cert_file: "/path/to/cert.crt"
          key_file: "/path/to/key.key"
        path: "/health/status" 
3

        check_collector_pipeline: 
4

          enabled: true 
5

          interval: "5m" 
6

          exporter_failure_threshold: 5 
7


    receivers:
      otlp:
        protocols:
          http: {}

    exporters:
      debug: {}

    service:
      extensions: [health_check]
      pipelines:
        traces:
          receivers: [otlp]
          exporters: [debug]
# ...
Copy to Clipboard Toggle word wrap

1
发布健康检查状态的目标 IP 地址。默认值为 0.0.0.0:13133
2
TLS 服务器端配置。定义 TLS 证书的路径。如果省略,则禁用 TLS。
3
健康检查服务器的路径。默认值为 /
4
Collector 管道健康检查的设置。
5
启用 Collector 管道健康检查。默认值为 false
6
检查失败次数的时间间隔。默认值为 5m
7
在容器仍标记为健康前,失败次数的阈值。默认值为 5

6.8. zPages Extension

zPages 扩展提供了一个 HTTP 端点,提供实时数据来实时调试检测组件。您可以使用此扩展进行进程诊断,并深入了解 trace 和 metrics,而无需依赖外部的后端。使用这个扩展,您可以通过观察提供的端点上的诊断信息来监控和排除 OpenTelemetry Collector 和相关组件的行为。

重要

zPages 扩展只是一个技术预览功能。技术预览功能不受红帽产品服务等级协议(SLA)支持,且功能可能并不完整。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。

有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围

OpenTelemetry Collector 自定义资源带有配置的 zPages Extension

# ...
  config:
    extensions:
      zpages:
        endpoint: "localhost:55679" 
1


    receivers:
      otlp:
        protocols:
          http: {}
    exporters:
      debug: {}

    service:
      extensions: [zpages]
      pipelines:
        traces:
          receivers: [otlp]
          exporters: [debug]
# ...
Copy to Clipboard Toggle word wrap

1
指定提供 zPages 扩展的 HTTP 端点。默认值为 localhost:55679
重要

访问 HTTP 端点需要端口转发,因为红帽构建的 OpenTelemetry Operator 不会公开此路由。

您可以通过运行以下 oc 命令启用端口转发:

$ oc port-forward pod/$(oc get pod -l app.kubernetes.io/name=instance-collector -o=jsonpath='{.items[0].metadata.name}') 55679
Copy to Clipboard Toggle word wrap

Collector 为诊断提供以下 zPages:

ServiceZ
显示 Collector 服务和到以下 zPages 的链接的概述:PipelineZExtensionZFeatureZ。本页还显示有关构建版本和运行时的信息。此页面的 URL 示例是 http://localhost:55679/debug/servicez
PipelineZ
显示有关 Collector 中活跃管道的详细信息。此页面显示管道类型,无论数据是否被修改,以及每个管道的相关接收器、处理器和导出器。此页面的 URL 示例是 http://localhost:55679/debug/pipelinez
ExtensionZ
显示 Collector 中当前活跃的扩展。此页面的 URL 示例是 http://localhost:55679/debug/extensionz
FeatureZ
显示 Collector 中启用的功能门及其状态和描述。此页面的 URL 示例是 http://localhost:55679/debug/featurez
TraceZ
显示延迟,按 span 分类。可用时间范围包括 0 µs, 10 µs, 100 µs, 1 ms, 10 ms, 100 ms, 1 s, 10 s, 1 m.此页面还允许快速检查错误示例。此页面的 URL 示例是 http://localhost:55679/debug/tracez

法律通告

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
返回顶部