Add/set key/value

The Add/set key/value processing rule adds the same key/value pair to every record that passes through your pipeline. If a record contains a matching key, this rule overwrites that key's associated value with the value you specify.

Configuration

  • Key: the key you'd like to add to each record. You can use record accessor syntax to add or overwrite keys nested inside a parent object.
  • Value: the value to associate with your key. This value will be identical for every instance of key.

Example usage

Using the add/set key/value rule lets you enrich events with identifying information, like the source from which they originate or their associated user action.

For example, given this sample log data:

{"timestamp":"2023-03-28T09:08:41.64283645Z","user_id":3,"page_id":30,"action":"purchase", "source": "storefront"}
{"timestamp":"2023-03-28T09:08:42.643343109Z","user_id":4,"page_id":10,"action":"purchase", "source": "storefront"}
{"timestamp":"2023-03-28T09:08:48.643600498Z","user_id":1,"page_id":50,"action":"click"}
{"timestamp":"2023-03-28T09:08:50.643773688Z","user_id":5,"page_id":40,"action":"purchase", "source": "storefront"}
{"timestamp":"2023-03-28T09:08:51.643932272Z","user_id":1,"page_id":30,"action":"purchase", "source": "storefront"}
{"timestamp":"2023-03-28T09:08:56.644080944Z","user_id":2,"page_id":40,"action":"click"}
{"timestamp":"2023-03-28T09:09:03.64425954Z","user_id":3,"page_id":30,"action":"click"}
{"timestamp":"2023-03-28T09:09:03.644317046Z","user_id":1,"page_id":20,"action":"view"}
{"timestamp":"2023-03-28T09:09:10.64447719Z","user_id":2,"page_id":50,"action":"purchase", "source": "storefront"}
{"timestamp":"2023-03-28T09:09:17.644810963Z","user_id":2,"page_id":10,"action":"view"}
{"timestamp":"2023-03-28T09:09:20.644994805Z","user_id":1,"page_id":50,"action":"view"}

A processing rule to add the key source and the value acme-storefront yields the following result:

{"action":"purchase","page_id":30,"source":"acme-wholesale","timestamp":"2023-03-28T09:08:41.64283645Z","user_id":3}
{"action":"purchase","page_id":10,"source":"acme-wholesale","timestamp":"2023-03-28T09:08:42.643343109Z","user_id":4}
{"action":"click","page_id":50,"source":"acme-wholesale","timestamp":"2023-03-28T09:08:48.643600498Z","user_id":1}
{"action":"purchase","page_id":40,"source":"acme-wholesale","timestamp":"2023-03-28T09:08:50.643773688Z","user_id":5}
{"action":"purchase","page_id":30,"source":"acme-wholesale","timestamp":"2023-03-28T09:08:51.643932272Z","user_id":1}
{"action":"click","page_id":40,"source":"acme-wholesale","timestamp":"2023-03-28T09:08:56.644080944Z","user_id":2}
{"action":"click","page_id":30,"source":"acme-wholesale","timestamp":"2023-03-28T09:09:03.64425954Z","user_id":3}
{"action":"view","page_id":20,"source":"acme-wholesale","timestamp":"2023-03-28T09:09:03.644317046Z","user_id":1}
{"action":"purchase","page_id":50,"source":"acme-wholesale","timestamp":"2023-03-28T09:09:10.64447719Z","user_id":2}
{"action":"view","page_id":10,"source":"acme-wholesale","timestamp":"2023-03-28T09:09:17.644810963Z","user_id":2}
{"action":"view","page_id":50,"source":"acme-wholesale","timestamp":"2023-03-28T09:09:20.644994805Z","user_id":1}