# Better Stack Cloudflare Logpush

## Start logging in 2 minutes

Send Cloudflare logs to Better Stack using [Cloudflare Logpush](https://developers.cloudflare.com/logs/about/).


### Set up Cloudflare Logpush job

Configure Logpush job for [Worker Trace Events](https://developers.cloudflare.com/workers/platform/logpush/) dataset: 

```shell
[label Set up Logpush job]
curl -X POST "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/logpush/jobs" \
-H "Authorization: Bearer $CLOUDFLARE_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "logpush-better-stack-logs",
"destination_conf": "https://$INGESTING_HOST?header_Content-Type=application%2Fx-ndjson&header_Authorization=Bearer%20$SOURCE_TOKEN",
"dataset": "workers_trace_events",
"enabled": true
}'
``` 

[info]
#### Insert your Cloudflare details

You will need to replace `$ACCOUNT_ID` and `$CLOUDFLARE_TOKEN` in command above. You can get your token in [Cloudflare docs](https://developers.cloudflare.com/fundamentals/api/get-started/).

The token will need the **account-level permission for Logs: Edit**.
[/info]

### Enable logging on your Worker

Logpush will not send any data unless logging is explicitly enabled on your Worker. Make sure to turn on logging either in your Wrangler configuration, via the API, or in the dashboard under **Settings -> Observability**.

See [Cloudflare’s documentation](https://developers.cloudflare.com/workers/observability/logs/logpush/#enable-logging-on-your-worker ) for step-by-step instructions.

### View your logs and metrics 🚀

You should see your logs in [Better Stack → Live tail](https://telemetry.betterstack.com/team/0/tail ";_blank").

Check out your metrics in the [Cloudflare Logpush dashboard](https://telemetry.betterstack.com/team/0/dashboards/platform/cloudflare_logpush ";_blank").

[warning]
Cloudflare Logpush for [Workers Trace Events](https://developers.cloudflare.com/workers/platform/logpush/) is available on the [Workers Paid plan](https://developers.cloudflare.com/workers/platform/pricing/). Logpush for other [Cloudflare logs datasets](https://developers.cloudflare.com/logs/reference/log-fields/#datasets) are available on the [Enterprise plan](https://developers.cloudflare.com/logs/about/#availability).

**Not on a paid plan?** Check out [logging HTTP requests in Cloudflare via Worker](https://betterstack.com/docs/logs/cloudflare-http-requests/).
[/warning]

## Need help?

Please let us know at hello@betterstack.com.  
We're happy to help! 🙏

## Other datasets

Interested in logging other logs than **Worker Trace Events** from Cloudflare? Checkout the full list of available datasets in [Cloudflare documentation](https://developers.cloudflare.com/logs/reference/log-fields/). Specify the correct dataset in the request. Find more details in [Cloudflare docs](https://developers.cloudflare.com/logs/get-started/api-configuration/).

Please note that zone-scoped datasets (such as [HTTP Requests](https://developers.cloudflare.com/logs/reference/log-fields/zone/http_requests/)) require a different endpoint for the POST request:

```shell
[label Set up zone-scoped Logpush job]
curl -X POST "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/logpush/jobs" \
-H "Authorization: Bearer $CLOUDFLARE_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "logpush-better-stack-logs",
"destination_conf": "https://$INGESTING_HOST?header_Content-Type=application%2Fx-ndjson&header_Authorization=Bearer%20$SOURCE_TOKEN",
"dataset": "http_requests",
"enabled": true
}'
```

[info]
#### Insert your Cloudflare details

You will need to replace `$ZONE_ID` and `$CLOUDFLARE_TOKEN` in command above. You can get your token in [Cloudflare docs](https://developers.cloudflare.com/fundamentals/api/get-started/).

The token will need the **zone-level permission for Logs: Edit**.
[/info]