Skip to content

Commit 1808890

Browse files
angelampcostasoheiokamoto
authored andcommitted
[Logs] Custom fields updates (cloudflare#22266)
* Custom fields updates * Update src/content/docs/logs/reference/custom-fields.mdx Co-authored-by: Sohei Okamoto <[email protected]> --------- Co-authored-by: Sohei Okamoto <[email protected]>
1 parent df7edcc commit 1808890

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

src/content/docs/logs/reference/custom-fields.mdx

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,50 @@ Perform the following steps to create the rule:
189189
}
190190
```
191191

192+
#### Record duplicate response header values
193+
194+
Some headers sent from the origin — such as `set-cookie` — may have multiple values that you want to capture. You can use the Rulesets API to specify which headers should have all their values logged.
195+
196+
```bash
197+
curl --request PUT \
198+
--url https://api.cloudflare.com/client/v4/zones/{{ZONE_TAG}}/rulesets/{{RULE_ID}} \
199+
--header 'content-type: application/json' \
200+
--header 'x-auth-email: {{EMAIL}}' \
201+
--header 'x-auth-key: {{API_KEY}}' \
202+
--data '{
203+
"rules": [
204+
{
205+
"action": "log_custom_field",
206+
"expression": "true",
207+
"description": "Set Logpush custom fields for HTTP requests",
208+
"action_parameters": {
209+
"response_fields": [
210+
{"name": "set-cookie", "preserve_duplicates": true}
211+
]
212+
}
213+
}
214+
]
215+
}'
216+
```
217+
218+
Note that `preserve_duplicates` applies to both `response_fields` and `raw_response_fields`. If there are no transform rules that affect a header, including `preserve_duplicates` in either `response_fields` or `raw_response_fields` should achieve the same result.
219+
220+
In this example, all values of the `set-cookie` headers will be logged. They will appear as an array of string values under `ResponseFields`, for example:
221+
222+
```json
223+
{
224+
225+
“ResponseFields”: {
226+
“set-cookie”: [“name1=val1”, “name2=val2”...]
227+
}
228+
}
229+
```
230+
231+
You can use a worker or custom logic at your logpush destination to extract these values.
232+
192233
### 2. Include the custom fields in your Logpush job
193234

194-
Next, include `Cookies`, `RequestHeaders`, and/or `ResponseHeaders`, depending on your custom field configuration, in the list of fields of the `output_options` job parameter when creating or updating a job. The logs will contain the configured custom fields and their values in the request/response.
235+
Next, include `Cookies`, `RequestHeaders`, `ResponseHeaders`, and/or `ResponseFields`, depending on your custom field configuration, in the list of fields of the `output_options` job parameter when creating or updating a job. The logs will contain the configured custom fields and their values in the request/response.
195236

196237
For example, consider the following request that creates a job that includes custom fields:
197238

@@ -230,6 +271,5 @@ If you are a Cloudflare Access user, as of March 2022 you have to manually add t
230271
## Limitations
231272

232273
- Custom fields allow 100 headers per field type — this applies separately to `request_fields`, `transformed_request_fields`, `response_fields`, `raw_response_fields`, and `cookie_fields`.
233-
- For headers which may be included multiple times (for example, the `set-cookie` response header), a custom field will only log the first instance of the header. Subsequent headers of the same type will be ignored.
234274
- The request header `Range` is currently not supported by Custom Fields.
235275
- Transformed and raw values for request and response headers are available only via the API and cannot be set through the UI.

0 commit comments

Comments
 (0)