Cloudflare
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.
Prerequisites
Wrangler version 2.2.2
. Check your Wrangler version with the following command:
Shell
wrangler version
Install
Step 1: Install Cloudflare
APM Package
Run the following command in your terminal:
Shell
npm i @middleware.io/agent-apm-worker
Step 2: Import Tracker
JavaScript
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
:
init({ serviceName:"{APM-SERVICE-NAME}", accountKey:"<MW_API_KEY>", target:"https://{ACCOUNT-UID}.middleware.io", consoleLogEnabled:false, });
Step 4: Track Requests with MW SDK
JavaScript
const sdk = track(request, ctx); sdk.sendResponse(response);
Step 5: Enable Logging
JavaScript
// 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 section to learn more about using Continuous Profiling with our other APMs.
Need assistance or want to learn more about Middleware? Contact our support team in Slack.