|
| 1 | +# Content Modifier |
| 2 | + |
| 3 | +The **content_modifier** processor allows you to manipulate the metadata/attributes and content of Logs and Traces. |
| 4 | + |
| 5 | +Similar to the functionality exposed by filters, this processor presents a unified mechanism to perform such operations for data manipulation. The most significant difference is that processors perform better than filters, and when chaining them, there are no encoding/decoding performance penalties. |
| 6 | + |
| 7 | +Note that processors and this specific component can only be enabled using the new YAML configuration format. Classic mode configuration format doesn't support processors. |
| 8 | + |
| 9 | +## Configuration Parameters |
| 10 | + |
| 11 | +| Key | Description | |
| 12 | +| :---------- | :--- | |
| 13 | +| action | Define the operation to run on the target content. This field is mandatory; for more details about the actions available, check the table below. | |
| 14 | +| context | Specify which component of the Telemetry type will be affected. When processing Logs the following contexts are available: `attributes` or `body`. When processing Traces the following contexts are available: `span_name`, `span_kind`, `span_status`, `span_attributes`. | |
| 15 | +| key | Specify the name of the key that will be used to apply the modification. | |
| 16 | +| value | Based on the action type, `value` might required and represent different things. Check the detailed information for the specific actions. | |
| 17 | +| pattern | Defines a regular expression pattern. This property is only used by the `extract` action. | |
| 18 | +| converted_type | Define the data type to perform the conversion, the available options are: `string`, `boolean`, `int` and `double` . | |
| 19 | + |
| 20 | +### Actions |
| 21 | + |
| 22 | +The actions specify the type of operation to run on top of a specific key or content from a Log or a Trace. The following actions are available: |
| 23 | + |
| 24 | +| Action | Description | |
| 25 | +| ------- | ------------------------------------------------------------ | |
| 26 | +| insert | Insert a new key with a value into the target context. The `key` and `value` parameters are required. | |
| 27 | +| upsert | Given a specific key with a value, the `upsert` operation will try to update the value of the key. If the key does not exist, the key will be created. The `key` and `value` parameters are required. | |
| 28 | +| delete | Delete a key from the target context. The `key` parameter is required. | |
| 29 | +| rename | Change the name of a key. The `value` set in the configuration will represent the new name. The `key` and `value` parameters are required. | |
| 30 | +| hash | Replace the key value with a hash generated by the SHA-256 algorithm, the binary value generated is finally set as an hex string representation. The `key` parameter is required. | |
| 31 | +| extract | Allows to extact the value of a single key as a list of key/value pairs. This action needs the configuration of a regular expression in the `pattern` property . The `key` and `pattern` parameters are required. For more details check the examples below. | |
| 32 | +| convert | Convert the data type of a key value. The `key` and `converted_type` parameters are required. | |
| 33 | + |
| 34 | +#### Insert example |
| 35 | + |
| 36 | +The following example appends the key `color` with the value `blue` to the log stream. |
| 37 | + |
| 38 | +```yaml |
| 39 | +pipeline: |
| 40 | + inputs: |
| 41 | + - name: dummy |
| 42 | + dummy: '{"key1": "123.4"}' |
| 43 | + |
| 44 | + processors: |
| 45 | + logs: |
| 46 | + - name: content_modifier |
| 47 | + action: insert |
| 48 | + key: "color" |
| 49 | + value: "blue" |
| 50 | + outputs: |
| 51 | + - name : stdout |
| 52 | + match: '*' |
| 53 | + format: json_lines |
| 54 | +``` |
| 55 | +
|
| 56 | +#### Upsert example |
| 57 | +
|
| 58 | +Update the value of `key1` and insert `key2`: |
| 59 | + |
| 60 | +```yaml |
| 61 | +pipeline: |
| 62 | + inputs: |
| 63 | + - name: dummy |
| 64 | + dummy: '{"key1": "123.4"}' |
| 65 | +
|
| 66 | + processors: |
| 67 | + logs: |
| 68 | + - name: content_modifier |
| 69 | + action: upsert |
| 70 | + key: "key1" |
| 71 | + value: "5678" |
| 72 | +
|
| 73 | + - name: content_modifier |
| 74 | + action: upsert |
| 75 | + key: "key2" |
| 76 | + value: "example" |
| 77 | + |
| 78 | + outputs: |
| 79 | + - name : stdout |
| 80 | + match: '*' |
| 81 | + format: json_lines |
| 82 | +
|
| 83 | +``` |
| 84 | + |
| 85 | + |
| 86 | +#### Delete example |
| 87 | + |
| 88 | +Delete `key2` from the stream: |
| 89 | + |
| 90 | +```yaml |
| 91 | +pipeline: |
| 92 | + inputs: |
| 93 | + - name: dummy |
| 94 | + dummy: '{"key1": "123.4", "key2": "example"}' |
| 95 | +
|
| 96 | + processors: |
| 97 | + logs: |
| 98 | + - name: content_modifier |
| 99 | + action: delete |
| 100 | + key: "key2" |
| 101 | + |
| 102 | + outputs: |
| 103 | + - name : stdout |
| 104 | + match: '*' |
| 105 | + format: json_lines |
| 106 | +``` |
| 107 | + |
| 108 | +#### Rename example |
| 109 | + |
| 110 | +Change the name of `key2` to `test`: |
| 111 | + |
| 112 | +```yaml |
| 113 | +pipeline: |
| 114 | + inputs: |
| 115 | + - name: dummy |
| 116 | + dummy: '{"key1": "123.4", "key2": "example"}' |
| 117 | +
|
| 118 | + processors: |
| 119 | + logs: |
| 120 | + - name: content_modifier |
| 121 | + action: rename |
| 122 | + key: "key2" |
| 123 | + value: "test" |
| 124 | +
|
| 125 | + outputs: |
| 126 | + - name : stdout |
| 127 | + match: '*' |
| 128 | + format: json_lines |
| 129 | +``` |
| 130 | + |
| 131 | +#### Hash example |
| 132 | + |
| 133 | +Apply the SHA-256 algorithm for the value of the key `password`: |
| 134 | + |
| 135 | +```yaml |
| 136 | +pipeline: |
| 137 | + inputs: |
| 138 | + - name: dummy |
| 139 | + dummy: '{"username": "bob", "password": "12345"}' |
| 140 | +
|
| 141 | + processors: |
| 142 | + logs: |
| 143 | + - name: content_modifier |
| 144 | + action: hash |
| 145 | + key: "password" |
| 146 | +
|
| 147 | + outputs: |
| 148 | + - name : stdout |
| 149 | + match: '*' |
| 150 | + format: json_lines |
| 151 | +``` |
| 152 | + |
| 153 | + |
| 154 | + |
| 155 | +#### Extract example |
| 156 | + |
| 157 | +By using a domain address, perform a extraction of the components of it as a list of key value pairs: |
| 158 | + |
| 159 | +```yaml |
| 160 | +pipeline: |
| 161 | + inputs: |
| 162 | + - name: dummy |
| 163 | + dummy: '{"http.url": "https://fluentbit.io/docs?q=example"}' |
| 164 | +
|
| 165 | + processors: |
| 166 | + logs: |
| 167 | + - name: content_modifier |
| 168 | + action: extract |
| 169 | + key: "http.url" |
| 170 | + pattern: ^(?<http_protocol>https?):\/\/(?<http_domain>[^\/\?]+)(?<http_path>\/[^?]*)?(?:\?(?<http_query_params>.*))? |
| 171 | + |
| 172 | + outputs: |
| 173 | + - name : stdout |
| 174 | + match: '*' |
| 175 | + format: json_lines |
| 176 | +``` |
| 177 | + |
| 178 | + |
| 179 | + |
| 180 | +#### Convert example |
| 181 | + |
| 182 | +Both keys in the example are strings. Convert the `key1` to a double/float type and `key2` to a boolean: |
| 183 | + |
| 184 | +```yaml |
| 185 | +pipeline: |
| 186 | + inputs: |
| 187 | + - name: dummy |
| 188 | + dummy: '{"key1": "123.4", "key2": "true"}' |
| 189 | +
|
| 190 | + processors: |
| 191 | + logs: |
| 192 | + - name: content_modifier |
| 193 | + action: convert |
| 194 | + key: key1 |
| 195 | + converted_type: int |
| 196 | +
|
| 197 | + - name: content_modifier |
| 198 | + action: convert |
| 199 | + key: key2 |
| 200 | + converted_type: boolean |
| 201 | + |
| 202 | + outputs: |
| 203 | + - name : stdout |
| 204 | + match: '*' |
| 205 | + format: json_lines |
| 206 | +``` |
0 commit comments