new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Cloudflare Workers · all subjects

observability & monitoring

20 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Enable Workers tracing in wrangler configuration

Workers tracing is enabled by setting `observability.traces.enabled = true` in the wrangler configuration file. The configuration also supports an optional `head_sampling_rate` parameter for sampling (recommended for high-traffic workloads). Example configuration: {"observability": {"traces": {"enabled": true, "head_sampling_rate": 0.05}}}

Workers tracing provides automatic instrumentation

Cloudflare Workers provides tracing instrumentation out of the box with no code changes or SDK required. Automatic instrumentation captures: Fetch calls (all outbound HTTP requests with timing, status codes, and request metadata), Binding calls (interactions with Worker bindings such as KV reads/writes, R2 object storage operations, and Durable Object invocations), and Handler calls (complete lifecycle of each Worker invocation including fetch handlers, scheduled handlers, and queue handlers).

Workers tracing follows OpenTelemetry standards

Workers tracing follows OpenTelemetry (OTel) standards, making it compatible with popular observability platforms such as Honeycomb, Grafana Cloud, and Axiom. Traces can be exported to third-party destinations with zero development effort. Setting `persist: false` exports traces to your destination without persisting them in the Cloudflare dashboard.

Workers tracing default and valid sampling rates

The default sampling rate for Workers tracing is 1, meaning 100% of requests will be traced if tracing is enabled. The valid sampling range is from 0 to 1, where 0 indicates zero out of one hundred invocations will be traced and 1 indicates every request will be traced. For example, 0.05 indicates five out of one hundred requests will be traced. Sampling is head-based, meaning non-traced requests do not incur any tracing overhead.

Workers tracing captures span data from custom and automatic instrumentation

Workers tracing provides automatic instrumentation for fetch calls, binding calls, and handler calls. Users can also create custom spans to trace application-specific logic. Custom spans nest automatically with the built-in instrumentation, giving end-to-end visibility across both platform operations and user code. Refer to the spans and attributes documentation for a full list of instrumented operations.

Enable Workers Logs with observability setting

To enable Workers Logs, add the observability setting to your Worker's wrangler configuration file with "enabled": true and redeploy. The minimum required Wrangler version is 3.78.6.

Disable invocation logs in wrangler configuration

Invocation logs can be disabled by adding the configuration: {"observability": {"logs": {"invocation_logs": false}}} in wrangler.jsonc.

Access Workers Logs from dashboard

To view logs for a Worker from the Cloudflare dashboard: go to Workers & Pages page, select your Worker in Overview, then select Observability.

Workers Logs includes invocation logs, custom logs, errors and exceptions

Workers Logs automatically collects invocation logs containing request and response details, custom logs from console.log statements, errors, and uncaught exceptions. Invocation logs are identified by the field $cloudflare.$metadata.type = "cf-worker-event".

Structured JSON logging best practice

To get the most out of Workers Logs, log in JSON format using console.log({key: value}) instead of string concatenation. Workers Logs automatically extracts JSON fields and indexes them intelligently in the database, enabling filtering across any dimension with unlimited cardinality.

Invocation log messages by handler type

Invocation log messages vary by handler type: Alarm shows <Scheduled Time>, Email shows <Email Recipient>, Fetch shows <Method> <URL>, Queue shows <Queue Name>, Cron shows <UNIX-cron schedule>, Tail shows "tail", RPC shows <RPC method>, WebSocket shows <WebSocket Event Type>.

Custom logs from console.log statements

Any console.log statements within a Worker will be visible in Workers Logs and can be viewed in the dashboard or with real-time logs.

Head-based sampling configuration and behavior

Head-based sampling allows logging a percentage of incoming requests by setting head_sampling_rate in observability configuration. Valid range is 0 to 1, where 0 means 0% of requests are logged and 1 means 100% of requests are logged. Default is 1 (100%). All logs within the context of a sampled request are collected.

Send logs to third-party services

To send logs to a third party from Workers Logs, use OpenTelemetry export (recommended), Workers Logpush, or Tail Workers.

Custom log example with Module Worker

In a Module Worker, custom logs can be added using console.log within the fetch handler: export default { async fetch(request) { const { cf } = request; const { city, country } = cf; console.log(`Request came from city: ${city} in country: ${country}`); return new Response("Hello worker!", { headers: { "content-type": "text/plain" } }); } };

AI Crawl Control enhanced analytics capabilities

AI Crawl Control provides a Crawlers tab that displays total allowed and blocked requests for each AI crawler. Trend charts show crawler activity over a selected time range on a per-crawler basis.

AI Crawl Control status code distribution chart

The Metrics tab in AI Crawl Control includes a status code distribution chart that shows HTTP response codes (2xx, 3xx, 4xx, 5xx) over time. You can filter by individual crawler, category, operator, or time range to analyze how specific crawlers interact with your site.

AI Crawl Control extended actions menu options

Each crawler row in AI Crawl Control includes a three-dot menu with the following per-crawler actions: View Metrics (filter the AI Crawl Control Metrics page to the selected crawler), View on Cloudflare Radar (access verified crawler details on Cloudflare Radar), Copy User Agent (copy user agent strings for use in WAF custom rules, Redirect Rules, or robots.txt files), View in Security Analytics (filter Security Analytics by detection IDs, available for Bot Management customers), and Copy Detection ID (copy detection IDs for use in WAF custom rules, available for Bot Management customers).

AI Crawl Control bulk copy for multiple crawlers

You can select multiple crawlers in AI Crawl Control to use bulk copy buttons for user agents or detection IDs.

AI Crawl Control export data uses

Crawler data exported from AI Crawl Control can be used in WAF custom rules, Redirect Rules, and robots.txt files.

Give your agent this brain