Overview
Cloudflare Trace is an observability solution designed for applications built on Cloudflare Workers. It provides tools for distributed tracing, log analysis, and metrics collection, enabling developers to gain insight into the runtime behavior and performance of their serverless functions deployed at the edge. The platform aims to simplify debugging and performance optimization for applications that leverage Cloudflare's global network infrastructure.
The primary use case for Cloudflare Trace involves understanding the execution path of requests that traverse multiple Workers or external services. By offering detailed traces, developers can visualize the latency contributions of different components within a request flow and pinpoint bottlenecks. This is particularly relevant for edge computing architectures where traditional centralized logging and monitoring tools may not offer adequate visibility into distributed execution environments.
In addition to tracing, Cloudflare Trace aggregates logs generated by Workers, making them searchable and analyzable. This allows developers to quickly diagnose errors, review application state, and understand user interactions. The integration of metrics provides a quantitative view of application health and performance over time, including request counts, error rates, and duration percentiles. This combination of tracing, logging, and metrics aims to provide comprehensive observability for edge applications, aligning with practices often described as "the three pillars of observability" by industry practitioners (see OpenTelemetry's observability primer).
Cloudflare Trace is best suited for organizations that have adopted Cloudflare Workers as their serverless platform. Its direct integration into the Cloudflare ecosystem provides a unified developer experience, streamlining setup and usage for existing Workers users. It offers a free tier as part of Cloudflare Workers plans, scaling based on usage for logs and traces, which can be beneficial for small projects or early-stage development.
Key features
- Distributed tracing: Visualizes the end-to-end flow of requests through one or more Cloudflare Workers, helping identify performance bottlenecks and dependencies (Cloudflare Trace documentation).
- Log analysis: Centralizes and provides search capabilities for logs generated by Workers, aiding in debugging and operational troubleshooting.
- Metrics collection: Gathers performance metrics such as request duration, error rates, and invocations, offering quantitative insights into application health.
- Real-time insights: Provides near real-time data for monitoring and debugging active deployments.
- Edge network integration: Specifically designed for the Cloudflare global network, providing observability into code executed close to users.
- Environment visibility: Offers details on the runtime environment of Workers, including CPU time and memory usage.
Pricing
Cloudflare Trace is included as part of Cloudflare Workers plans. Costs for logs and traces are consumption-based, with a free tier available for initial usage.
| Plan (as of 2026-05-28) | Description | Price |
|---|---|---|
| Workers Free | Includes a free allowance for Workers invocations, CPU time, and fetches. | Free |
| Workers Bundled | Higher allowances for Workers invocations, CPU time, and fetches, plus additional features. | $5/month |
| Workers Unbound | Consumption-based pricing for larger-scale applications with no fixed limits. | Variable, based on usage |
For detailed pricing information, including specific usage allowances and overage rates for logs and traces, refer to the official Cloudflare Workers and Pages pricing page.
Common integrations
- Cloudflare Workers: Native integration for serverless functions deployed on Cloudflare's edge network (Cloudflare Workers Trace guide).
- Cloudflare R2: Can trace interactions with R2 object storage from Workers.
- Cloudflare KV: Provides visibility into data operations with KV namespaces from Workers.
- Cloudflare D1: Integrates with D1 serverless database interactions within Workers.
Alternatives
- Datadog: A comprehensive monitoring and analytics platform offering infrastructure monitoring, APM, log management, and security solutions across various cloud environments.
- New Relic: An observability platform providing APM, infrastructure monitoring, log management, and error tracking for a wide range of applications and services.
- OpenTelemetry: An open-source project providing a collection of tools, APIs, and SDKs to instrument, generate, collect, and export telemetry data (metrics, logs, and traces) for cloud-native software.
- AWS X-Ray: A service from Amazon Web Services that helps developers analyze and debug distributed applications, such as those built using microservices architectures, for serverless functions on AWS Lambda.
- Google Cloud Trace: A distributed tracing system from Google Cloud Platform that collects latency data from applications and displays it in the Google Cloud Console for analysis.
Getting started
To enable Cloudflare Trace for a Cloudflare Worker, ensure that the Worker is configured to send traces. The following example demonstrates a basic Worker that logs a message and processes a request, with tracing implicitly handled when enabled in the Cloudflare dashboard or via API.
First, create a new Cloudflare Worker or modify an existing one. Ensure your wrangler.toml file has the necessary configurations if you're deploying via Wrangler.
// worker.js
export default {
async fetch(request, env, ctx) {
// Log a message that will appear in Cloudflare Trace logs
console.log(`Processing request for: ${request.url}`);
// Simulate some work or an API call
const response = await fetch("https://api.example.com/data").catch(err => {
console.error("Failed to fetch data:", err);
return new Response("Error fetching data", { status: 500 });
});
const data = await response.text();
// Return a new response
return new Response(`Hello from Cloudflare Worker! Data: ${data}`, {
headers: { 'content-type': 'text/plain' },
});
},
};
# wrangler.toml
name = "my-traced-worker"
main = "src/worker.js"
compatibility_date = "2024-01-01"
# Enable tracing for this worker
# This often needs to be configured in the Cloudflare dashboard or via Cloudflare API
# The configuration for enabling Trace is not directly in wrangler.toml for basic setup,
# but rather through the Cloudflare dashboard for individual Workers under the "Observability" tab.
# If you're using a more advanced setup or specific trace services, you might use bindings.
After deploying this Worker, navigate to your Worker in the Cloudflare dashboard, go to the "Observability" tab, and ensure "Trace" is enabled. Once enabled, requests to your Worker will generate traces accessible through the Cloudflare dashboard, providing detailed execution timelines, logs, and any errors encountered during the request processing (Cloudflare Workers Trace setup).