You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用transformprocessor通过OTTL为Span添加Span Event?

使用Transform Processor添加Span Event的正确配置方式

要通过OTTL的transformprocessor给现有Span添加Span Event,关键是构造符合SpanEvent类型规范的对象——必须包含name和timestamp字段(attributes为可选)。你之前的配置缺少必需的timestamp字段,导致无法正确执行。

正确的配置示例如下:

processors:
  transform/test:
    trace_statements:
      - context: span
        statements:
          - append(events, [{name: "new-span", timestamp: time_now(), attributes: {}}]) where attributes["condition"] != nil

关键说明:

  • timestamp字段:为必填项,使用OTTL内置的time_now()函数可获取当前时间作为事件时间戳,也可以传入符合格式的固定时间值。
  • attributes字段:可选配置,若需要给事件添加自定义属性,直接在该字段下添加键值对即可,比如attributes: {event_type: "custom", status: "success"}。
  • 条件判断:保留你原有的where attributes["condition"] != nil逻辑,仅当Span存在指定属性时才触发事件添加操作。

内容的提问来源于stack exchange,提问作者Mike

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 18:13:09