Skip to content

Test and debug

Previews support the same Workers Observability features as production — logs, traces, metrics, profiles, and Tail Workers — configured independently so your Preview telemetry stays separate.

Logs and traces

Enable logs and traces for Previews in your previews block. These settings are independent from production, so you can run full sampling on a Preview without affecting production telemetry.

{
  "observability": {
    "enabled": true,
    "logs": { "enabled": true, "invocation_logs": true }
  },
  "previews": {
    "observability": {
      "enabled": true,
      "logs": {
        "enabled": true,
        "invocation_logs": true,
        "persist": true
      },
      "traces": {
        "enabled": true,
        "head_sampling_rate": 1,
        "persist": true
      }
    }
  }
}
[observability]
enabled = true

  [observability.logs]
  enabled = true
  invocation_logs = true

[previews.observability]
enabled = true

  [previews.observability.logs]
  enabled = true
  invocation_logs = true
  persist = true

  [previews.observability.traces]
  enabled = true
  head_sampling_rate = 1
  persist = true

Once enabled, Preview logs and traces appear in the Cloudflare dashboard under the individual Preview's Observability tab. You can also configure these settings per Preview in the dashboard under Settings > Observability.

Tail Workers

Tail Workers receive execution metadata from your Worker — request URLs, response status codes, console logs, and errors. You can configure a Tail Worker destination for production, for Previews, or both.

{
  "tail_consumers": [
    { "service": "my-tail-sink" }
  ],
  "previews": {
    "tail_consumers": [
      { "service": "my-tail-sink" }
    ]
  }
}
[[tail_consumers]]
service = "my-tail-sink"

[[previews.tail_consumers]]
service = "my-tail-sink"

When you deploy a Preview with npx wrangler preview --json, the output confirms whether Tail Worker destinations are attached. You can also configure Tail Worker destinations per Preview in the dashboard under Settings > Observability > Tail Worker.

Metrics

Preview invocation metrics are available through the GraphQL Analytics API. Query the workersInvocationsAdaptive dataset with isPreview: 1 to filter for Preview traffic.

query PreviewMetrics($accountTag: String!, $since: Time!) {
	viewer {
		accounts(filter: { accountTag: $accountTag }) {
			workersInvocationsAdaptive(
				limit: 100
				filter: { datetime_geq: $since, isPreview: 1 }
			) {
				dimensions {
					datetime
					scriptName
					previewSlug
					status
				}
				sum {
					requests
					errors
				}
			}
		}
	}
}

Useful fields include scriptName (Worker name), previewSlug (Preview name), and status.

Per-Preview metrics are also visible in the dashboard under the Preview's Metrics tab.

You can also query Preview observability data using the Cloudflare API MCP server.

Profile a Preview

Capture CPU and heap profiles from a Preview to find expensive functions and allocating code before your change reaches production. You can profile a Preview's Worker or a Durable Object instance running on the Preview.

Profiling a Preview works the same way as profiling in production. Before you capture a profile:

  • Enable source maps so the flamegraph shows readable function names.
  • Send traffic to the Preview URL before and during the capture. Capturing a profile does not invoke your code for you.

Use dashboard

  1. In the Cloudflare dashboard, go to Workers & Pages and select your Worker:

    Go to Workers & Pages ↗
  2. Select Previews, then select your Preview.

  3. Select Observability. In the view dropdown, select Flamegraph.

  4. In Profile type, select CPU or Heap.

  5. In Duration (ms), enter a capture duration from 1000 to 50000 milliseconds. The default is 10000 milliseconds.

  6. In Deployment, select the Preview deployment to profile.

  7. Select Capture profile.

    Flamegraph view for a Preview with Profile type, Duration, and Deployment fields and the Capture profile button

When capture completes, the dashboard displays the profile as a flamegraph. Switch to Table to sort functions by self or total value, which is CPU time for CPU profiles and allocated memory for Heap profiles. Select Download profile to download the raw pprof profile.

Flamegraph of a Preview CPU profile with the Download profile button and Flamegraph and Table toggle

To profile a Durable Object instance on the Preview, go to Durable Objects, select the Preview's namespace, select Observability, and switch the view to Flamegraph. Enter the 64-character object ID in Instance ID before you capture.

Use Cloudflare CLI

Install cf and sign in, then capture a CPU profile for 5 seconds from a Preview deployment. Pass latest or a specific deployment ID:

cf previews deployments profile "$DEPLOYMENT_ID" \
  --worker my-worker \
  --preview my-preview \
  --duration-ms 5000 \
  --profile-type cpu > preview-cpu.pprof

To profile a Durable Object instance on the Preview, also pass --namespace-id and --actor-id.

Use API

Send a POST request to the Preview deployment's profile endpoint. Use an API token with the same permissions as the production profiling API: Workers Scripts Read or the Content Read-Only Workers role.

Set $DEPLOYMENT_ID to latest to profile the newest deployment of the Preview. To profile a specific deployment, copy its ID from the Preview's Deployments tab.

The request body accepts the same fields as the production profiling API: duration_ms, profile_type, and, for a Durable Object, namespace_id and actor_id.

curl --fail --silent --show-error --request POST \
  "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/workers/workers/$WORKER_ID/previews/$PREVIEW_ID/deployments/$DEPLOYMENT_ID/profile" \
  --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
    "duration_ms": 10000,
    "profile_type": "cpu"
  }' \
  --output preview-cpu.pprof.gz

To read the results, refer to Inspect the results. For pprof tools, rate limits, and error messages, refer to Download the capture and Limits.

Browser evidence

Preview observability shows what happened inside the Worker. Browser Run can add the browser-side view of the same change — open the Preview URL, exercise a flow, and capture a screenshot or PDF.

Include a debug ID in the URL or request headers so the browser traffic can be correlated with the Preview's logs and traces in Workers Observability.

# Deploy the Preview
npx wrangler preview --name my-feature

# Capture a screenshot of the Preview URL
curl "https://YOUR_BROWSER_RUN_WORKER.workers.dev/screenshot?url=https://my-feature-my-worker.subdomain.workers.dev&debugId=review-123"

Browser Run is not required — you can also use curl, Playwright, integration tests, or any other tool to send traffic to the Preview URL. Browser Run is useful when you want the review artifact to include what a browser actually rendered.

For GitHub Actions examples that create a Preview URL, probe it, capture a screenshot, or post it back to a pull request, refer to Examples.

Exporting data

You can export Preview telemetry to your existing observability stack using OpenTelemetry-compliant exports or Workers Logpush. Configure these in the previews block to keep Preview exports separate from production.

Current limitations

  • wrangler tail does not support targeting Previews.

Was this helpful?