Skip to content

Commit c9de6f8

Browse files
Updates Custom fields (#21740)
1 parent 963760e commit c9de6f8

File tree

1 file changed

+33
-11
lines changed

1 file changed

+33
-11
lines changed

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

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,23 @@ sidebar:
66

77
---
88

9-
You can configure custom fields — selected from the list of HTTP request headers, HTTP response headers, and cookies — to include in Logpush log entries of a zone. Custom fields are only available for the [HTTP requests dataset](/logs/reference/log-fields/zone/http_requests/). Once configured, these custom fields will be enabled for all the Logpush jobs in the zone that use the HTTP requests dataset and include the request headers, response headers, or cookie fields.
9+
The HTTP requests dataset includes most standard log information by default. However, if you need to capture additional request or response headers or cookies, you can use custom fields to tailor the logs to your specific needs
10+
11+
Custom fields are configured per zone and, once set up, are enabled for all Logpush jobs in that zone that use the HTTP requests dataset and include the request headers, response headers, or cookie fields. You can log these fields in their raw form or as transformed values.
12+
13+
:::note[By default:]
14+
- **Request headers** are logged as **raw values**.
15+
- **Response headers** are logged as **transformed values**.
16+
:::
17+
18+
This default behavior can be changed. You can configure either request or response headers to be logged as raw or transformed, depending on your needs - but not both for the same header.
1019

1120
Custom fields can be enabled via API or the Cloudflare dashboard.
1221

22+
:::note
23+
Custom fields are only available for the [HTTP requests dataset](/logs/reference/log-fields/zone/http_requests/).
24+
:::
25+
1326
## Enable custom rules via API
1427

1528
Use the [Rulesets API](/ruleset-engine/rulesets-api/) to create a rule that configures custom fields. For more information on concepts like phases, rulesets, and rules, as well as the available API operations, refer to the [Ruleset Engine](/ruleset-engine/) documentation.
@@ -27,20 +40,22 @@ The `action_parameters` object that you must include in the rule that configures
2740

2841
```json
2942
"action_parameters": {
43+
//select raw (default) or transformed request header
3044
"request_fields": [
31-
{ "name": "<http_request_header_name_1_in_lower_case>" },
32-
{ "name": "<http_request_header_name_2_in_lower_case>" },
33-
// ...
45+
{ "name": "<http_request_header_raw>" }
3446
],
47+
"transformed_request_fields": [
48+
{ "name": "<http_request_header_transformed>" }
49+
],
50+
//select raw or transformed (default) response header
3551
"response_fields": [
36-
{ "name": "<http_response_header_name_1_in_lower_case>" },
37-
{ "name": "<http_response_header_name_2_in_lower_case>" },
38-
// ...
52+
{ "name": "<http_response_header_transformed>" }
53+
],
54+
"raw_response_fields": [
55+
{ "name": "<http_response_header_raw>" }
3956
],
4057
"cookie_fields": [
41-
{ "name": "<cookie_name_1>" },
42-
{ "name": "<cookie_name_2>" },
43-
// ...
58+
{ "name": "<cookie_name>" }
4459
]
4560
}
4661
```
@@ -51,6 +66,7 @@ Ensure that your rule definition complies with the following:
5166
* You must enter HTTP request and response header names in lower case.
5267
* Cookie names are case sensitive — you must enter cookie names with the same capitalization they have in the HTTP request.
5368
* You must set the rule expression to `true`.
69+
* You can only log raw or transformed values for either request or response headers but not both for the same header.
5470

5571
Perform the following steps to create the rule:
5672

@@ -101,11 +117,14 @@ Perform the following steps to create the rule:
101117
"request_fields": [
102118
{ "name": "content-type" },
103119
{ "name": "x-forwarded-for" },
104-
{ "name": "host" }
105120
],
121+
"transformed_request_fields": [
122+
{"name": "host"}
123+
],
106124
"response_fields": [
107125
{ "name": "server" },
108126
{ "name": "content-type" },
127+
"raw_response_fields": [
109128
{ "name": "allow" }
110129
],
111130
"cookie_fields": [
@@ -138,11 +157,13 @@ Perform the following steps to create the rule:
138157
"request_fields": [
139158
{ "name": "content-type" },
140159
{ "name": "x-forwarded-for" },
160+
"transformed_request_fields": [
141161
{ "name": "host" }
142162
],
143163
"response_fields": [
144164
{ "name": "server" },
145165
{ "name": "content-type" },
166+
"raw_response_fields": [
146167
{ "name": "allow" }
147168
],
148169
"cookie_fields": [
@@ -212,3 +233,4 @@ If you are a Cloudflare Access user, as of March 2022 you have to manually add t
212233
* 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.
213234
* Currently, Cloudflare only logs original request/response headers. Headers that were modified earlier in the request lifecycle with [Transform Rules](/rules/transform/) will not be logged.
214235
* The request header `Range` is currently not supported by Custom Fields.
236+
* 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)