APM
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 demo code here.
Prerequisites
- Wrangler version 2.2.2, you can check your Wrangler version with the following command.
Shell
wrangler version
Step 1: Install Middleware Worker 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.
JavaScript
init({
projectName:"{APM-PROJECT-NAME}",
serviceName:"{APM-SERVICE-NAME}",
accountKey:"{ACCOUNT_KEY}",
target:"https://{ACCOUNT-UID}.middleware.io",
consoleLogEnabled:false,
});
Step 4: Track Requests with the Middleware 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")
Need assistance or want to learn more about Middleware? Contact us at support[at]middleware.io.