Export logs to multiple destinations with different fields
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:
-
Tag -- Add a
tagfield to the log that lists all destination names. -
Split -- Split the log into separate copies, one per destination.
-
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
For more information about the data transformation functions used in this example, see Function overview.
The following rules implement the tag-split-route pattern:
-
Call
e_setto add atagfield with the valuetarget1, target2. -
Call
e_splitto split the log into two copies based on thetagfield. One copy containstag: target1, the other containstag: target2. -
For the
tag: target1copy, calle_composeinsidee_ifto drop fields f1 and f2, then send the result to target1 withe_output. Becausee_outputterminates processing for that copy, subsequent rules do not apply to it. -
For the
tag: target2copy (which continues to the next rule), drop fields f3 and f4, then send the result to target2 withe_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")