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
Workers Logs lets you automatically collect, store, filter, and analyze logging data emitted from Cloudflare Workers. Data is written to your Cloudflare Account, and you can query it in the dashboard for each of your Workers. All newly created Workers will come with the observability setting enabled by default.
16
+
Workers Logs lets you automatically collect, store, filter, and analyze logging data emitted from
17
+
Cloudflare Workers. Data is written to your Cloudflare Account, and you can query it in the dashboard
18
+
for each of your Workers. All newly created Workers will come with the observability setting enabled
19
+
by default.
17
20
18
-
Logs include [invocation logs](/workers/observability/logs/workers-logs/#invocation-logs), [custom logs](/workers/observability/logs/workers-logs/#custom-logs), errors, and uncaught exceptions.
21
+
Logs include [invocation logs](/workers/observability/logs/workers-logs/#invocation-logs),
22
+
[custom logs](/workers/observability/logs/workers-logs/#custom-logs), errors, and uncaught exceptions.
19
23
20
24

21
25
22
-
To send logs to a third party, use [Workers Logpush](/workers/observability/logs/logpush/) or [Tail Workers](/workers/observability/logs/tail-workers/).
26
+
To send logs to a third party, use [Workers Logpush](/workers/observability/logs/logpush/)
27
+
or [Tail Workers](/workers/observability/logs/tail-workers/).
23
28
24
29
## Enable Workers Logs
25
30
26
31
:::note[Wrangler version]
27
-
Minimum required Wrangler version: 3.78.6. Check your version by running `wrangler version`. To update Wrangler, refer to [Install/Update Wrangler](/workers/wrangler/install-and-update/).
32
+
Minimum required Wrangler version: 3.78.6. Check your version by running `wrangler version`.
33
+
To update Wrangler, refer to [Install/Update Wrangler](/workers/wrangler/install-and-update/).
28
34
:::
29
35
30
-
You must add the observability setting for your Worker to write logs to Workers Logs. Add the following setting to your Worker's `wrangler.toml` file and redeploy your Worker.
36
+
You must add the observability setting for your Worker to write logs to Workers Logs.
37
+
Add the following setting to your Worker's `wrangler.toml` file and redeploy your Worker.
31
38
32
39
<WranglerConfig>
33
40
@@ -39,11 +46,15 @@ You must add the observability setting for your Worker to write logs to Workers
39
46
40
47
</WranglerConfig>
41
48
42
-
[Head-based sampling](/workers/observability/logs/workers-logs/#head-based-sampling) allows you set the percentage of Workers requests that are logged.
49
+
[Head-based sampling](/workers/observability/logs/workers-logs/#head-based-sampling) allows you
50
+
to set the percentage of Workers requests that are logged.
43
51
44
52
### Enabling with environments
45
53
46
-
[Environments](/workers/wrangler/environments/) allow you to deploy the same Worker application with different configurations. For example, you may want to configure a different `head_sampling_rate` to staging and production. To configure observability for an environment named `staging`:
54
+
[Environments](/workers/wrangler/environments/) allow you to deploy the same Worker application
55
+
with different configurations. For example, you may want to configure a different
56
+
`head_sampling_rate` to staging and production. To configure observability for an environment
57
+
named `staging`:
47
58
1. Add the following configuration below `[env.staging]`
48
59
49
60
@@ -62,10 +73,12 @@ You must add the observability setting for your Worker to write logs to Workers
62
73
63
74
## View logs from the dashboard
64
75
65
-
Access logs for your Worker from the [Cloudflare dashboard](https://dash.cloudflare.com/?to=/:account/workers/services/view/:worker/production/observability/logs/).
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com/?to=/:account/workers/services/view/:worker/production/observability/logs/) and select your account.
80
+
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com/?to=/:account/workers/services/view/:worker/production/observability/logs/)
81
+
and select your account.
69
82
2. In Account Home, go to **Workers & Pages**.
70
83
3. In **Overview**, select your **Worker**.
71
84
4. Select **Logs**.
@@ -75,7 +88,10 @@ Access logs for your Worker from the [Cloudflare dashboard](https://dash.cloudfl
75
88
76
89
### Logging structured JSON objects
77
90
78
-
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:
91
+
To get the most out of Workers Logs, it is recommended you log in JSON format. Workers Logs
92
+
automatically extracts the fields and indexes them intelligently in the database.
93
+
The benefit of this structured logging technique is in how it allows you to easily segment data
94
+
across any dimension for fields with unlimited cardinality. Consider the following scenarios:
@@ -89,14 +105,18 @@ The difference between these examples is in how you index your logs to enable fa
89
105
90
106
### Invocation Logs
91
107
92
-
Each Workers invocation returns a single invocation log that contains details such as the Request, Response, and related metadata. These invocation logs can be identified by the field `$cloudflare.$metadata.type = "cf-worker-event"`. Each invocation log is enriched with information available to Cloudflare in the context of the invocation.
108
+
Each Workers invocation returns a single invocation log that contains details such as the Request,
109
+
Response, and related metadata. These invocation logs can be identified by the field
110
+
`$cloudflare.$metadata.type = "cf-worker-event"`. Each invocation log is enriched with information
111
+
available to Cloudflare in the context of the invocation.
93
112
94
-
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 invocation message.
113
+
In the Workers Logs UI, logs are presented with a localized timestamp and a message. The message is
114
+
dependent on the invocation handler. For example, Fetch requests will have a message describing
115
+
the request method and the request URL, while cron events will be listed as cron. Below is a list
116
+
of invocation handlers along with their invocation message.
95
117
96
118
Invocation logs can be disabled in wrangler by adding the `invocation_logs = false` configuration.
97
119
98
-
99
-
100
120
<WranglerConfig>
101
121
102
122
```toml
@@ -119,9 +139,12 @@ invocation_logs = false
119
139
120
140
### Custom logs
121
141
122
-
By default a Worker will emit [invocation logs](/workers/observability/logs/workers-logs/#invocation-logs) containing details about the request, response and related metadata.
142
+
By default a Worker will emit [invocation logs](/workers/observability/logs/workers-logs/#invocation-logs)
143
+
containing details about the request, response and related metadata.
123
144
124
-
You can also add custom logs throughout your code. Any `console.log` statements within your Worker will be visible in Workers Logs. The following example demonstrates a custom `console.log` within a Worker request handler.
145
+
You can also add custom logs throughout your code. Any `console.log` statements within your Worker
146
+
will be visible in Workers Logs. The following example demonstrates a custom `console.log` within a
@@ -165,14 +188,22 @@ async function handleRequest(request) {
165
188
166
189
</TabItem> </Tabs>
167
190
168
-
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/).
191
+
After you deploy the code above, view your Worker's logs in [the dashboard](/workers/observability/logs/workers-logs/#view-logs-from-the-dashboard)
192
+
or with [real-time logs](/workers/observability/logs/real-time-logs/).
169
193
170
194
### Head-based sampling
171
195
172
-
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.
173
-
174
-
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.
196
+
Head-based sampling allows you to log a percentage of incoming requests to your Cloudflare Worker.
197
+
Especially for high-traffic applications, this helps reduce log volume and manage costs, while still
198
+
providing meaningful insights into your application's performance. When you configure a head-based
199
+
sampling rate, you can control the percentage of requests that get logged. All logs within the
200
+
context of the request are collected.
175
201
202
+
To enable head-based sampling, set `head_sampling_rate` within the observability configuration.
203
+
The valid range is from 0 to 1, where 0 indicates zero out of one hundred requests are logged,
204
+
and 1 indicates every request is logged. If `head_sampling_rate` is unspecified, it is configured
205
+
to a default value of 1 (100%). In the example below, `head_sampling_rate` is set to 0.01, which
206
+
means one out of every one hundred requests is logged.
| Maximum logs per account per day<sup>1</sup> | 5 Billion |
194
225
| Maximum log size<sup>2</sup> | 128 KB |
195
226
196
-
<sup>1</sup> While Workers Logs is in open beta, there is a daily limit of 5 billion logs per account per day. After the limit is exceed, a 1% head-based sample will be applied for the remainder of the day.
227
+
<sup>1</sup> While Workers Logs is in open beta, there is a daily limit of 5 billion logs per account
228
+
per day. After the limit is exceed, a 1% head-based sample will be applied for the remainder of the day.
197
229
198
-
<sup>2</sup> A single log has a maximum size limit of [128 KB](/workers/platform/limits/#log-size). Logs exceeding that size will be truncated and the log's `$cloudflare.truncated` field will be set to true.
230
+
<sup>2</sup> A single log has a maximum size limit of [128 KB](/workers/platform/limits/#log-size).
231
+
Logs exceeding that size will be truncated and the log's `$cloudflare.truncated` field will be
232
+
set to true.
199
233
200
234
## Pricing
201
235
@@ -208,7 +242,8 @@ Workers Logs billing will begin on November 1, 2024.
208
242
209
243
#### Example 1
210
244
211
-
A Worker serves 15 million requests per month. Each request emits 1 invocation log and 1 `console.log`. `head_sampling_rate` is configured to 1.
245
+
A Worker serves 15 million requests per month. Each request emits 1 invocation log and 1
246
+
`console.log`. `head_sampling_rate` is configured to 1.
0 commit comments