Processors.regex.tag_rename not keeping original tag

I’m using Telegraf to collect data from a network device using the gnmi input plugin.

I’m receiving data like this:

  "fields": {
    "lsps/constrained_path/tunnels/tunnel/state/counters/byteRate": 0,
    "lsps/constrained_path/tunnels/tunnel/state/counters/bytes": 1234,
    "lsps/constrained_path/tunnels/tunnel/state/counters/packetRate": 0,
    "lsps/constrained_path/tunnels/tunnel/state/counters/packets": 10
  "name": "lsps",
  "tags": {
    "/mpls/lsps/constrained-path/tunnels/tunnel/state/counters/name": "oc-123456",
    "component": "aftd-trio",
    "component_id": "1",
    "host": "gnmi-deployment-telegraf-agent",
    "interface-name": "device1-device2-0-XE",
    "path": "/mpls/lsps/constrained-path/tunnels/tunnel/state/counters",
    "sub_component_id": "0",
    "source": ""
  "timestamp": 1707409986

This is my telegraf.conf:

  round_interval = true
  metric_batch_size = 1000
  metric_buffer_limit = 500000
  flush_interval = "10s"
  debug = false
  quiet = false
  hostname = "telegraf-agent"
  omit_hostname = false

  addresses = [""]
  username = "$user"
  password = "$password"
  encoding = "proto"
  redial = "10s"
  enable_tls = true
  tls_ca = "/etc/telegraf/router_ca.pem"
  insecure_skip_verify = true
  vendor_specific = ["juniper_header"]
    optics = "/interfaces"
    opticsVendor = "/components"
    lsps = "/mpls"
      name = "lsps"
      origin = "openconfig-interfaces"
      path = "/junos/services/label-switched-path/usage/"
      subscription_mode = "sample"
      sample_interval = "60s"

      tag = "name"
      dest = "interface-name"

namepass = ["lsps"]
    pattern = "source"
    replacement = "system-id"
    result_key = "keep"

  files = ["stdout"]

I have specified the result_key = "keep", because I want to keep the original tag, however, the original tag source is not coming through. Only the replacement tag system-id is coming through and is assigned the value of source. I’m expecting to see both source and system-id come through as tags with the same value.

I have replicated this on Docker Telegraf Alpine versions 1.28.5 and 1.29.3.

Well as the documentation says:

Optionally, the result_key can be set to either overwrite or keep (default) to control the behavior in case the target tag/field already exists

This controls what the plugin does if the rename target already exists!

You should use

  namepass = ["lsps"]
    key = "source"
    result_key = "system-id"
    pattern = "(.*)"
    replacement = "${1}"


1 Like