Skip to content
AnswerWell geo Documentation

Research · 8 min read · Answerwell

Serverless Logs, Real-Time Tail, Head Sampling and Persisted Observability

How to enable Cloudflare Workers Logs, stream with wrangler tail, use Tail Workers, sample requests, and debug errors in production.

This page summarises Cloudflare Workers observability documentation on collecting, streaming, and querying logs from deployed Workers and related runtimes (Pages Functions, Durable Objects, Dynamic Workers). The platform offers several overlapping paths; the right choice depends on whether you need live debugging, searchable history, export to your own stack, or custom processing after each invocation.

Workers Logs vs real-time logs vs Tail Workers vs Logpush

Section titled “Workers Logs vs real-time logs vs Tail Workers vs Logpush”

Cloudflare groups logging into layers that differ in retention, who runs the pipeline, and what you can do with the data.

Approach Stored? Typical use
Workers Logs Yes, up to 7 days in your account Filter, Query Builder, historic debugging
Real-time logs (wrangler tail, dashboard Live) No Immediate feedback after deploy or during incident response
Tail Workers You decide (e.g. forward to HTTP, KV, Workers Logs) Custom filtering, transforms, alerts, diagnostics channels
Workers Logpush Your destination Long-term storage and SIEM-style pipelines

For platform operators, Workers for Platforms observability states the same trade-off in short form:

Workers Logs — Cloudflare stores and indexes your logs, and you query them through the API. Nothing else to run. This is the best starting point for most platforms. Logpush — Cloudflare delivers your logs to a storage destination that you own and manage. Tail Workers — Cloudflare streams your logs to a Worker in real time, and you decide what to do with them.

Common conclusion: use Workers Logs (with observability in Wrangler) as the default for production diagnosis; add real-time tooling when you are actively watching traffic; use Logpush or Tail Workers when logs must leave Cloudflare or need custom handling. OpenTelemetry export is noted in docs as an alternative to Tail Workers for batch export to tools like Sentry or Grafana—see Tail Workers for that comparison.

Workers Logs: enable observability and head_sampling_rate in Wrangler

Section titled “Workers Logs: enable observability and head_sampling_rate in Wrangler”

Workers Logs ingests, indexes, and stores logs emitted from your Workers. GA announcements describe retention and setup:

With a small change to your Wrangler configuration, Workers Logs ingests, indexes, and stores all logs emitted from your Workers for up to 7 days.

— Cloudflare, Workers Logs is now Generally Available

observability settings people search for (Wrangler)

Section titled “observability settings people search for (Wrangler)”

Add observability to the Worker’s Wrangler file and redeploy. Minimum Wrangler version for Workers Logs is 3.78.6 (see Enable Workers Logs).

{
"observability": {
"enabled": true,
"logs": {
"invocation_logs": true,
"head_sampling_rate": 1
}
}
}

Wrangler configuration documents head_sampling_rate as a number between 0 and 1: 0 logs none of the sampled head requests, 1 logs every request (default 1 if omitted). All console.* output within a logged request is collected together with that request.

To reduce volume on high-traffic Workers:

[observability]
enabled = true
head_sampling_rate = 0.1

Workers Best Practices recommends enabling logs (and optionally traces) before production deploy so intermittent failures are not a “black box.”

Invocation logs and custom console.log in Workers Logs

Section titled “Invocation logs and custom console.log in Workers Logs”

Each invocation can emit an invocation log (request/response metadata). Identify them with $cloudflare.$metadata.type = "cf-worker-event". Disable with invocation_logs: false under observability.logs (Invocation Logs).

Custom lines come from your code:

Any console.log statements within your Worker will be visible in Workers Logs.

— Cloudflare, Custom logs

For queryable fields, prefer logging objects or JSON strings—not only concatenated text (Logging structured JSON objects).

Query Builder and Workers Issues for errors

Section titled “Query Builder and Workers Issues for errors”

The Query Builder searches stored Workers Logs in the dashboard (Workers & Pages → your Worker → Observability). No separate “enable Query Builder” flag is required; you need Workers Logs collection enabled.

For exceptions in stored logs, Debug exceptions with Workers Logs suggests filters such as $metadata.error EXISTS or $workers.outcome = "exception". Group recurring failures with Workers Issues (report handled errors via console.error() before returning a fallback—see Report handled errors).

Real-time logs: wrangler tail and dashboard Live

Section titled “Real-time logs: wrangler tail and dashboard Live”

Real-time logs show invocation logs, custom logs, errors, and uncaught exceptions in near real time globally (Real-time logs).

wrangler tail: livestream JSON from the terminal

Section titled “wrangler tail: livestream JSON from the terminal”

From the Worker project directory:

npx wrangler tail

Each line is structured JSON with outcome, logs, exceptions, and event.request (View logs using wrangler tail). Useful flags include --status, --method, --search (text in console.log), and --sampling-rate (tail command).

After starting wrangler tail, you will receive a live feed of console and exception logs for each request your Worker receives.

— Cloudflare, tail

Tail Worker vs wrangler tail: a Tail Worker is a configured destination on the producer; wrangler tail is a CLI live stream. wrangler tail does not support Previews—use a Tail Worker destination or Logpush for preview environments (Tail Workers).

In the dashboard: Workers & Pages → Worker → Logs → Live (View logs from the dashboard).

Zone-level Instant Logs can stream filtered views via Stream live logs; filters that cannot stream show a message instead of being dropped silently.

Real-time logs limits (dropped messages, clients, WebSockets)

Section titled “Real-time logs limits (dropped messages, clients, WebSockets)”
Limit Detail
Storage Not persisted; use Workers Logs to keep history
High traffic May enter sampling mode; some messages drop with a warning
Concurrent viewers Max 10 clients (dashboard + wrangler tail combined)
WebSocket handlers console.log in the handler may be hidden until the WebSocket closes (Real-time logs limits, Known issues)
China Network Real-time logs not available for zones on the Cloudflare China Network

console API: what actually appears in logs and tail events

Section titled “console API: what actually appears in logs and tail events”

The console runtime API mirrors standard methods. Fully supported methods (console.log, console.error, console.warn, console.info, console.debug) write in local wrangler dev, appear in real-time tail/dashboard, and show up in Tail Worker events and trace events (Logpush-capable).

Many other methods are no ops in production; some throw in production (console.createTask()). Libraries that call unsupported APIs will not error but may not log.

For Python Workers, you can use js.console, logging, or print() (Emit logs from your Python Worker).

Common mistake: logging Headers as empty {}

Section titled “Common mistake: logging Headers as empty {}”

console.log(request.headers) or JSON.stringify(request.headers) often prints {} because Headers are not enumerable—iterate entries instead (Logging headers to console).

Tail Workers: tail_consumers and the tail() handler

Section titled “Tail Workers: tail_consumers and the tail() handler”

A Tail Worker runs after the producer invocation finishes and receives execution metadata: console.log data, exceptions, outcomes, and (when applicable) diagnosticsChannelEvents (Tail Workers).

A Tail Worker is automatically invoked after the invocation of a producer Worker … It captures events after the producer has finished executing.

— Cloudflare, Tail Workers

Tail Workers are available on Workers Paid and Enterprise; billing is by CPU time, not request count. Configure the producer with tail_consumers pointing at a Worker that implements tail() (Configure Tail Workers). Event shape and outcome values (ok, exception, exceededCpu, canceled, etc.) are documented on the tail() handler page—outcome is not the same as HTTP status.

Diagnostics channel messages forward to Tail Workers without subscription code in the producer (Diagnostics Channel). When the event buffer fills, a truncated flag can indicate dropped events (platform changelog).

For Dynamic Workers, attach Tail Workers via the tails array on load; the Tail Worker can re-emit structured entries into the loader Worker’s Workers Logs (Dynamic Workers API, Observability with Dynamic Workers).

Use ctx.waitUntil() when posting logs to external HTTP endpoints so floating promises are not canceled at the end of the invocation (Set up a 3rd party logging service).

Pages Functions logs: wrangler pages deployment tail limits

Section titled “Pages Functions logs: wrangler pages deployment tail limits”

Pages Functions debugging and logging uses wrangler pages deployment tail or the dashboard (View details → Functions). Custom console.log in Functions appears in both channels.

Important differences from Workers Logs for Functions:

Logs are not stored. You can start and stop the stream at any time to view them, but they do not persist.

— Cloudflare, Limits

Functions logs also stop displaying if request rate exceeds 100 RPS (five-minute window), share the 10 concurrent viewer cap, and follow the same non-persistence model as real-time Worker logs.

  • Relying on real-time tail only — no history after the session ends; enable Workers Logs for up to seven days of retained data.
  • Unstructured log strings — harder to filter in Query Builder; log JSON objects (Workers Best Practices).
  • 100% head_sampling_rate on very high traffic — cost and noise; sample intentionally (Head-based sampling).
  • External error reporting without waitUntil — log POST may never complete (Errors and exceptions).
  • Tailing WebSocket-heavy Workers for live console output — logs may batch until disconnect (Real-time logs limits).
  • Assuming Preview logs via wrangler tail — use Tail Worker destinations or Logpush for Previews (Test and debug).
  1. Confirm Wrangler is at least 3.78.6, set observability.enabled (and optional head_sampling_rate) in your Worker config, deploy, then open Workers & Pages → your Worker → Observability and confirm new invocations appear (Workers Logs).

  2. Trigger a test request with a distinctive console.log or console.error, then find it in Observability → Logs or run npx wrangler tail --search '<your text>' (Real-time logs).

  3. For errors, filter stored logs with $workers.outcome = "exception" or use Workers Issues, and cross-check Overview metrics (Errors and exceptions).

  4. If you configured tail_consumers, verify the Tail Worker’s tail() runs and receives logs / exceptions for a test invocation (Tail Workers).

  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact wording you are asking about, and we will correct or clarify it.