You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/workers/observability/logs/index.mdx
+17-3Lines changed: 17 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,8 +7,22 @@ sidebar:
7
7
hideIndex: false
8
8
---
9
9
10
-
import { DirectoryListing } from"~/components";
10
+
import { Badge } from"~/components";
11
11
12
-
TODO
12
+
Logs are an important component of a developer's toolkit to troubleshoot and diagnose application issues and maintaining system health. The Cloudflare Developer Platform offers many tools to help developers manage their application's logs.
Send Workers Trace Event Logs to a supported destination. Workers Logpush includes metadata about requests and responses, unstructured `console.log()` messages and any uncaught exceptions.
Copy file name to clipboardExpand all lines: src/content/docs/workers/observability/logs/workers-logs.mdx
+36-8Lines changed: 36 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,7 +35,7 @@ You must add the observability setting for your Worker to write logs to Workers
35
35
head_sampling_rate = 1# optional. default = 1.
36
36
```
37
37
38
-
The default value for `head_sampling_rate` is 1, meaning 100% of your logs are sampled. `head_sampling_rate` can be set to a value between 0 and 1. For example, 0.01 indicates that 1% of your logs are sampled.
38
+
[Head-based sampling](/workers/observability/logs/workers-logs/#head-based-sampling) allows you set the percentage of Workers requests that are logged.
39
39
40
40
### Enabling with environments
41
41
@@ -56,20 +56,42 @@ To view logs for your Worker:
56
56
<Steps>
57
57
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com) and select your account.
58
58
2. In Account Home, go to **Workers & Pages**.
59
-
3. In **Overview**, select your **Worker** > and select **Logs**.
59
+
3. In **Overview**, select your **Worker**.
60
+
4. Select **Logs**.
60
61
</Steps>
61
62
62
63
## Best Practices
63
64
64
-
### Logging JSON objects
65
+
### Logging structured JSON objects
65
66
66
-
To get the most out of Workers Logs, it is recommended to log in JSON format. Workers Logs automatically extracts the fields and indexes TODO
67
+
To get the most out of Workers Logs, it is recommended you log in JSON format. Workers Logs automatically extracts the fields and indexes them intelligently in the database. The benefit of this structured logging technique is in how it allows you to easily segment data across any dimension for fields with unlimited cardinality. Consider the following scenarios:
The difference between these examples is in how you index your logs to enable faster queries. In scenario 1, the `user_id` is embedded within a message. To find all logs relating to a particular user_id, you would have to run a text match. In scenarios 2 and 3, your logs can be filtered against the keys `user_id` and `user_email`.
67
76
68
77
## Features
69
78
70
79
### Execution Logs
71
80
72
-
Each Workers invocation returns an execution log that contain details about the Request, Response, and related metadata. TODO
81
+
Each Workers invocation returns a single execution log that contains details such as the Request, Response, and related metadata. These execution logs can be identified by the field `$cloudflare.$metadata.type = "cf-worker-event"`. Each execution log is enriched with information available to Cloudlare in the context of the invocation.
82
+
83
+
In the Workers Logs UI, logs are presented with a localized timestamp and a Message. The Message is dependent on the invocation handler. For example, Fetch requests will have a message describing the request method and the request URL, while cron events will be listed as cron. Below is a list of invocation handlers along with their execution message.
@@ -121,11 +143,17 @@ async function handleRequest(request) {
121
143
122
144
After you deploy the code above, view your Worker's logs in [the dashboard](/workers/observability/logs/workers-logs/#view-logs-from-the-dashboard) or with [real-time logs](/workers/observability/logs/real-time-logs/).
123
145
124
-
### Head-based Sampling
146
+
### Head-based sampling
147
+
148
+
Head-based sampling allows you to log a percentage of incoming requests to your Cloudflare Worker. Especially for high-traffic applications, this helps reduce log volume and manage costs, while still providing meaningful insights into your application's performance. When you configure a head-based sampling rate, you can control the percentage of requests that get logged. All logs within the context of the request are collected.
125
149
126
-
Head-based sampling allows you to log only a subset of incoming requests to your Cloudflare Workers. Especially for high-traffic applications, this helps reduce log volume and manage costs, while still providing meaningful insights into your application's performance. When you configure a head-based sampling rate, you can control the percentage of requests that get logged. All logs within the context of the request are collected.
150
+
To enable head-based sampling, set `head_sampling_rate` within the observability configuration. The valid range is from 0 to 1, where 0 indicates zero out of one hundred requests are logged, and 1 indicates every request is logged. If `head_sampling_rate` is unspecified, it is configured to a default value of 1 (100%). In the example below, `head_sampling_rate` is set to 0.01, which means one out of every one hundred requests is logged.
127
151
128
-
To enable head-based sampling, simply set `head_sampling_rate` within the observability configuration. For example, setting a sampling rate of 0.01 (1%) will log one out of every one hundred requests. If the `head_sampling_rate` is unspecified, it is configured to a default value of 1 (100%).
0 commit comments