Export logs to multiple destinations with different fields

Updated at:

Route a single log entry to multiple storage destinations, with each destination receiving only the fields it needs. Use the tag-split-route pattern in data transformation to create independent copies of the original log before modifying fields.

Scenario

A raw log contains fields f1, f2, f3, f4, and f5. Each destination requires a different subset of these fields:

  • target1: Exclude f1 and f2. Retain f3, f4, and f5.

  • target2: Exclude f3 and f4. Retain f1, f2, and f5.

Solution overview

Export the same log to multiple destinations with different field sets by applying the tag-split-route pattern:

  1. Tag -- Add a tag field to the log that lists all destination names.

  2. Split -- Split the log into separate copies, one per destination.

  3. Route -- For each copy, drop the unwanted fields and send the log to the corresponding destination.

This pattern creates independent copies of the original log before applying any field-level modifications. Each destination receives exactly the fields it requires without affecting the other copies.

Configuration example

Raw log

__time__ : 1591754815
f1: GET
f2: https
f3: aliyun
f4: 200
f5: standard

Transformation rules

Note

For more information about the data transformation functions used in this example, see Function overview.

The following rules implement the tag-split-route pattern:

  1. Call e_set to add a tag field with the value target1, target2.

  2. Call e_split to split the log into two copies based on the tag field. One copy contains tag: target1, the other contains tag: target2.

  3. For the tag: target1 copy, call e_compose inside e_if to drop fields f1 and f2, then send the result to target1 with e_output. Because e_output terminates processing for that copy, subsequent rules do not apply to it.

  4. For the tag: target2 copy (which continues to the next rule), drop fields f3 and f4, then send the result to target2 with e_output.

e_set("tag", "target1, target2")
e_split("tag")
e_if(e_search("tag==target1"), e_compose(e_drop_fields("f1", "f2", regex=False), e_output("target1")))
e_drop_fields("f3", "f4", regex=False)
e_output("target2")

Result for target1

__time__ : 1591754815
f3: aliyun
f4: 200
f5: standard

Result for target2

__time__ : 1591754815
f1: GET
f2: https
f5: standard

Incorrect configuration

If you use the following transformation rules, the output to target1 meets the requirements. However, the output from target1 is fed directly to target2, causing the logs in target2 to lose the f1 and f2 fields.

e_drop_fields("f1", "f2", regex=False)
e_coutput("target1")
e_drop_fields("f3", "f4", regex=False)
e_output("target2")