Skip to content

Commit ba2a1e3

Browse files
[Logs] Adds datasets to Log Explorer (#19949)
* Adds datasets to Log Explorer * Apply suggestions from code review Co-authored-by: marciocloudflare <[email protected]> --------- Co-authored-by: marciocloudflare <[email protected]>
1 parent 729904e commit ba2a1e3

File tree

1 file changed

+78
-11
lines changed

1 file changed

+78
-11
lines changed

src/content/docs/logs/log-explorer.mdx

Lines changed: 78 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,49 @@ Log Explorer is currently in beta. To request access, complete the [sign-up form
1919

2020
## Supported datasets
2121

22-
The following zone-level datasets are currently available with Log Explorer:
22+
Log Explorer is available at the account and zone level. At the zone level, datasets currently available are:
2323

2424
- [HTTP requests](/logs/reference/log-fields/zone/http_requests/) (`FROM http_requests`)
2525
- [Firewall events](/logs/reference/log-fields/zone/firewall_events/) (`FROM firewall_events`)
2626

27+
At the account level, the datasets available are:
28+
29+
- [Access requests](/logs/reference/log-fields/account/access_requests/) (`FROM access_requests`)
30+
- [CASB Findings](/logs/reference/log-fields/account/casb_findings/) (`FROM casb_findings`)
31+
- [Device posture results](/logs/reference/log-fields/account/device_posture_results/) (`FROM device_posture_results`)
32+
- [Gateway DNS](/logs/reference/log-fields/account/gateway_dns/) (`FROM gateway_dns`)
33+
- [Gateway HTTP](/logs/reference/log-fields/account/gateway_http/) (`FROM gateway_http`)
34+
- [Gateway Network](/logs/reference/log-fields/account/gateway_network/) (`FROM gateway_network`)
35+
2736
## Authentication
2837

29-
In order to communicate with the API, you will need to configure the appropriate authentication headers.
38+
Log Explorer is available to users with the following permissions:
39+
40+
- **Logs Edit**: users with Logs Edit permissions can enable datasets.
41+
- **Logs Read**: users with Logs Read permissions can run queries via the UI or API.
42+
43+
Note that these permissions exist at the account and zone level and you need the appropriate permission level for the datasets you wish to query.
44+
45+
Authentication with the API can be done via an authentication header or API token. Append your API call with either of the following additional parameters.
3046

31-
- `X-Auth-Email` - the Cloudflare account email address associated with the domain
32-
- `X-Auth-Key` - the Cloudflare API key
47+
- **Authentication header**
3348

34-
Alternatively, API tokens with Account and Zone level Logs Edit permissions can also be used for authentication:
49+
- `X-Auth-Email` - the Cloudflare account email address associated with the domain
50+
- `X-Auth-Key` - the Cloudflare API key
3551

36-
- `Authorization: Bearer <API_TOKEN>`
52+
- **API token**
53+
54+
- `Authorization: Bearer <API_TOKEN>` To create an appropriately scoped API token, refer to [Create API token](/fundamentals/api/get-started/create-token/) documentation. Copy and paste the token into the authorization parameter for your API call.
55+
56+
3757

3858
## Enable Log Explorer
3959

40-
You can use the dashboard or the API to enable the datasets you want to query with Log Explorer.
60+
In order for Log Explorer to begin storing logs, you need to enable the desired datasets. You can do this via the dashboard or the API.
4161

4262
<Tabs syncKey="dashPlusAPI"> <TabItem label="Dashboard">
4363

44-
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com/login) and select your account and domain.
64+
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com/login) and select your account or domain (also known as zone).
4565
2. Go to **Analytics & Logs** > **Log Explorer**.
4666
3. Select **Enable a dataset** to select the datasets you want to query. You can enable more datasets later.
4767

@@ -52,9 +72,9 @@ It may take a few minutes for the logs to become available for querying.
5272

5373
</TabItem> <TabItem label="API">
5474

55-
Use the Log Explorer API to enable Log Explorer for each dataset you wish to store. It may take up to 30 minutes after a logstream is enabled before you can view the logs.
75+
Use the Log Explorer API to enable Log Explorer for each dataset you wish to store. It may take a few minutes after a log stream is enabled before you can view the logs.
5676

57-
The following curl command is an example for enabling `http_requests`, as well as the expected response when the command succeeds.
77+
The following curl command is an example for enabling the zone-level dataset `http_requests`, as well as the expected response when the command succeeds.
5878

5979
```bash
6080
curl https://api.cloudflare.com/client/v4/zones/{zone_id}/logs/explorer/datasets \
@@ -79,6 +99,17 @@ curl https://api.cloudflare.com/client/v4/zones/{zone_id}/logs/explorer/datasets
7999
}
80100
```
81101

102+
If you would like to enable an account-level dataset, replace `zones/{zone_id}` with `accounts/{account_id}` in the curl command. For example:
103+
104+
```bash
105+
curl https://api.cloudflare.com/client/v4/accounts/{account_id}/logs/explorer/datasets \
106+
--header "Authorization: Bearer <API_TOKEN>" \
107+
--header "Content-Type: application/json" \
108+
--data '{
109+
"dataset": "access_requests"
110+
}'
111+
```
112+
82113
</TabItem> </Tabs>
83114

84115
## Use Log Explorer
@@ -87,7 +118,7 @@ Filtering and viewing your logs is available via the Cloudflare Dashboard or via
87118

88119
<Tabs syncKey="dashPlusAPI"> <TabItem label="Dashboard">
89120

90-
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com/login) and select your account and domain.
121+
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com/login) and select your account or domain (also known as zone).
91122
2. Go to **Analytics & Logs** > **Log Explorer**.
92123
3. From the dropdown, select the **Dataset** you want to use.
93124
4. Select a **Limit**. That is the maximum number of results to return, for example, 50.
@@ -133,6 +164,38 @@ Which returns the following HTTP request details:
133164
}
134165
```
135166

167+
For another example using an account-level dataset, to find Cloudflare Access requests with selected columns from a specific timeframe, you can perform the following SQL query.
168+
169+
```bash
170+
curl https://api.cloudflare.com/client/v4/account/{account_id}/logs/explorer/query/sql \
171+
--header "Authorization: Bearer <API_TOKEN>" \
172+
--url-query query="SELECT CreatedAt, AppDomain, AppUUID, Action, Allowed, Country, RayID, Email, IPAddress, UserUID FROM access_requests WHERE Date >= '2025-02-06' AND Date <= '2025-02-06' AND CreatedAt >= '2025-02-06T12:28:39Z' AND CreatedAt <= '2025-02-06T12:58:39Z'"
173+
```
174+
175+
Which returns the following request details:
176+
177+
```json
178+
{
179+
"result": [
180+
{
181+
"createdat": "2025-01-14T18:17:55Z",
182+
"appdomain": "example.com",
183+
"appuuid": "a66b4ab0-ccdf-4d60-a6d0-54a59a827d92",
184+
"action": "login",
185+
"allowed": true,
186+
"country": "us",
187+
"rayid": "90fbb07c0b316957",
188+
"email": "[email protected]",
189+
"ipaddress": "1.2.3.4",
190+
"useruid": "52859e81-711e-4de0-8b31-283336060e79"
191+
}
192+
],
193+
"success": true,
194+
"errors": [],
195+
"messages": []
196+
}
197+
```
198+
136199
</TabItem> </Tabs>
137200

138201
## Output formats
@@ -214,6 +277,10 @@ Log Explorer performs best when query parameters focus on narrower ranges of tim
214277

215278
If your query times out with an HTTP status of 524 (Gateway Timeout), consider using one of the [streaming output formats](/logs/log-explorer/#output-formats), such as `application/x-ndjson`.
216279

280+
### Why don't I see any logs in my queries after enabling the dataset?
281+
282+
Log Explorer starts ingesting logs from the moment you enable the dataset. It will not display logs for events that occurred before the dataset was enabled. Make sure that new events have been generated since enabling the dataset, and check again.
283+
217284
### My query returned an error. How do I figure out what went wrong?
218285

219286
We are actively working on improving error codes. If you receive a generic error, check your SQL syntax (if you are using the custom SQL feature), make sure you have included a date and a limit, and that the field you are filtering is not a key-value pair. If the query still fails it is likely timing out. Try refining your filters.

0 commit comments

Comments
 (0)