Skip to content

Commit 4be2750

Browse files
committed
[workers-observability] update max width for workers logs
1 parent e822350 commit 4be2750

File tree

1 file changed

+60
-24
lines changed

1 file changed

+60
-24
lines changed

src/content/docs/workers/observability/logs/workers-logs.mdx

Lines changed: 60 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,28 @@ sidebar:
1313

1414
import { TabItem, Tabs, Steps, Render, WranglerConfig } from "~/components"
1515

16-
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.
1720

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.
1923

2024
![Example showing the Workers Logs Dashboard](~/assets/images/workers-observability/preview.png)
2125

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/).
2328

2429
## Enable Workers Logs
2530

2631
:::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/).
2834
:::
2935

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.
3138

3239
<WranglerConfig>
3340

@@ -39,11 +46,15 @@ You must add the observability setting for your Worker to write logs to Workers
3946

4047
</WranglerConfig>
4148

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.
4351

4452
### Enabling with environments
4553

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`:
4758
1. Add the following configuration below `[env.staging]`
4859

4960

@@ -62,10 +73,12 @@ You must add the observability setting for your Worker to write logs to Workers
6273

6374
## View logs from the dashboard
6475

65-
Access logs for your Worker from the [Cloudflare dashboard](https://dash.cloudflare.com/?to=/:account/workers/services/view/:worker/production/observability/logs/).
76+
Access logs for your Worker from the
77+
[Cloudflare dashboard](https://dash.cloudflare.com/?to=/:account/workers/services/view/:worker/production/observability/logs/).
6678

6779
<Steps>
68-
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.
6982
2. In Account Home, go to **Workers & Pages**.
7083
3. In **Overview**, select your **Worker**.
7184
4. Select **Logs**.
@@ -75,7 +88,10 @@ Access logs for your Worker from the [Cloudflare dashboard](https://dash.cloudfl
7588

7689
### Logging structured JSON objects
7790

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:
7995

8096
| Scenario | Logging Code | Event Log (Partial) |
8197
| -------- | ---------------------------------------------------------- | --------------------------------------------- |
@@ -89,14 +105,18 @@ The difference between these examples is in how you index your logs to enable fa
89105

90106
### Invocation Logs
91107

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.
93112

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.
95117

96118
Invocation logs can be disabled in wrangler by adding the `invocation_logs = false` configuration.
97119

98-
99-
100120
<WranglerConfig>
101121

102122
```toml
@@ -119,9 +139,12 @@ invocation_logs = false
119139

120140
### Custom logs
121141

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.
123144

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
147+
Worker request handler.
125148

126149
<Tabs> <TabItem label="Module Worker" icon="seti:javascript">
127150

@@ -165,14 +188,22 @@ async function handleRequest(request) {
165188

166189
</TabItem> </Tabs>
167190

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/).
169193

170194
### Head-based sampling
171195

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.
175201

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.
176207

177208

178209
<WranglerConfig>
@@ -193,9 +224,12 @@ head_sampling_rate = 0.01 # 1% sampling rate
193224
| Maximum logs per account per day<sup>1</sup> | 5 Billion |
194225
| Maximum log size<sup>2</sup> | 128 KB |
195226

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.
197229

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.
199233

200234
## Pricing
201235

@@ -208,7 +242,8 @@ Workers Logs billing will begin on November 1, 2024.
208242

209243
#### Example 1
210244

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.
212247

213248
| | Monthly Costs | Formula |
214249
| ---------- | ----------------- | ---------------------------------------------------------------------------------------------------------------------- |
@@ -217,7 +252,8 @@ A Worker serves 15 million requests per month. Each request emits 1 invocation l
217252

218253
#### Example 2
219254

220-
A Worker serves 1 billion requests per month. Each request emits 1 invocation log and 1 `console.log`. `head_sampling_rate` is configured to 0.1.
255+
A Worker serves 1 billion requests per month. Each request emits 1 invocation log and 1
256+
`console.log`. `head_sampling_rate` is configured to 0.1.
221257

222258
| | Monthly Costs | Formula |
223259
| ---------- | ----------------- | ---------------------------------------------------------------------------------------------------------------------- |

0 commit comments

Comments
 (0)