Tail Logger
Tail Worker that stores recent traces from another Worker in KV
A Tail Worker that receives TraceItem batches from producer Workers, keeps the last 50 events in Workers KV, and exposes them over HTTP for inspection.
Features
tailhandler - receives TraceItem batches and stores keyrecentGET /logs- read recent eventsDELETE /logs- clear stored events
API Reference
GET /logs
Example Request
curl "https://your-worker.workers.dev/logs"Success Response
{
"events": [
{
"scriptName": "my-producer",
"outcome": "ok",
"eventTimestamp": 1710000000000,
"logs": ["request handled"]
}
],
"count": 1
}DELETE /logs
Example Request
curl -X DELETE "https://your-worker.workers.dev/logs"Success Response
{
"cleared": true
}Configuring a producer
In the producer Worker's wrangler.json, add this Worker as a tail consumer:
{
"name": "my-producer",
"tail_consumers": [{ "service": "tail-logger" }]
}Deploy tail-logger first, then the producer. When the producer handles requests, its traces are delivered to this Worker's tail handler.
Use Cases
- Learn Tail Workers /
tail_consumerswiring - Debug producer Workers without streaming
wrangler taillocally - Keep a short rolling window of outcomes and console logs
- Teach observability patterns across Workers
Limitations
- Stores only the last 50 events in a single KV key
- Tail delivery from another Worker typically requires deployed Workers
- No filtering UI - raw recent events only
- No authentication on
/logs
Deployment
Configure KV and producers
Create a KV namespace and bind it as TAIL_LOGS. Deploy this Worker, then add "tail_consumers": [{ "service": "tail-logger" }] to producer Workers.
Local Development
cd apps/experiments/tail-logger
npm install
npm run devcurl "http://localhost:8787/logs"Tail delivery from another Worker typically requires deployed Workers; unit tests call the tail export directly with mock events.
Configuration
wrangler.json declares:
- KV namespace
TAIL_LOGS
Cloudflare Features Used
- Workers - Edge compute runtime
- Tail Workers - Consume traces from other Workers
- Workers KV - Rolling store for recent events