# Cloudflare Logs

> Send logs to Last9 from Cloudflare for CDN monitoring and worker monitoring via Logpush

Source: https://last9.io/docs/integrations/observability/cloudflare-logs/

This document lists step-by-step instructions for pushing logs from Cloudflare to Last9.

## Prerequisites

1. Create a Last9 account by following [Getting Started](/docs/onboard/).
2. Keep the following information handy from the [Integrations](https://app.last9.io/integrations?integration=OpenTelemetry) page:
   - `$last9_otlp_endpoint`: Last9's OTLP endpoint copies from Cloudflare Integration section from [Integrations](https://app.last9.io/integrations/) page.
   - `$last9_basic_auth_header`: OTLP Basic authorization header

## Setup

You can use Cloudflare's [Logpush](https://developers.cloudflare.com/logs/about/) Custom [HTTPS endpoint integration](https://developers.cloudflare.com/logs/get-started/enable-destinations/http/) to push logs from Cloudflare to Last9.
Logpush delivers logs in batches as quickly as possible, with no minimum batch size, potentially delivering files more than once per minute. This capability enables Cloudflare to provide information almost in real time, in smaller file sizes.

Logpush does not offer storage or search functionality for logs; its primary aim is to send logs as quickly as they arrive which makes it perfect candidate to send logs to [Last9 Log Management](https://last9.io/logs/).

### Via Cloudflare dashboard

5. In **Select a destination**, choose **HTTP destination**.

6. Enter the **HTTP endpoint** as the Last9 Endpoint, and select **Continue**.

```shell
https://$last9_otlp_endpoint/cloudflare?header_Authorization=<encoded($last9_basic_auth_header)>
```

7. Select the dataset to push to the storage service.

8. In the next step, you need to configure your logpush job:

   - Enter the **Job name** as Last9.
   - Under **If logs match**, you can select the events to include and/or remove from your logs. Refer to [Filters](https://developers.cloudflare.com/logs/reference/filters/) for more information. Not all datasets have this option available.
   - In **Send the following fields**, you can choose to either push all logs to Last9 or selectively choose which logs you want to push.

9. In **Advanced Options**:

   - Choose the format of timestamp fields in your logs to be `UnixNano`.

10. Select **Submit** once you are done configuring your logpush job.

### Via API

To create a Logpush job, make a `POST` request to the [Logpush job creation endpoint URL](https://developers.cloudflare.com/logs/get-started/api-configuration/) with the appropriate parameters.

#### Example curl request

```bash
curl https://api.cloudflare.com/client/v4/zones/{zone_id}/logpush/jobs \
--header "X-Auth-Email: <EMAIL>" \
--header "X-Auth-Key: <API_KEY>" \
--header "Content-Type: application/json" \
--data '{
  "name": "last9",
  "output_options": {
    "field_names": ["EdgeStartTimestamp", "RayID"],
    "timestamp_format": "unixnano"
  },
  "destination_conf": "https://$last9_otlp_endpoint/cloudflare?header_Authorization=<encoded($last9_basic_auth_header)>",
  "dataset": "http_requests",
  "enabled": true
}'
```

## Verification

Visit [Log Explorer](https://app.last9.io/logs) to see the Cloudflare logs in action.

---

## Troubleshooting

Please get in touch with us on [Discord](https://discord.com/invite/Q3p2EEucx9)
or [Email](mailto:support@last9.io) if you have any questions.
