Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Comprehensive Cloudflare platform skill covering Workers, D1, R2, KV, AI, Durable Objects, and security.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/tail-workers/README.md
1# Cloudflare Tail Workers23Specialized Workers that consume execution events from producer Workers for logging, debugging, analytics, and observability.45## When to Use This Reference67- Implementing observability/logging for Cloudflare Workers8- Processing Worker execution events, logs, exceptions9- Building custom analytics or error tracking10- Configuring real-time event streaming11- Working with tail handlers or tail consumers1213## Core Concepts1415### What Are Tail Workers?1617Tail Workers automatically process events from producer Workers (the Workers being monitored). They receive:18- HTTP request/response info19- Console logs (`console.log/error/warn/debug`)20- Uncaught exceptions21- Execution outcomes (`ok`, `exception`, `exceededCpu`, etc.)22- Diagnostic channel events2324**Key characteristics:**25- Invoked AFTER producer finishes executing26- Capture entire request lifecycle including Service Bindings and Dynamic Dispatch sub-requests27- Billed by CPU time, not request count28- Available on Workers Paid and Enterprise tiers2930### Alternative: OpenTelemetry Export3132**Before using Tail Workers, consider OpenTelemetry:**3334For batch exports to observability tools (Sentry, Grafana, Honeycomb):35- OTEL export sends logs/traces in batches (more efficient)36- Built-in integrations with popular platforms37- Lower overhead than Tail Workers38- **Use Tail Workers only for custom real-time processing**3940## Decision Tree4142```43Need observability for Workers?44├─ Batch export to known tools (Sentry/Grafana/Honeycomb)?45│ └─ Use OpenTelemetry export (not Tail Workers)46├─ Custom real-time processing needed?47│ ├─ Aggregated metrics?48│ │ └─ Use Tail Worker + Analytics Engine49│ ├─ Error tracking?50│ │ └─ Use Tail Worker + external service51│ ├─ Custom logging/debugging?52│ │ └─ Use Tail Worker + KV/HTTP endpoint53│ └─ Complex event processing?54│ └─ Use Tail Worker + Durable Objects55└─ Quick debugging?56└─ Use `wrangler tail` (different from Tail Workers)57```5859## Reading Order60611. **[configuration.md](configuration.md)** - Set up Tail Workers622. **[api.md](api.md)** - Handler signature, types, redaction633. **[patterns.md](patterns.md)** - Common use cases and integrations644. **[gotchas.md](gotchas.md)** - Pitfalls and debugging tips6566## Quick Example6768```typescript69export default {70async tail(events, env, ctx) {71// Process events from producer Worker72ctx.waitUntil(73fetch(env.LOG_ENDPOINT, {74method: "POST",75headers: { "Content-Type": "application/json" },76body: JSON.stringify(events),77})78);79}80};81```8283## Related Skills8485- **observability** - General Workers observability patterns, OTEL export86- **analytics-engine** - Aggregated metrics storage for tail event data87- **durable-objects** - Stateful event processing, batching tail events88- **logpush** - Alternative for batch log export (non-real-time)89- **workers-for-platforms** - Dynamic dispatch with tail consumers90