Apitally now supports Cloudflare Workers

Introducing two new serverless SDKs and a Logpush integration for easy monitoring of REST APIs running on Cloudflare Workers.

Simon GurckeSimon Gurcke//2 min read

We’re excited to announce that you can now use Apitally with Hono and FastAPI running on Cloudflare Workers.

Cloudflare offers basic observability for Workers, but if you’re building APIs, you’ll miss features like request and response body capture for debugging, detailed metrics broken down by endpoint and API consumer, exception tracking with stack traces, custom alerts, and more.

Our new integration with Cloudflare Workers brings all of that to your serverless APIs, while keeping things simple and lightweight.

A different approach

Apitally’s existing SDKs require long-running processes to periodically sync data with our servers in the background. Serverless functions can’t execute code outside of the request handling context, so we needed a different approach.

Some monitoring tools work around this by sending a fire-and-forget HTTP request for each invocation. However, this adds execution time to each invocation and isn’t particularly reliable or efficient.

We decided to hook into Cloudflare’s native observability features and leverage Logpush. Instead of sending data directly to Apitally from our SDK, our middleware captures request and response data, compresses it with gzip, and outputs it as a base64-encoded log message. Cloudflare’s Workers Logs capture this message, and Logpush batches and ships the logs to Apitally for ingestion.

The emitted log messages look like this:

apitally:H4sIAHYnV2kC/3VSS4+bMBD+Lz6uYoJ5xpH2sOppW/VQqb10E0XGHoJb1nZtky2J+O8d2EWrSi0HhL/HeOYbbkSbEIWRcBoGrciepAXPeJ2XtGgzTguVlVRkLaNlmTctz6FmsiUb4uHXACGuLlVwpUpW0UyynBZQZHTH8CXqmpVlxji02buL7G/Eidihcdtau71pNSHbgVDgA9k/PREhJbiI4N32jhw3K0DBSKu0OSNzvmr3H6rxCyFbKq0xICPCFNUbwkqeMF4lu6Tmq0Y7aQcT/Yj8w7cV9WI+86auBBSsUU1V7N49Fx10tB4VtwMJsoNnOJD9gXQxunAg06vu7XJrUPcJwNGHXl9g4Tob5vFagfE7TSPGQoVzCR6i6PsxebH+J6aRKLgshiGAp+IMZrbJwfdbnCFhC/ebtta/CK9AUedttHOacydvrAfR/2v+4zTvJDhrAsxLWb9PUT8jkCZpmaX4FGVdV3lVM74h2G8cwgmzRgWyf+8NR47YIu3BnHHBeGG6RrHgcXSAKE7aaynmaLY/AuZzPGJlfcWSDCs2Vo34c8D40X3/8Fh9/vp4bb/c35Np+gMi/gCFsQIAAA==

New serverless SDKs

We’ve published two new serverless SDKs for this integration:

Both SDKs are lightweight and have no dependencies, ensuring a minimal impact on your application’s bundle size.

Adding the middleware to your application is easy and works similarly to our standard SDKs. Here’s an example for Hono:

import { Hono } from "hono";
import { useApitally } from "@apitally/serverless/hono";

const app = new Hono();

useApitally(app, {
  logRequestHeaders: true,
  logRequestBody: true,
  logResponseBody: true,
});

Note the absence of the clientId and env parameters, which normally identify your application. These are specified in the Logpush job configuration instead.

Getting started

Setting up Apitally for your Cloudflare Worker takes just a few steps:

  1. Create an app in the Apitally dashboard and select Hono (Cloudflare Workers) or FastAPI (Cloudflare Workers) as the framework.
  2. Create a Logpush job in the Cloudflare dashboard, pointing to the dedicated HTTP endpoint for your app. The exact URL is displayed after creating the app.
  3. Install the serverless SDK and add the middleware to your application.
  4. Enable Workers Logs and Logpush in your Wrangler configuration.
  5. Deploy your Worker.

For detailed instructions, check out our setup guides for Hono and FastAPI.

Things to note

There are a couple of things to be aware of regarding Cloudflare Logpush:

  • Workers Paid plan: Logpush requires the Workers Paid plan in Cloudflare.
  • 2-3 minute delay: Logpush batches log data before sending it, so expect a short delay before requests appear in Apitally.
  • Local development: Logpush doesn’t include requests from local development environments. You’ll only see data from deployed Workers.

Wrapping up

If you’re building APIs on Cloudflare Workers, give our new integration a try and let us know what you think. We’re looking to expand support to other serverless platforms in the future and your feedback will help shape our roadmap.