OpenTelemetry
  x/otel组件:v0.28.0+ OpenTelemetry客户端组件,用于记录各种指标数据,通过OTLP协议发送到后端系统(如:Prometheus、Datadog、InfluxDB等)。
需要额外引入扩展库:rulego-components (opens new window)
# 配置
| 字段 | 类型 | 说明 | 默认值 | 
|---|---|---|---|
| server | string | OTLP后端系统地址 | localhost:4318 | 
| protocol | string | 传输协议,支持 grpc 和 http |  http | 
| metricExpr | string | 动态指标配置表达式,支持从消息负荷中获取指标配置 | ${msg.metrics} | 
| metrics | MetricConfig[] | 静态指标配置列表 | 无 | 
# MetricConfig 指标配置
| 字段 | 类型 | 说明 | 示例值 | 
|---|---|---|---|
| metricName | string | 指标名称 | http_requests | 
| description | string | 指标描述 | HTTP请求数 | 
| unit | string | 指标单位(如:1, s, ms, B, %等) | 1 | 
| opType | string | 操作类型:COUNTER, GAUGE, HISTOGRAM |  COUNTER | 
| value | string | 指标值表达式,支持动态取值 | ${msg.value} | 
| labels | string | 标签表达式,支持动态取值,格式为JSON对象 | ${msg.labels} | 
# 指标类型说明
- COUNTER: 计数器,只增不减的累计值(如:请求总数)
 - GAUGE: 仪表盘,可增可减的即时值(如:CPU使用率)
 - HISTOGRAM: 直方图,用于统计数值分布(如:请求延迟分布)
 
# 配置示例
{
  "id": "otel1",
  "type": "x/otel",
  "configuration": {
    "server": "localhost:4317",
    "protocol": "grpc",
    "metricExpr": "${msg.metrics}",
    "metrics": [
      {
        "metricName": "http_requests",
        "description": "HTTP requests made",
        "unit": "1",
        "opType": "COUNTER",
        "value": "${msg.value}",
        "labels": "${msg.labels}"
      }
    ]
  }
}
 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 动态指标数据格式
通过metricExpr表达式从消息负荷中获取的指标数据格式示例:
{
  "metrics": [
    {
      "metricName": "http_requests",
      "description": "HTTP requests made",
      "unit": "1",
      "opType": "COUNTER",
      "value": 10,
      "labels": {
        "method": "GET",
        "path": "/api/v1/data"
      }
    }
  ]
}
 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Relation Type
- Success: 执行成功,把消息发送到
Success链 - Failure: 执行失败,把消息发送到
Failure链 
# 执行结果
不改变消息负荷值
在 GitHub 上编辑此页  (opens new window)
  上次更新: 2025/09/03, 10:09:04