Cloudflare Docs
Edit this page
Report an issue with this page
Log into the Cloudflare dashboard
Set theme to dark (⇧+D)

Workers Trace Events Logpush

Cloudflare Logpush supports the ability to send Workers Trace Event Logs to a supported destination. Worker’s Trace Events Logpush includes metadata about requests and responses, unstructured console.log() messages and any uncaught exceptions. This product is available on the Workers Paid plan. For pricing information, refer to Pricing.

​​ Verify your Logpush access

Workers Logpush requires a Wrangler version of 2.2.0 or higher. Check your version by running wrangler version. To update Wrangler, refer to Install/Update Wrangler.

To configure a Logpush job, verify that your Cloudflare account role can use Logpush. To check your role:

  1. Log in the Cloudflare dashboard.
  2. Select your account and scroll down to Manage Account > Members.
  3. Check your account permissions. Roles with Logpush configuration access are different than Workers permissions. Super Administrators, Administrators, and the Log Share roles have full access to Logpush.

Alternatively, create a new API token scoped at the Account level with Logs Edit permissions.

​​ Create a Logpush job

​​ Via the Cloudflare dashboard

To create a Logpush job in the Cloudflare dashboard:

  1. Log in to the Cloudflare dashboard, and select your account.
  2. Select Analytics & Logs > Logs.
  3. Select Add Logpush job.
  4. Select Workers trace events as the data set > Next.
  5. If needed, customize your data fields. Otherwise, select Next.
  6. Follow the instructions on the dashboard to verify ownership of your data’s destination and complete job creation.

​​ Via cURL

The following example sends Workers logs to R2. For more configuration options, refer to Enable destinations and API configuration in the Logs documentation.

curl -X POST '<ACCOUNT_ID>/logpush/jobs' \
-H 'X-Auth-Key: <API_KEY>' \
-H 'X-Auth-Email: <EMAIL>' \
-H 'Content-Type: application/json' \
-d '{
"name": "workers-logpush",
"logpull_options": "fields=Event,EventTimestampMs,Outcome,Exceptions,Logs,ScriptName",
"destination_conf": "r2://<BUCKET_PATH>/{DATE}?account-id=<ACCOUNT_ID>&access-key-id=<R2_ACCESS_KEY_ID>&secret-access-key=<R2_SECRET_ACCESS_KEY>",
"dataset": "workers_trace_events",
"enabled": true
}'| jq .

In Logpush, you can configure filters and a sampling rate to have more control of the volume of data that is sent to your configured destination. For example, if you only want to receive logs for requests that did not result in an exception, add the following filter JSON property below logpull_options:

"filter":"{\"where\": {\"key\":\"Outcome\",\"operator\":\"!eq\",\"value\":\"exception\"}}"

​​ Enable logging on your Worker

Enable logging on your Worker by adding a new property, logpush = true, to your wrangler.toml file. This can be added either in the top-level configuration or under an environment. Any new Workers with this property will automatically get picked up by the Logpush job.

# Top-level configuration
name = "my-worker"
main = "src/index.js"
compatibility_date = "2022-07-12"
workers_dev = false
logpush = true
route = { pattern = "*", zone_name = "" }

Configure via multipart script upload API:

curl -X PUT "<ACCOUNT_ID>/workers/scripts/<SCRIPT_NAME>" \
-H 'X-Auth-Key: <API_KEY>' \
-H 'X-Auth-Email: <EMAIL>' \
--form 'metadata={"main_module": "my-worker.js", "logpush": true}' \
--form '"my-worker.js"=@./my-worker.js;type=application/javascript+module'

​​ Limits

The logs and exceptions fields have the following limits in place.

  • Message size: Maximum of 2056 characters per log line
  • Array limit: 20 elements
  • Log message array: A nested array with a limit of three elements