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

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

Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2026 Red Hat
返回顶部