> ## Documentation Index
> Fetch the complete documentation index at: https://mw-docs.middleware.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Cloudflare

> Cloudflare APM - Setup & Installation Docs | Middleware

| Traces | Metrics | App Logs | Custom Logs | Profiling |
| :----: | :-----: | :------: | :---------: | :-------: |
|    ✅   |    ✖️   |    ✖️    |      ✅      |     ✖️    |

This guide walks you through setting up Application Performance Monitoring (APM) on applications deployed through Cloudflare Workers. These instructions can also be found on the Installation page in your Middleware Account. View example code [here](https://github.com/middleware-labs/demo-apm/tree/master/cloudflare).

## Prerequisites

`Wrangler version 2.2.2`. Check your Wrangler version with the following command:

```bash Shell theme={null}
wrangler version
```

# Install

### Step 1: Install `Cloudflare` APM Package

Run the following command in your terminal:

```bash Shell theme={null}
npm i @middleware.io/agent-apm-worker 
```

### Step 2: Import Tracker

```javascript JavaScript theme={null}
import { init,track } from '@middleware.io/agent-apm-worker';
```

### Step 3: Initialize Tracker

The access token is your account key, which can be found on the Installation page. To watch instrumented logs in the terminal, set `consoleLogEnabled: true`:

```javascript JavaScript theme={null}
init({
   serviceName:"{APM-SERVICE-NAME}",
   accountKey:"{ACCOUNT_KEY}",
   target:"https://{ACCOUNT-UID}.middleware.io",
   consoleLogEnabled:false,
});
```

### Step 4: Track Requests with MW SDK

```javascript JavaScript theme={null}
const sdk = track(request, ctx);
sdk.sendResponse(response);
```

### Step 5: Enable Logging

```javascript JavaScript theme={null}
// sdk.logger.SEVERITY( MESSAGE, KEY-VALUE PAIRS )

sdk.logger.error("error test")
sdk.logger.error("error with attributes",{"log.file.name":"error.log"})
sdk.logger.info("info test")
sdk.logger.debug("debug test")
sdk.logger.warn("warn test")
```

# Continuous Profiling

Continuous profiling captures real-time performance insights from your application to enable rapid identification of resource allocation, bottlenecks, and more. The following table describes the available features offered by the continuous profiler for the Cloudflare APM.

Continuous Profiling for the Cloudflare APM is not yet available; reach out to our support team if you'd like more information. Navigate to the [Continuous Profiling](https://docs.middleware.io/workflow/profiling#continuous-profiling) section to learn more about using Continuous Profiling with our other APMs.

<Note> Need assistance or want to learn more about Middleware? Contact us at support\[at]middleware.io. </Note>
